I am trying to make a plugin for woocommerce that, at each new order, take all the data that I need, split it by item in a foreach loop and then send each item data as a separate post through cURL. But my code don't seem to ignore the foreach loop. Here is the code for my loop:
add_action('woocommerce_new_order', 'wdm_send_order_to_ext');
function wdm_send_order_to_ext( $order_id ){
// get order object and order details
$order = wc_get_order($order_id);
print_r(" Start ");
if($order->get_items()>0)
{
print_r(" Item exist ");
foreach($order->get_items() as $item_id => $item_data){
print_r(" Foreach loop executing for item ID: $item_id ");
}
}
else
{
print_r(" No Item ");
}
print_r(" End ");
}
and my result is: Start Item exist End edit: When i used print_r on $order->get_items(), it printed as Array ( )
$order
variable has any data or not? or are you sure that the hook is executing on the right time? – Asif