I am trying to bulk update lots of Woocomerce orders (Approx 8000) from processing to Completed. Using the bulk editor I just get an error trying to select so many and change the status. So I made the following query but had to limit the returned results to 100 and I'm only returning IDs to speed it up, any more and the serer would 500 error. But even this is taking ages to execute. We are running on an Azure server.
Is there a more efficient way to do this? Thanks:
<?php
$args = array(
'limit' => 100,
'return' => 'ids',
'status' => 'processing',
'orderby' => 'ID',
'order' => 'ASC',
);
$query = new WC_Order_Query( $args );
$orders = $query->get_orders();
foreach( $orders as $order_id ) {
if ($order_id <= 18500) {
$order = new WC_Order($order_id);
if (!empty($order)) {
$order->update_status( 'completed' );
}
}
}
?>