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:
- If the product was updated - the webhook is fired to my API which creates the event with the current stock information.
- 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)?
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' );
} );
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML