There may come a time when you may need to remove all the products in your WooCommerce powered ecommerce website. There’s just no easy way to do this natively in WooCommerce. I needed to do it because I changed the my product data XML file I was using to import into the site. It’s pretty straight forward, but to do it properly, you have to make sure you’re deleting all the additional data such as taxonomy, relationships, etc connected with all the existing products.
I tried using the WooCommerce Remove All Products plugin to do this, but first it didn’t work with my WordPress 4.1.1 installation and second it doesn’t remove any taxonomy.
So, to remove all your products you’ll need access to your PhpMyAdmin or some other tool like Sequel Pro to edit your WordPress database. I’ll be using PhpMyAdmin because its the easiest.
Step 1: Login to Your PhpMyAdmin
If you have more than one database, make sure you click on the correct database. If you’re not sure because you have more than one WordPress installation on the same domain, open a table and look for “wp_options”, you’ll be able to see the URL of the website you’re making changes to.
Step 2: Run the SQL Statement
If you are on the correct database, click on the SQL tab on the top right. It might be empty or have an SQL statement there from a previous command.
With it empty, copy and paste the following code:
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';
So the SQL text area looks like this:
Press the “Go” button to execute the SQL statement.
Leave a Reply