We have covered various WooCommerce shipping method customizations in our blog. In this post, we are going to change the order status based on the shipping method. This customization is useful for an online store offering local pickup as a convenient option for customers. Imagine how easy it would be if their orders were automatically marked as ‘Completed’ as soon as they chose the ‘local pickup’ method during checkout. That’s exactly what this code does.
Solution: Change WooCommerce Order Status based on Shipping Method
The code snippet will mark all orders as ‘completed’ when the chosen shipping method is ‘local pickup’.
add_action( 'woocommerce_thankyou', 'ts_local_pickup_update_order_status', 10, 1 ); function ts_local_pickup_update_order_status( $order_id ) { if ( ! $order_id ) return; $search = 'local_pickup'; // enter the shipping method ID // 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 ){ // When "local pickup" method is used, we change the order to "on-hold" status if( strpos( $shipping_item->get_method_id(), $search ) !== false ){ $order->update_status('completed'); $order->save(); break; } } }
Output
During checkout if the customer chooses the local pick up shipping method , those orders will be automatically marked as ‘completed’.
We have seen the automation of order status transition based on shipping methods. But wait, there’s more! You can also change WooCommerce order status based on order total. This feature may also help you to expedite the shipping process based on order total.