How to Delete All Products in WooCommerce
Deleting all products in WooCommerce can be a time-consuming process. Sure, if the number of products is small, then it can be done via the WooCommerce panel manually. But most online stores have hundreds of products with different variations, custom taxonomies, and categories. Deleting such a large number of products manually is incredibly cumbersome. Let us take a look at different ways how you can delete WooCommerce products.
Deleting WooCommerce Products Manually
The simplest way of deleting WooCommerce products is by deleting them manually via your WordPress dashboard. It is an efficient method for online stores with a relatively small amount of products.
Start with locating the WooCommerce Products panel in your WordPress dashboard. It is located just underneath the WooCommerce tab. Click on it and you will be re-directed to the Products overview page.
By default, WooCommerce displays 20 products per page. If the amount of products 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 products on a single page. Click the Apply button afterward to save changes.
Now, all products can be seen on a single page and you can select them all by ticking the checkbox underneath the Bulk Actions window. If you want to select only certain products, then you will have to tick them one by one. Keep in mind that you can apply different filters to target specific products or product groups.
After you have selected the products that need to be deleted, go back to the Bulk Actions window and select the Move to Thrash option. Then, click on the Apply button.
It is important to note that, even though we moved products to the Thrash, they have not been deleted. To complete the deletion process, go to the Thrash and either select all products 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.
Voilà! All WooCommerce products have been deleted. Remember to clear cache!
Deleting WooCommerce Products from Database via SQL
As we mentioned previously, deleting WooCommerce products manually in online stores with a large number of products is highly inefficient. In web development, time is of the essence, and wasting precious time ticking thousands of checkboxes is a tedious way of accomplishing this 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. In order 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.
Now that you have located the SQL panel, select the wp_posts table and paste 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 relations.*, taxes.*, terms.* FROM wp_term_relationships AS relations INNER JOIN wp_term_taxonomy AS taxes ON relations.term_taxonomy_id=taxes.term_taxonomy_id INNER JOIN wp_terms AS terms ON taxes.term_id=terms.term_id WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation')); 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');
Go back to your WordPress dashboard and verify if your products are deleted. If you encountered an error after executing the SQL statement, then make sure you have replaced all the prefixes properly.
Additionally, if you want to delete just the attributes you can run the following code.
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'); DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'; DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
There are cases when you must do extensive work with databases. Creating posts, deleting posts, editing posts, et cetera. 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.
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL
Deleting WooCommerce products 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 products 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 products.
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 products and their corresponding data. The plugin has a free(lite) version and a paid one.
With the aforementioned methods, you will be able to delete WooCommerce products with relative ease. It is up to you to decide which procedure is better suited for your online store. Keep in mind that the simplest method might not always be the right one and vice versa. We wish you a bug-free journey through the world of e-commerce and stay tuned for more articles!
KEEP YOUR ONLINE SHOP SAFE WooCommerce Maintenance Service
Save 17% with our Annual pricing plan.