Here are two handy SQL commands that are probably most helpful if you are doing bulk imports. I am using WP All Import, and sometimes I find that my Layered Nav disappears after an import. The only fix I have found is to remove all attributes (!) and then run the import again.
Deleting attributes one at a time is a pain if you have ten.
It’s always a good idea to take a backup of your database before you run these kinds of commands. If you don’t know how to do that, you probably shouldn’t attempt this.
NB: This will not remove any images that were uploaded into Media Library in the process of creating products (post_type = attachment).
Remove all attributes from WooCommerce
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);
Delete all WooCommerce products
DELETE FROM wp_term_relationships 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');
Delete orphaned postmeta
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL
Google Analytics reckons this is the most popular page on my website. If I saved you some time, please let me know in the comments below!