WooCommerce - Order Status Change to Complete

majidorc

Active member
Aug 27, 2019
207
66
28
35
tours.co.th
Hello,
anybody have any method to make automatic order status from Processing to Complete after Delivery Date?
Thank you.

1620663013394.png
 

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
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?
 

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
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

majidorc

Active member
Aug 27, 2019
207
66
28
35
tours.co.th
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 :)
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu