Woocommerce Product publish, update and delete hooks

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 Also:  Laravel 6 Group By using Eloquent

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

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
}

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
        }
    }
}

List of all WordPress hooks

Woocommerce Product publish, update and delete hooks

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);
}

WooCommerce add or update products hook – WordPress Ecommerce Tutorial

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...
        }
    }
}

woocommerce hook publish product

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
     }

  }

Woocommerce Action List

        $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',
            ),
        );

Web Programming Tutorials Example with Demo

Read :

Read Also:  PHP is not recognized as an internal or external command

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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *