Automatically Update WooCommerce Order Status after 2 days from "Order Placed" to "Processing"

844 Views Asked by At

Is there any way to automatically update the order status of all the "Order Placed" to "Processing" after 2 days. Currently, this can be done manually from Woocommerce < Orders < Change order status.

For example - If a user placed an order it should automatically change status to processing after 2 days. I've tried this plugin name WunderAutomation, but unable to get the result. Plugin link - https://wordpress.org/plugins/wunderautomation/

Is there any WooCommerce expert out there who can share a code to change order status automatically?

Thanks for your help

1

There are 1 best solutions below

0
InvictusMKS On

Create a WordPress Cron for two days.

add_filter( 'cron_schedules', 'example_add_cron_interval' );
function example_add_cron_interval( $schedules ) { 
    $schedules['two_days'] = array(
        'interval' => 172800,
        'display'  => esc_html__( 'Every Two Days' ), );
    return $schedules;
}

Create a hook for your function.

add_action( 'bl_cron_hook', 'bl_cron_exec' );

Schedule the hook using the WP Cron we setup above.

if ( ! wp_next_scheduled( 'bl_cron_hook' ) ) {
    wp_schedule_event( time(), 'two_days', 'bl_cron_hook' );
}

Create the function that is called in your hook.

function bl_cron_exec() {
    // Get list of WC orders.
    // Loop over each order.
    // Check if order is over two days old
    // If older then two days then set status of order.
}

WordPress Cron examples taken from WordPress Cron Handbook. You might want to look at the WC_Order documentation to see how to update an orders status.

This is completely not tested and will need to be adjusted based on specific needs. I don't use WordPress Cron very often, so there might be a thing or two I'm missing.