• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

WooCommerce - Order Status Change to Complete

majidorc

Active member
Trusted Uploader
Aug 27, 2019
214
76
28
34
tours.co.th
Hello,
anybody have any method to make automatic order status from Processing to Complete after Delivery Date?
Thank you.

1620663013394.png
 
It depends in which database table this Delivery Date is inserted, but once you know that it's not so difficult to check those dates and if the current date is +1 change the status.
Is this Delivery Date added by a WooCommerce extension or by a third-party plug-in?
 
Something like this in functions.php or a custom code snippets plug-in:

PHP:
function auto_change_order_status() {

    global $wpdb;

    $results = $wpdb->get_results("
    SELECT *
    FROM  $wpdb->posts
        WHERE post_type = 'shop_order'
        AND post_status = 'wc-processing'
");
    if (!$results) return;
    else {
        foreach ($results as $result) {
        $delivery_date = get_post_meta( $result->ID, '_delivery_date', true );
        $currentdate = date ('Y-m-d');
            if ($currentdate >= $delivery_date) {
                $ord = new WC_Order($result->ID);
                $ord->update_status('wc-completed');
            }
        }
    }
   
}

add_action('init', 'auto_change_order_status');
 
  • Love
Reactions: majidorc
Something like this in functions.php or a custom code snippets plug-in:

PHP:
function auto_change_order_status() {

    global $wpdb;

    $results = $wpdb->get_results("
    SELECT *
    FROM  $wpdb->posts
        WHERE post_type = 'shop_order'
        AND post_status = 'wc-processing'
");
    if (!$results) return;
    else {
        foreach ($results as $result) {
        $delivery_date = get_post_meta( $result->ID, '_delivery_date', true );
        $currentdate = date ('Y-m-d');
            if ($currentdate >= $delivery_date) {
                $ord = new WC_Order($result->ID);
                $ord->update_status('wc-completed');
            }
        }
    }
  
}

add_action('init', 'auto_change_order_status');
thank you so much, worked :)
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock