Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Automatically Update Order Status Based on Set Day and Time in WooCommerce?

Change WooCommerce Order Status

Store owners in the food delivery sectors often need to fulfill orders quickly and manage a large number of orders accumulated throughout the day. In such scenarios, automation becomes essential for updating the status of those orders at a specific day and time. 

Imagine this: every Friday at 9:00 AM, like clockwork, all your ‘Processing’ orders automatically switch to ‘Completed’ status. Automating the update of order statuses at specific times can significantly enhance order management efficiency. This customization ensures that your orders are consistently updated on time, saving valuable time and eliminating the risk of human error.

Solution: Automatically Update Order Status Based on Set Day and Time in WooCommerce

This code snippet automatically changes order statuses from ‘processing’ to ‘completed’ every Friday at 9:00 AM as specified in the code.

add_action('init', 'ts_orders');

function ts_orders() {
    // Define your target day and time
    $target_day = 'Fri'; // Friday
    $target_time = '9:00 AM'; // Time in 12-hour format

    // Get current day and time in WordPress timezone
    $current_day = date('D', current_time('timestamp'));
    $current_time = date('g:i A', current_time('timestamp'));

    // Check if it's the target day and time
    if ($current_day === $target_day && $current_time === $target_time) {
        global $wpdb;

        // Query to get all orders with 'wc-processing' status
        $my_query = "SELECT * FROM {$wpdb->prefix}wc_order_stats WHERE status='wc-processing'";
        $results = $wpdb->get_results($my_query);

        foreach ($results as $result) {
            $order_id = $result->order_id;
            $order = new WC_Order($order_id);
            if (!empty($order)) {
                $order->update_status('completed');
            }
        }
    }
}

Output

When the current day and time matches with the day and time as specified in the code(Friday 9:00 AM), orders in ‘processing’ status are automatically updated to ‘completed’.

How to Automatically Update Order Status Based on Set Day and Time in WooCommerce? - Tyche Softwares

The way businesses automate order status updates can vary depending on their specific needs. For example, food delivery services prioritize updating orders promptly at specific times to ensure quick order fulfillment. On the other hand, other businesses might explore methods like automating WooCommerce order status changes based on certain timeframes. Regardless of the scenario, automating order statuses can simplify your workflow and order management efficiency.


Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
1 Comment
Newest
Oldest
Inline Feedbacks
View all comments
Tom
3 months ago

Hi Saranya
Thank you for the snippet!
I’m looking forward to trying it!!
I will let you know how it goes.
(You are quite wonderful!!)
Tom

1
0
Would love your thoughts, please comment.x
()
x