I have followed this tutorial and to add a custom order status "Awaiting Shipment":
My problem is I'm trying to update the status via a php function, but it stays sets on pending payment! So it is executing and changing the correct order but not with this new status.
My code:
$order = new WC_Order($order_id);
$order->update_status('Awaiting shipment', 'order_note');
I can set 'Awaiting Shipment' in the WordPress dashboard ok...
What am I doing wrong?
You need to set it using the slug awaiting-shipment
instead, so your code will be:
$order = new WC_Order( $order_id );
$order->update_status('awaiting-shipment', 'order_note');
This time it will work…
Also
'order_note'
is optional and should be replaced with a real explicit text as an order note should be.
To finish you also can use $order = wc_get_order( $order_id );
Reference: WC_Order
update_status()
method
Related thread: WooCommerce: Auto complete paid orders