Blog

How to delete all products from WooCommerce stores? (with SQL and plugin)

bulk delete all woocommerce products using code and plugin
Table of Contents

One of the problems that most WordPress users have is bulk remove of all WooCommerce products at once. Suppose you own a store with more than 2000 thousand products and you want to delete all products or half of them for any reason. It is not surprising if you are looking for a solution to delete all products in the shortest possible time. The good news is that there are different ways to delete all WooCommerce products very quickly, and in this post, we are going to teach you how to do it.

WooCommerce delete all products manually

The easiest way to bulk delete WooCommerce products is to remove them manually through the WooCommerce product bulk edit page. This is an efficient method for online stores with a relatively small volume of products.

First, go to the “Products » All Products” section in the WordPress dashboard.

By default, WooCommerce displays 20 products per page. If the number of products available on your site is more, find the screen options tab in the upper right corner and click on it.

click screen options to change number of items per page
For delete all WooCommerce products you must change default product per page value to a large number

Now, in the pagination section, set the “Number of items per page” option so that all the products you have are displayed on one page. Finally, click on “Apply”.

Set products per page value
change number of items per page

Now, all products can be viewed on one page and you can select them all by checking the checkbox under the bulk actions window. If you want to select only certain products, you have to check them one by one. Keep in mind that you can apply different filters to target specific products or product groups.

select bulk action in woocommerce product list
Select move to trash to delete all selected products in the list

After selecting the products to be deleted, return to the “Bulk Actions” box and select the “Move to Trash” option. Then click on the Apply button.

It’s important to note that even though we’ve moved the products to the trash, they haven’t been completely removed yet. To complete the bulk delete process, go to “Trash” and again select all products through the checkbox and delete them.

Delete WooCommerce products from database via SQL

As you may notice, bulk remove products via WooCommerce product bulk edit manually, is very inefficient in online stores with a large number of products. Time is of the essence in web development, and wasting precious time ticking thousands of checkboxes is a tedious way to do it. Fortunately, this problem can be solved using code.

For delete all WooCommerce product via SQL, you must first enter your host Cpanel and go to “phpMyAdmin” as shown in the image below.

Select phpmyadmin in cpanel
Select phpMyAdmin in cPanel home page

After entering “phpMyAdmin“, you will see the image below, where you can enter the name of your database from the left and then click on “wp-post” from the window that opens.

Select WordPress database in phpmyadmin
Select WordPress database in phpMyAdmin
select wp_posts database in phpmyadmin
Select wp_posts table to access all WordPress posts and products

After entering this section, you will see the image below on the left side. Please note that in some Cpanels, there is a “Go” button on the right side of the image, and you can apply it by entering the desired code.

Otherwise, you have to click on “Console” and apply the code there and then press “Ctrl+Enter”.

Select console in SQL tab of phpmyadmin
Click on “Console” to write SQL code for deleting all products in WooCommerce

To execute WooCommerce delete all products, you can enter one of the following codes according to your needs in this section:

Bulk delete all WooCommerce simple products

The following code is for deleting all WooCommerce simple products!

Copy and paste the following code in the indicated section and then press “Ctrl+Enter” and wait for the code to be applied.

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='product');

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';

Bulk remove all WooCommerce products and categories

The following code is for deleting all related products and categories in WooCommerce.

Copy and paste the following code in the indicated section and then press “Ctrl+Enter” and wait for the code to be applied.

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='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
delete from `wp_termmeta`
where
	`term_id` in (
		SELECT `term_id`
		FROM `wp_term_taxonomy`
		WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility')
	);
delete from `wp_terms`
where
	`term_id` in (
		SELECT `term_id`
		FROM `wp_term_taxonomy`
		WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility')
	);
DELETE FROM `wp_term_taxonomy` WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility');
DELETE meta FROM wp_termmeta meta LEFT JOIN wp_terms terms ON terms.term_id = meta.term_id WHERE terms.term_id IS NULL;
DELETE FROM wp_woocommerce_attribute_taxonomies;
DELETE FROM wp_woocommerce_sessions;

WooCommerce delete all products with variations and taxonomies

The following code is for deleting all products with variations and taxonomies in WooCommerce.

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');

Bulk remove all WooCommerce product taxonomies

If you want to remove only 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);

After running each of these codes, go back to your WordPress dashboard and check if your products have been removed. If you get an error after running the SQL statement, make sure you’ve replaced all prefixes correctly with wp.

Note that the above code deletes all WooCommerce products. If you are not familiar with coding, be sure to back up your data or use the next method we are introducing which is using one of the best  WooCommerce product bulk edit plugins.

How to use the WooCommerce product bulk edit plugin to bulk remove all products in your online store?

To bulk remove all WooCommerce products using the WooCommerce product bulk edit plugin, first download, install and launch the plugin, after activation, the plugin will be automatically added to the WordPress dashboard.

WooCommerce product bulk edit plugin

Then you can run this plugin to see the list of products displayed as a table. To bulk delete all products, you must first display all of them in the product table of this plugin. For this, just set the pagination box to 100.

Then mark the checkbox next to the ID option so that all products are selected.

Change number of items in woocommerce bulk product editing plugin
Change number of items in WooCommerce bulk product editing plugin

After selecting the products, the “Delete” button will be displayed to you, if you click on it, you will see the following two options:

  • Move to trash.
  • Delete products permanently.
delete selected products in woocommerce bulk product editing plugin
Delete all selected products in WooCommerce bulk product editing plugin

If you don’t want to delete all the products, click on the “Permanently” option. In this way, all the products are completely deleted and there is no possibility of restoring them.

But if you think that in the future you may need the products to be added to your store again, click on the “Move to Trash” option. In this way, the trash option is displayed on the top of the table, if you click on it, you will see the deleted products and you can restore them to your store whenever you want.

Conclusion

In WooCommerce store, the most important part is their products, and every online store tries to display and sell high-quality products for its users. In this article, we answered one of the most common questions of online store owners regarding the different methods useful for  WooCommerce products bulk delete.

In general, you can remove your products from the store from your WooCommerce editor, through coding or using the bulk edit plugins. But WooCommerce product bulk edit plugin is the easiest and most reliable way to delete or edit products in bulk. We suggest you visit the demo of this plugin and get familiar with more features included in it.

WooCommerce product bulk edit plugin

One thought on “How to delete all products from WooCommerce stores? (with SQL and plugin)

  1. Billie Strutton says:

    I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart
Sign in

No account yet?

We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Start typing to see products you are looking for.