Imagine your online store bustling with orders. Each time a customer completes a purchase, their order promptly moves into the ‘Processing’ status. But here’s the exciting part: What if, exactly 5 days later, these orders seamlessly transitioned to a new status like ‘Awaiting Shipping’ all on their own?
Solution: Automate WooCommerce Order Status Change after Specific Days
The code snippet will change the order statuses from ‘Processing’ to ‘Awaiting Shipping’ after 5 days from the processing status was set.
add_action( 'woocommerce_order_status_changed', 'ts_mark_order_complete_if_within_timeframe', 10, 4 ); function ts_mark_order_complete_if_within_timeframe( $order_id, $from_status, $to_status, $order ) { // Check if the order status is changing to 'processing' if ( $to_status === 'processing' ) { // Set the timezone date_default_timezone_set( 'Asia/Kolkata' ); // Adjust timezone as needed // Define the start time (order creation time) $start_time = strtotime( $order->get_date_created()->format( 'Y-m-d H:i:s' ) ); // Calculate the end time (start time + 0 business days) $end_time = strtotime( '+5 weekdays', $start_time ); // Get the current time $current_time = strtotime( "now" ); // Check if the current time is after the end time if ( $current_time >= $end_time ) { // Update order status to 'completed' $order->update_status( 'completed' ); } } } add_filter( 'wc_order_statuses', 'ts_rename_order_status_msg', 20, 1 ); function ts_rename_order_status_msg( $order_statuses ) { $order_statuses['wc-completed'] = _x( 'Awaiting Shipping', 'Order status', 'woocommerce' ); return $order_statuses; }
Output
Orders in ‘Processing’ status will be automatically marked as ‘Awaiting Shipping’ if they have been in the ‘processing’ status for more than 5 days.
Just want to automate the WooCommerce order status regardless of the number of days. You can also automatically complete WooCommerce orders when they go to the Processing status.