You might clone or migrating Woocommerce site to new server and you might want to purge all Woommerce order. Here is the script.
Simply place at your root folder. Save as XX.php
<?php @ini_set('output_buffering', 'off'); @ini_set('zlib.output_compression', false); @ini_set('implicit_flush', true); ob_implicit_flush(true); while (ob_get_level() > 0) ob_end_flush(); require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' ); if ( ! current_user_can('manage_woocommerce') ) { wp_die('Unauthorized'); } echo "<pre>"; $start_time = microtime(true); // Get ALL orders (no limit) $order_ids = wc_get_orders(array( 'limit' => -1, 'return' => 'ids', 'status' => array_keys(wc_get_order_statuses()), )); $total = count($order_ids); echo "š§¹ Found $total orders to delete...\n\n"; $counter = 0; foreach ($order_ids as $order_id) { $order = wc_get_order($order_id); if ($order) { $order->delete(true); // true = force delete $counter++; echo "ā [$counter / $total] Deleted Order ID: $order_id\n"; flush(); } } wc_delete_shop_order_transients(); $end_time = microtime(true); $duration = round($end_time - $start_time, 2); echo "\nš Done! Deleted $counter orders in {$duration} seconds.\n"; echo "</pre>";
Then, to execute, hit your domain/XX.php
For example your domain is afifrus.com and you PHP file is deletewoo.php.
Hit afifrus.com/deletewoo.php – it might take awhile depending on your order history, but eventually, it will complete.
That’s all.