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.

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

Read Also:  Pure CSS custom Fancy checkboxes

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:  jquery Bootstrap Creating Tooltips Example

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Remove WooCommerce action Hook in Wordpress
  2. Read Also:  How to Show or hide invisible characters?
  3. Read Also:  Ng-Cloak Directive using Angular Example
  4. Read Also:  PHP woocommerce_template_single_add_to_cart wordpress function
  5. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  6. Read Also:  Laravel set global Variable in middleware, all controller and views
  7. Read Also:  how to upload project file to github using command line?
  8. Read Also:  Laravel 5.7 Get Current Page URL path
  9. Read Also:  PHP MySQL Infinite Scroll Pagination
  10. Read Also:  jquery replace newline with br Example - Convert new lines to br - nl2br function