Last active
February 27, 2021 14:55
-
-
Save etiennetremel/6190256 to your computer and use it in GitHub Desktop.
WooCommerce, Delete all products from DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete Product term relationships | |
DELETE | |
term_relationships.*, | |
term_taxonomy.*, | |
terms.* | |
FROM wp_term_relationships AS term_relationships | |
INNER JOIN wp_term_taxonomy AS term_taxonomy | |
ON term_relationships.term_taxonomy_id=term_taxonomy.term_taxonomy_id | |
INNER JOIN wp_terms AS terms | |
ON term_taxonomy.term_id=terms.term_id | |
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product'); | |
# Delete attachement & Product variation including metas | |
DELETE | |
postmeta.*, | |
posts.* | |
FROM wp_posts AS posts | |
INNER JOIN wp_postmeta AS postmeta | |
ON postmeta.post_id = posts.ID | |
INNER JOIN wp_posts AS postparent | |
ON postparent.ID = posts.post_parent | |
WHERE postparent.post_type = 'product'; | |
# Delete product meta | |
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product'); | |
# Delete all products | |
DELETE FROM wp_posts WHERE post_type = 'product'; | |
# Delete all product categories | |
DELETE | |
term_taxonomy.*, | |
terms.* | |
FROM wp_term_taxonomy AS term_taxonomy | |
INNER JOIN wp_terms AS terms | |
ON terms.term_id = term_taxonomy.term_id | |
WHERE term_taxonomy.taxonomy = 'product_cat'; | |
# Finally, delete everything from WooCommerce tables | |
DELETE FROM wp_woocommerce_downloadable_product_permissions; | |
DELETE FROM wp_woocommerce_termmeta; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment