Deleting Woocommerce products using Mysql commands

mysql> 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');
Query OK, 497631 rows affected (4 min 10.74 sec)

mysql>
mysql> DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');

Query OK, 1419875 rows affected (13 min 16.68 sec)

mysql> DELETE FROM wp_posts WHERE post_type = 'product';
Query OK, 66618 rows affected (51.91 sec)

Very useful commands especially when you need to purge large amount of products.

Leave a Reply

Your email address will not be published. Required fields are marked *