Woocommerce product publishes, updates and removes hooks

I need the Woocommerce Product to post, update and remove hooks, if anyone knows, then let me know.

I find this hook:

add_action('transition_post_status', 'wpse_110037_new_posts', 10, 3);
 function wpse_110037_new_posts($new_status, $old_status, $post) {
 if( 
        $old_status != 'publish' 
        && $new_status == 'publish' 
        && !empty($post->ID) 
        && in_array( $post->post_type, 
            array( 'product') 
            )
        ) {
          //add some cde here
     }

  }

but it only displays the product identifier, name, publication status, etc., but I want to know the price of the product, category, tag, brand and stock status.

So please, replay me if anyone knows.

Thanks, Ketan.

+4
source share
2 answers

Woocommerce products are mainly Wordpress posts. You can use wordpress interceptors

add_action( 'before_delete_post', 'wpse_110037_new_posts' );
add_action( 'save_post', 'wpse_110037_new_posts' );

function wpse_110037_new_posts($post_id){
    $WC_Product = wc_get_product( $post_id);
}

wc_get_product()will return an object WC_Product, and you can get information about it.

+8
source

, . update, , .

add_action( 'save_post', array($this, 'wpse1511_create_or_update_product' ), 10, 3);

function wpse1511_create_or_update_product($post_id, $post, $update){
    if ($post->post_status != 'publish' || $post->post_type != 'product') {
        return;
    }

    if (!$product = wc_get_product( $post )) {
        return;
    }

    // Make something with $product
    // You can also check $update
}
+3

Source: https://habr.com/ru/post/1598326/


All Articles