Search code examples
phpwordpresswoocommercepluginshook-woocommerce

Which hooks affect anything about WooCommerce product?


I am developing a plugin for WooCommerce that sends available products to a third party advertising server. The server requires every product information (including title, description, categories, etc...) and product stock value and price.

The goal is to use other parties to act as an alternative marketplace, therefore those markets should be aware of the product information, price and stock quantity.

The problem is I don't know which hooks affect these data so that I can notify the advertising server with newest information. I need every hook and by every hook I mean ALL of the hooks (Adding a product, modifying a product, deleting a product, changing a product stock or price, selling a product, reserving a stock for an end-user in checkout process, everything that affects product info or price or stock).

I've checked WooCommerce docs but there are so many hooks with confusing names and many of them do not have usage description. I even looked up in ChatGPT, but many answers were old and the remaining were insufficient.


Solution

  • First, you need to look at WC_Product_Data_Store_CPT class file, where you can use the following action hooks:

    • Creation: woocommerce_new_product (function arguments are $id and $product),
    • Update: 'woocommerce_update_product (function arguments are $product_id and $product),
    • Delete: 'woocommerce_delete_{$post_type} product type composite hook (function argument is $id),
    • Trash: 'woocommerce_trash_{$post_type} product type composite hook (function argument is $id).

    There are also the following hooks:

    Then as product metadata is also added/updated/deleted via WordPress post meta functions, you can also use the following WordPress composite action hooks (targeting "product" and "product_variation" custom WooCommerce post types):

    You will need to check progressively if every product change is triggered via those hooks...

    Also for product reviews:

    Also for product terms (category, tags…):