I developed a plugin for connecting WooCommerce orders to HubSpot. The problem I'm having is that while it works, the hook I'm using now sends the order information to HubSpot before the technology is complete. So this means things like "Failed Order" will be sent as "Pending" and the coupon code is omitted.
So I want to know what is the correct hook to use.
My goal: Send data to HubSpot every time a WooCommerce order is created and completed and when a WooCommerce order is updated.
What I have so far:
add_action('save_post_shop_order', 'printout', 10, 3); function printout($post_ID, $post, $update) { if (!is_admin()){ return; } if($update){ $msg = $post_ID; $order = get_woocommerce_order($msg); mainplugin($msg, $order); } } add_action('woocommerce_new_order', 'neworder_delegator', 10, 2); function neworder_delegator($order_id, $order){ mainplugin($order_id, $order); }
So I guess I'm just looking for the right hook to get what I want.
Thanks!
P粉2168079242024-04-01 17:11:24
This is your answer:
Each WooCommerce order transition has one or more dynamic hooks that fire when the state transition occurs.
They start with "woocommerce_order_status_" and the rest of the operation is the new status the order has transitioned to, or the round trip status in the format "
Example
You can hook your functions
add_action( 'woocommerce_order_status_completed', 'your_order_completed_function');
Your function is only triggered when an order is converted to completed, not when refunded, canceled, paused, etc. Does not trigger your function as these operations will be run on other operations, such as
woocommerce_order_status_refunded woocommerce_order_status_cancelled woocommerce_order_status_on-hold woocommerce_order_status_failed woocommerce_order_status_processing
Edit to add link to official WooCommerce documentation:
https://woocommerce.github.io/code-reference/hooks /hooks.html