$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Does the woocommerce_order_status_changed hook fire when WooCommerce updates an order status automatically?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Does the woocommerce_order_status_changed hook fire when WooCommerce updates an order status automatically?

matteradmin7PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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:

  1. 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?

  2. 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?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

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:

  1. 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?

  2. 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?

Share Improve this question asked Feb 15, 2019 at 13:17 no.no. 1331 gold badge1 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

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.

That's not what that means. What that's saying is that WooCommerce itself doesn't add any additional actions to that hook. Not that it doesn't get fired at all.

The woocommerce_order_status_changed hook fires whenever an order status is changed using the $order->update_status() or $order->set_status() methods. WooCommerce only uses these methods internally to change order statuses (and 3rd-party extensions are supposed to also). So if WooCommerce itself ever updates the order status, automatically or not, the hook will fire. This includes when updating the Order manually in the back-end.

The hook wouldn't fire if an extension, such as a payment gateway, tried to set the order status incorrectly. For example, if they changed the status by using $order->status = 'processing' or wp_transition_post_status( 'on-hold', 'processing', $order ); then the hook would not fire.

So you're going to need to find out what circumstances exactly the hook is not firing. If it's a payment gateway updating the order status, and the hook doesn't fire, then it's likely that its developers are doing the status change incorrectly. At that point you would need to talk to its developers.

Post a comment

comment list (0)

  1. No comments so far