We have a plugin that uses the woocommerce_payment_complete
hook which calculates an orders point value for our customers based on the items and order total. This generates a CSV file and then uses rsync
to send the CSV file to an external system which stores and manipulates this data.
In the same plugin we also use the woocommerce_order_status_changed
hook which recalculates the values depending on the new order status (refunded items etc), generates the CSV file and sends to the external source again.
This is all working fine, a customer can make an order and the CSV file is generated etc, we can update the order status in the admin dashboard manually and the new CSV file is generated and sent. However, if an order is automatically changed via WooCommerce or the payment gateway, it seems as though the woocommerce_order_status_changed
hook is not firing as the CSV file is not being generated.
So my questions are:
Does the
woocommerce_order_status_changed
hook get triggered when the order status is changed automatically, or is it only when the order status is changed manually in the backend by us?Is there a hook that is triggered when the order status is changed automatically via WooCommerce/payment gateways?
I've search high and low but every result seems to either point to what I'm already doing or is about setting up a script that changes the status using $order->update_status()
and similar alternatives which is not what we're looking for.
One of the results did bring up this (in reference to woocommerce_order_status_changed
):
"Where the hook is used (in WC core): Does not used."
Which seems to answer Question 1, which is what leads me to believe if WooCommerce or a payment gateway changes the order status automatically, it will never fire, thus not creating our CSV etc.
Can anyone shed some light on this? Is there a hook which we can trigger on order statuses changed automatically via WooCommerce or a payment gateway?