Skip to content
Advertisement

WooCommerce – change order status with php code

I am trying to change order status in WooCommerce, but I encountered no luck so far. $order instance is created successfully (I know it because echo $order->status; works fine, $order_id is also correct. $order->status = 'pending'; simply doesn’t change anything, I do not know why.

$order = new WC_Order($order_id);
$order->status = 'pending';

Could anyone help me with this?

Advertisement

Answer

Try this code:

$order = new WC_Order($order_id);
$order->update_status('pending', 'order_note'); // order note is optional, if you want to  add a note to order
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement