Ad

Prevent WooCommerce From Firing Product Update Webhook On REST API Update Only

I am trying to create a stock sync system that communicates with WooCommerce via REST API and webhooks. It works simply like that:

  1. If the product was updated - the webhook is fired to my API which creates the event with the current stock information.
  2. When event is created it is being processed and the product update information is sent via REST to other WooCommerce stores in my "network". The product is updated.

The issue here is that it creates some kind of infinite loop as when the product is updated on other website it fires webhook again and creates a new event in my API again.

Question: Is it possible to prevent WooCommerce from firing product update webhooks ONLY when product is updated via REST API (or specific function)?

Ad

Answer

Yes, there is an example using the filter woocommerce_webhook_should_deliver here: https://shanerutter.co.uk/fix-woocommerce-webhook-loop/

Also, I've had luck un-scheduling the Action Scheduler actions upon their creation, which is a consequence of a REST API inventory type sync job firing product updated hooks and web hooks:

add_action( 'init', function() {
    as_unschedule_all_actions( 'adjust_download_permissions' );
} );
Ad
source: stackoverflow.com
Ad