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!
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 "to" '
Example
You can hook your functions
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
Edit to add link to official WooCommerce documentation:
https://woocommerce.github.io/code-reference/hooks /hooks.html