Woocommerce Product publish, update and delete hooks

Today, We want to share with you Woocommerce Product publish, update and delete hooks.In this post we will show you woocommerce shipping calculator hook, hear for woocommerce save_post product we will give you demo and example for implement.In this post, we will learn about WooCommerce hook on product updated or added with an example.

Woocommerce Product publish, update and delete hooks

There are the Following The simple About Woocommerce Product publish, update and delete hooks Full Information With Example and source code.

READ :  10 Free Best Regards Should Be Your Go-To Email Closing

As I will cover this Post with live Working example to develop woocommerce order notes hook, so the woocommerce_add_to_cart for this example is following below.

Updated method for WooCommerce 3.x

[php]
add_action( ‘woocommerce_update_product’, ‘plugin_name_sync_on_product_save’, 10, 1 );
function plugin_name_sync_on_product_save( $product_id ) {
$get_all_product = wc_get_product( $product_id );
// return json data
}
[/php]

[php]
add_action( ‘added_post_meta’, ‘plugin_name_sync_on_product_save’, 10, 4 );
add_action( ‘updated_post_meta’, ‘plugin_name_sync_on_product_save’, 10, 4 );
function plugin_name_sync_on_product_save( $meta_id, $post_id, $meta_key, $meta_value ) {
if ( $meta_key == ‘_edit_lock’ ) { // we’ve been editing the post
if ( get_post_type( $post_id ) == ‘product’ ) { // we’ve been editing a product
$product = wc_get_product( $post_id );
// do something with this product
}
}
}
[/php]

List of all WordPress hooks

READ :  Laravel 6 Call controller method from another controller

Woocommerce Product publish, update and delete hooks

[php]
add_action( ‘before_delete_post’, ‘plugin_name_new_posts’ );
add_action( ‘save_post’, ‘plugin_name_new_posts’ );

function plugin_name_new_posts($post_id){
$WC_Product = wc_get_product( $post_id);
}
[/php]

WooCommerce add or update products hook – WordPress Ecommerce Tutorial

[php]
add_action( ‘added_post_meta’, ‘your_function_name’, 10, 4 );
add_action( ‘updated_post_meta’, ‘your_function_name’, 10, 4 );
function your_function_name( $meta_id, $post_id, $meta_key, $meta_value ) {
if ( $meta_key == ‘_edit_lock’ ) { // we’ve been editing the post
if ( get_post_type( $post_id ) == ‘product’ ) { // we’ve been simple editing a product
$product_data = wc_get_product( $post_id );
// do something here
//code here…
}
}
}
[/php]

woocommerce hook publish product

[php]
add_action(‘transition_post_status’, ‘your_function_name’, 10, 3);
function your_function_name($new_status, $old_status, $post) {
if(
$old_status != ‘publish’
&& $new_status == ‘publish’
&& !empty($post->ID)
&& in_array( $post->post_type,
array( ‘product’)
)
) {
//add some code here
}

READ :  vue js Login Form get http json data

}
[/php]

Woocommerce Action List

[php]
$topic_hooks = array(
‘coupon.created’ => array(
‘woocommerce_process_shop_coupon_meta’,
‘woocommerce_new_coupon’,
),
‘coupon.updated’ => array(
‘woocommerce_process_shop_coupon_meta’,
‘woocommerce_update_coupon’,
),
‘coupon.deleted’ => array(
‘wp_trash_post’,
),
‘coupon.restored’ => array(
‘untrashed_post’,
),
‘customer.created’ => array(
‘user_register’,
‘woocommerce_created_customer’,
‘woocommerce_new_customer’,
),
‘customer.updated’ => array(
‘profile_update’,
‘woocommerce_update_customer’,
),
‘customer.deleted’ => array(
‘delete_user’,
),
‘order.created’ => array(
‘woocommerce_new_order’,
),
‘order.updated’ => array(
‘woocommerce_update_order’,
‘woocommerce_order_refunded’,
),
‘order.deleted’ => array(
‘wp_trash_post’,
),
‘order.restored’ => array(
‘untrashed_post’,
),
‘product.created’ => array(
‘woocommerce_process_product_meta’,
‘woocommerce_new_product’,
‘woocommerce_new_product_variation’,
),
‘product.updated’ => array(
‘woocommerce_process_product_meta’,
‘woocommerce_update_product’,
‘woocommerce_update_product_variation’,
),
‘product.deleted’ => array(
‘wp_trash_post’,
),
‘product.restored’ => array(
‘untrashed_post’,
),
);
[/php]

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Woo-commerce Product publish, update and delete hooks.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment