There are times when you have thousands of WooCommerce orders, products, categories, tags, coupons, customers or custom fields and the “Bulk Edit > Delete” option in the WordPress dashboard is simply not cost- and time-effective.
Maybe because your website goes down as it can’t process that much information at the same time, or maybe because you’re on a low budget and can’t afford to hit “delete” 100 or 1000 times by hand.
Thankfully, WooCommerce information is stored in the WordPress database, which means we can access it, write a “SQL DELETE statement”, and bulk delete anything you like, in seconds. Of course, and you will find warnings below, NEVER DO THIS on a live website as I can’t guarantee this won’t have any side effects.
So, have fun!
How to Access the WordPress Database
Your hosting control panel should have a “phpMyAdmin” icon or link. This will allow you to login to your database. Here’s an example with SiteGround hosting.
Now, select your database from the left and once its tables get listed in the right panel note down the database tables prefix. By default this is “wp_“, but each WordPress install could possibly use a different custom prefix. In my case it’s “apos_“, as you can see from the screenshot.
Then, go to the “SQL” tab and write one of the DELETE statements you find below, based on what you need to erase. Of course, you must change all the occurrences of “wp_” to your custom WordPress database table prefix (“apos_” in my case). That’s it!
1. Bulk Delete All Orders
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';
2. Bulk Delete All Products
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type IN ( 'product', 'product_variation' ));
DELETE FROM wp_posts WHERE post_type IN ( 'product', 'product_variation' );
3. Bulk Delete All Trashed Products
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash' );
DELETE FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash';
4. Bulk Delete All Coupons
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_coupon' );
DELETE FROM wp_posts WHERE post_type = 'shop_coupon';
5. Bulk Delete All Order Notes
DELETE FROM wp_commentmeta WHERE comment_id IN ( SELECT ID FROM wp_comments WHERE comment_type = 'order_note' );
DELETE FROM wp_comments WHERE comment_type = 'order_note';