I need to change the order status from the default ‘processing’ status to ‘priority’ if a customer chooses any 1 of 4 express shipping options.
I’m using the classic checkout.
Here’s what I’ve tried so far but nothing happens when a user places an order.
add_action( 'woocommerce_thankyou', 'shipping_method_update_order_status', 10, 1 );
function shipping_method_update_order_status( $order_id ) {
if ( ! $order_id ) return;
// Here define your shipping methods Ids
$shipping_method_0_flat_rate25 = array('flat_rate');
$shipping_method_0_flat_rate26 = array('flat_rate');
$shipping_method_0_flat_rate27 = array('flat_rate');
$shipping_method_0_flat_rate28 = array('flat_rate');
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Get the WC_Order_Item_Shipping object data
foreach($order->get_shipping_methods() as $shipping_item ){
// For testing to check the shipping method slug (uncomment the line below):
// echo '<pre>'. print_r( $shipping_item->get_method_id(), true ) . '</pre>';
if( in_array( $shipping_item->get_method_id(), $shipping_method_0_flat_rate25 ) && ! $order->has_status('priority_dispatch') ){
$order->update_status('priority_dispatch'); // Already use internally save() method
break; // stop the loop
}
elseif( in_array( $shipping_item->get_method_id(), $shipping_method_0_flat_rate26 ) && ! $order->has_status('priority_dispatch') ){
$order->update_status('priority_dispatch'); // Already use internally save() method
break; // stop the loop
}
elseif( in_array( $shipping_item->get_method_id(), $shipping_method_0_flat_rate27 ) && ! $order->has_status('priority_dispatch') ){
$order->update_status('priority_dispatch'); // Already use internally save() method
break; // stop the loop
}
elseif( in_array( $shipping_item->get_method_id(), $shipping_method_0_flat_rate28 ) && ! $order->has_status('priority_dispatch') ){
$order->update_status('priority_dispatch'); // Already use internally save() method
break; // stop the loop
}
}
}