Delay a trigger

Hello everyone,

I got a simple question but didn’t found a solution anywhere : is that possible to delay a trigger ?

I put a trigger on the action “ORDER_CREATE”, and I would want to wait 3 seconds before executing the code of my trigger.

I tried sleep(3), but it seems to affect the whole Dolibarr system instead of delaying the trigger only.

Thank you for your help !

What you have seen is because of the way php works.
You can not natively delay anything while letting the script run on.
I do not know why you want to delay but you could hand over the action to some kind of “external” service to act on your trigger with the instruction to delay 3 seconds before execution.

I’m importing orders from a WooCommerce website through a Dolibarr plugin called Woosync.
When the plugin creates the order, if they’re already validated at creation, the stock of the products doesn’t decrement. If it’s imported as draft then manually validated, the stock decrements.

I was searching for a way to automatically validate incoming orders with a trigger on the “ORDER_CREATE” action. The problem is, the plugin still needs to add line to incoming orders and tries to do it after my trigger validates it. The delay would enable the plugin to add lines to the order before my trigger validates it.

The problem is on the module side.
You should get in contact with the devs there. Woosync should be able to sync the order and validate the order while triggering the stock decrease by the appropriate hook in dolibarr.

Delaying won’t do you any good as I wrote above