Reputation: 128
When creating a Woocommerce order using the "Add Order" screen in the Wordpress admin, if I retrieve the order using wc_get_order() in a callback attached to woocommerce_process_shop_order_meta, I have noticed that the Customer ID is 0 - despite the fact that I have selected a customer. The code I am writing uses this data to sync to an external API so my question is: Why is this ID empty and is there a way to get the correct ID?
A simplified version of the code would be:
add_action('woocommerce_process_shop_order_meta', 'processOrder', 10, 1);
function processOrder($order_id){
$order = wc_get_order($order_id);
die(print_r($order->get_customer_id(),1));
}
Upvotes: 2
Views: 765
Reputation: 65264
It's because of the priority you're using.
See attached image:
The customer id is saved in add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2 );
where priority is 40
.
Setting your priority greater than 40 then it should work.
Upvotes: 1