How to update Woocommerce order programmatically
-
I have made this function:
add_action(‘woocommerce_checkout_update_order_meta’, ‘my_own_function’);
function my_own_function ( $order_id ) {
$order = new WC_Order($order_id);
$order->shipping_last_name = ‘TEST’;
}Now if I write the $order->shipping_last_name to a log-file in that function, then the name is correctly printed as TEST. But when I recieve the order, then that last name is the value that user gave when ordering.
So I believe that action woocommerce_checkout_update_order_meta is called before the order is updated with the user given values? How could I do this so that the value would be saved properly?
I have also tried this in the same function but the result is the same:
update_post_meta( $order_id, ‘shipping_last_name’, ‘TEST’);
- The topic ‘How to update Woocommerce order programmatically’ is closed to new replies.