3
votes

I'm currently having some issues with a WooCommerce site. There are thousands of old orders that are stuck on the status "processing". These orders have received payment and products have been shipped.

I would like to mark these orders as complete without sending completed order E-mails. I'd like to use the following SQL Query to achieve this.

update wp_posts set post_status = 'wc-completed' where post_type = 'shop_order' and post_status ='wc-processing' ;

Do I need to change other tables too or would this work?

Thanks

Edit: The above code worked perfectly for me.

1
You don't need to change other tables … this SQL query is perfect as it is… Then here is the way to auto complete paid orders to avoid this happening again.LoicTheAztec

1 Answers

0
votes

You shouldn't need to update any other tables if you're only changing the order status. Note that you can also achieve this from within WordPress:

$args = array(
    'post_type'         => 'shop_order',
    'posts_per_page'    => -1,
    'post_status'       => 'wc-processing',
);

$orderList = get_posts($args);

foreach ($orderList as $orderPost) {
    $order = new WC_Order($orderPost->ID);
    $order->update_status('completed');
}

...although a direct SQL query will almost certainly be quicker in this circumstance.

Additionally, if you want to automatically convert orders to completed once they've been paid for, you can add the following filter:

function myWooAutoCompleteOrder($orderID) {

    //  Only continue if we have $orderID

    if (!$orderID) {
        return;
    }

    //  Get order

    $order = wc_get_order($orderID);

    //  Update order to completed status

    if ($order) {
        $order->update_status('completed');
    }
}

add_filter('woocommerce_thankyou', 'myWooAutoCompleteOrder');