How to Properly Delete All WooCommerce Products

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.

Screen Shot 2015-03-04 at 10.05.53 AM

With it empty, copy and paste the following code:

So the SQL text area looks like this:

Screen Shot 2015-03-04 at 9.53.36 AM

Press the “Go” button to execute the SQL statement.

Step 3: Verify All Products are Removed

Screen Shot 2015-03-04 at 10.10.02 AM

 

Tags

28 comments

  • Thanks!! this saved me a lot of time

  • How could I delete al products images in the “same” way?

    Thanks 🙂

    • you can’t really do it that way. just go into Cpanel file manager or your ftp client of preference and select the ones you want to delete

  • Sérgio Ventura /

    Thanks a lot. It worked for me!

  • Thanks for this post. Do you know how to bulk delete categories using SQL queries too? I’m struggling to find an answer anywhere.

  • Wow, thank you! I had done my research and found plugins, and partial “how to” articles. But I’m a newb when it comes to working in PhPAdmin. Well explained and pictured for a novice to use.

  • thank you so much….it was easy with those steps…9500 products deleted with ones 🙂
    Some it was asked before, can I delete all pictures of products the same way?
    best
    Carsten

  • Ah, awesome 🙂 Deleted 30.000 products in a flash!

  • How to delete the all media associated to the product?

  • Thank you for this code, looks like it’s been working for people.

    I got this error message below, if there’s a quick way to fix this I would appreciate a reply, otherwise I’ll look for other solutions to delete all products:

    Error
    SQL query: Documentation

    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’);
    MySQL said: Documentation

    #1146 – Table ‘efd.wp_term_relationships’ doesn’t exist

  • Thank you, very, very, very helpful. Worked the 1st time perfectly.

  • Thank you very much! This worked as expected and saved me a lot of time.

  • Thanks man, saved me time!

  • WOW thanks for this code. It messed up my website. THANKS A LOT!

    • Hi Ats, that is obviously something nobody wants to hear. I’ve used it more than once and others have had success with it. Maybe there’s something you need to figure out before you copy and paste code? If you’re unsure about anything, you can always ask. Its not fair to pass blame to me or others online who take the time to share their knowledge to help others; nobody is going to accept your blame.

      • Hi King and Ats,
        I use this snipped since march on many website, sql database…and never had any problem.
        And yes I have always a backup of website ready before any changes in database.
        thx ones again King
        Carsten

    • That is hugely unfair! If you are inexperienced enough to not know to take a backup of your site and database before attempting to run SQL queries that you do not understand then you are not in a position to criticise the code of another developer. Especially when several others have already used it and have come back and commented that it works.

      Either ask a reasonable question like “I got xxxxx error, what has gone wrong?”, make a constructive critique as to how to improve the OP’s code or don’t bother posting at all.

      • King Rosales /

        Thanks Adrian! I appreciate it bro. Yeah, it happens unfortunately, but hopefully he’ll learn and graduate from not blaming others 🙂

  • Brilliant! This worked perfect, best solution I’ve found – 30,000+ products – Bah-bye!!! Gone 🙂

    Thanks for sharing this.

  • Thank you so much!!! 🙂

  • This clears out the products database. However, in the Woocommerce “Stock” tab options, the products are still appearing. When I use the “Actions” button (the pencil to edit the product), I get this response “You attempted to edit an item that doesn’t exist. Perhaps it was deleted?”.
    I’m looking to find what needs to be done to clear this area too.

  • Dominic Tschan /

    Thanks a lot for that code, saved me some hours!
    Attributes are not deleted. Could you tell me what I need to add in the code so that attributes are deleted too?

    Thanks
    Best regards
    -Dominic

    • King Rosales /

      Hi Dominic, Yes I’ll be adding to this tutorial shortly. Sorry I cant do it right away, but I’ll do it as soon as I get the chance! thanks for your comment!

  • problem solved! can you delete my comment please ? thank you!

Leave a Reply

Your email address will not be published.

top