How to delete WooCommerce products and categories instantly

by Giannis Boulmetis
59 views

While developing a wordpress eshop, or if you own one, you might need to remove all your products and strart fresh, for either testing porpuses or even for a new beginning. Remove hundrends or thousend of products through woocommerce’s interface can take a while. Not any more!

With the use of the following mysql query we can remove thousends of products in no time!

Here is how:

1. Login to your admin area and access your database

You can access your database either with phpMyAdmin or with a desktop application.
Before moving further ensure that you are viewing the correct database and take a backup just in case.

2. Go to the SQL tab

Select the SQL tab on the top. It will give you an empty area to write.

3. Execute your SQL query

Final step is to run the following sql query and all the products will be removed.

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

Warning: Remember that if your database perfix is not wp_ you will have to change that on the above sql script with the correct prefix.

Now check if all the products are removed!

 

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy