WooCommerce hook after order is updated?

谁都会走 提交于 2019-12-06 10:40:47

Sorry but woocommerce_checkout_update_order_meta is fired after the order is saved… See this extract source code located in WC_Checkout create_order() method:

// Save the order.
$order_id = $order->save(); // <== Order is saved here before

do_action( 'woocommerce_checkout_update_order_meta', $order_id, $data ); <== // The hook

return $order_id;

So in woocommerce_checkout_update_order_meta you can get the saved order data:

  • by retrieving the WC_Order object from the $order_id argument and using all methods on it.
  • or using get_post_meta() on with the $order_id argument to get the data saved in wp_postmeta database table.

Then you can update the data with update_post_meta() function…


You can even use woocommerce_checkout_create_order before the data is saved…

You will be able to get the data from the $order argument using all available methods for the WC_Order class (CRUD getters methods).

You will be able to alter this data and saving it using the CRUD setters methods…

Some examples in stackOverFlow


If you need to do that after the order process the hooks to be used can be:

  • woocommerce_new_order (on newly created order event)
  • woocommerce_thankyou (on order received page)
  • woocommerce_order_status_changed (on order status changing event)

And may be some others…


To alter the data when order is saved in backend, you will use save_post_shop_order that has 3 arguments: $post_id, $post and $update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!