WooCommerce: remove empty SKU products

At work, we got ourselves a nice WooCommerce shop. Using WP All Import, it automagically imports the products and updates stock. But somehow in we ended up with products in our database with no SKU.

Removing one of those products, and then rerun the import, seemed to work. So maybe these products where in the product feed once without a SKU. Who knows. Anyways, I wanted them gone, and didn’t want to delete the entire database, afraid of what Google may think of that.

So I checked the database a bit and came up with a SQL query. First, to check if you have products with empty SKU’s as well, you could run something like this:

To remove the products, I think this should do. Of course this wouldn’t delete the files in your upload folder. If you want to delete those as well, you might want to write a script that selects the records, and then removes the images as well.

 

7 thoughts on “WooCommerce: remove empty SKU products

    • I don’t have a running WooCommerce anymore. But if I were you I’d first query the suplicate SKU’s. See how many you get. You could then also create a delete query from that, using the id’s with some creative copy & pasting.

  1. Pingback: Eliminar productos duplicados por SKU en Woocommerce - Kawaineko

  2. Hello –
    This could be my saviour! I have a strange problem with my database where it is adding around 30% additional product variations when I import the database (they all have unique IDs, but no SKU). Even when I delete everything and try again, the same thing happens.

    I can use this to delete those products, but is there a way of getting rid of the product variations too?
    I know there are around 2,500 variations that need to be deleted, but the result using the query below only brings up 200 products.

    Any help would be very much appreciated!

    Kind regards,

    Ollie

    • Just to update, I replaced ‘product’ with ‘product_variation’ and it worked like a dream.
      Thanks for posting this on your website. I have spent over a week trying to solve all sorts of database headaches, and this has saved me!

Leave a Reply

Your email address will not be published.