Every now and then you will need to delete all orders from WooCommerce online stores. For instance, you have created a new WordPress website for your client and now you need to test whether the WooCommerce online store functionality works or not. You generate mock orders to see if everything works properly, but you have to delete them afterward. A small number of orders can be deleted manually, but for a large number of orders, this method would be especially time-consuming. Let us take a look at different techniques on how to delete WooCommerce orders.
Deleting WooCommerce Orders Manually
The most common approach is to delete all orders manually via your WordPress dashboard. It is a quick and efficient method when the amount of orders is low.
Start with locating the WooCommerce Orders panel in your WordPress dashboard. It is located in the WooCommerce dropdown menu. Click on it, so you would be re-directed to the main Orders window.
By default, WooCommerce displays 25 orders per page. If the amount of orders in your case is higher, then locate the Screen Options tab in the upper right corner and click on it.
Set the Number of Items Per Page option accordingly, so it would display all your orders on a single page. Click the Apply button afterward to save changes.
Now all orders can be seen on a single page and we can start deleting them. You can select all orders at once, by ticking the checkbox underneath the Bulk Actions window. If you want to select only specific orders, then you will have to tick each box manually. Keep in mind that you can apply filters to target specific clients or dates.
When you have selected all orders that need to be deleted, then go back to the Bulk Actions window and select the Move to Thrash option. Click on the Apply window to confirm the action.
Bear in mind, that even though you moved orders to thrash, they are yet to be completely deleted. To remove them entirely, you will need to go to the Thrash and either select all orders via checkbox again and pick the Delete Permanently option in the Bulk Actions window, or just click on the Empty Thrash button next to the filter options.
As you can see, manually deleting orders is rather straightforward. Remember to clear cache!
Deleting WooCommerce Orders via SQL
As we mentioned previously, it is highly inefficient to manually delete a large number of WooCommerce orders. In web development, wasting time manually ticking thousands of checkboxes is an inept way of accomplishing such a task. Thankfully, the issue can be remedied via the use of code.
Login to your phpMyAdmin account. Before proceeding, confirm that the script will be run on the correct database. To ratify whether the correct database is loaded, look for the table wp_options and check if it has the correct URL for your website. Always backup your website before running any script! Otherwise, you may lose significant data or even render the website inaccessible. You should regularly take precautions when running advanced SQL queries.
You have located the SQL panel and now it is time to apply the code below. If your database prefix is not wp_, then replace it with the prefix you are using. Press the Go button to execute the SQL statement.
DELETE FROM wp_woocommerce_order_itemmeta;
DELETE FROM wp_woocommerce_order_items;
DELETE FROM wp_comments WHERE comment_type = ‘order_note’;
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = ‘shop_order’ );
DELETE FROM wp_posts WHERE post_type = ‘shop_order’;
Now all data associated with WooCommerce orders has been successfully deleted. Take note that even though we have cleared the database, there might be some leftover data. Every action influences the post metadata table and if you are not cautious, then you might end up with thousands of rows of data that is unused. By deleting orphaned post metadata (data that is affiliated with nonexistent posts), you will eliminate all records that have no use. In the same manner as before, run the following code.
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL;
After running this code, you can be sure that all data concerning orders and other useless data has been deleted. You should get a notification that SQL Query has been executed properly.
Deleting WooCommerce Orders via Plugins
If you are not savvy with coding and databases in general, then consider using plugins. Unfortunately, there are not many plugins that can delete all WooCommerce orders and their corresponding data. Although there are plugins that reset databases, not many of them have functionality for this specific task. Let us take a look at 3 popular plugins that can be used to delete all WooCommerce orders.
WP Reset. The most popular plugin for resetting sites databases to the default installation values without modifying files. It is a fast and efficient way of targeting specific data and removing it. With multiple fail-safe mechanisms integrated into the plugin, you will be able to restore any data you have accidentally deleted. We advise you to carefully take a look at the documentation in order to understand how to select and target the data you desire.
Store Toolkit for WooCommerce. This plugin includes a growing set of commonly-used WooCommerce administration tools, mainly, aimed at web developers and store maintainers. With a large set of maintenance/debugging/clearing tools at your disposal, you will be able to delete any data concerning WooCommerce.
Smart Manager for WooCommerce. For the most part, this plugin is used to increase WooCommerce functionality and add additional tools for managing your store, but it can be used to clear your database from unnecessary orders and their corresponding data. The plugin has a free(lite) version and a paid one.
Sometimes, deleting WooCommerce data is not as straightforward as it seems. Even if you have deleted the WooCommerce order data from your dashboard, there might be some leftover data in your database. With these methods, you should be able to thoroughly clean your database. Keep in mind that it is up to you to decide which approach is better suited for your situation. We wish you a bug-free journey through the world of e-commerce and stay tuned for more articles!