WooCommerce fix slow or delayed webhooks and achieve instant webhook firing

I’ve recently been working on a project which synced data between WooCommerce and an internal warehouse system, I was utilising the WooCommerce webhooks to achieve near real time syncing between the two systems, without having the creating API scripts to poll for data on a regular basis.

The Problem?

There was a delay ranging from couple seconds to 1 minute, WooCommerce uses a system called actions scheduler, this is an improved wordpress cron, allowing background processing to occur within WordPress for single or recurring actions. This is great and what WooCommerce utilises for its web hook system, however it is backed by the word press cron and the next load of scheduled actions will run on the next cron run (every 1 minute).

For this project, I needed the web hooks to fire as soon as the button was clicked, and a possible delay up to 1 minute was to long.

Fix

Disable async web hooks, web hooks will not fire as soon as they are created as part of the browser request.

I would recommend you test your site after doing this change, for example order webhooks will fire when a customer creates a new order, which could lead to a slow user experience.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

4 Comments

    • Hi, you can either create a plugin or simply add this to your themes function.php file. But the change will then be theme specific.

  1. Hi,

    Maybe you can suggest 🙂
    Is there a way to delay a webhook with 1 minute? Based on webhook id.
    So it still happens async but a specific webbook will be scheduled some time later.

    • The normaly webhook process uses the WP cron, if you want to keep the async nature, then you want to leave the above enabled. This way WordPress will queue the webhooks and each one will be processed with the next wp cron triggers.

      If doing this I would recommend ensuring your WP cron is setup to use server side cronjobs to ensure the cronjobs are fired every minute, resulting in the webhooks being fired.