I am trying to hook into a 3rd party application when a cart is checked out. Essentially i need to pass information about the order such as the products that are inside the order.
Everything i find points me towards the hook: woocommerce_new_order
When i use that hook i can get some information about the order but not everything.
add_action('woocommerce_new_order','order_check',10,1);
function order_check($order_id){
echo 'Order id is: '.$order_id;
$order = new WC_Order($order_id);
print_r($order);
echo '-----';
/** CHECK IF order has items */
$order_item = $order->get_items();
print_r($order_item);
exit;
}
For instance the above code sample will print the order array but when it call $order->get_items() nothing is returned.
At the time woocommerce_new_order
fires, order items is not yet populated.
Instead, use the hook woocommerce_checkout_order_processed
and you'll find that all items are then populated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With