Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Last active June 20, 2018 14:58
Show Gist options
  • Save tallesairan/e7b80a7a5cd9203c0f38839f6ca6e76a to your computer and use it in GitHub Desktop.
Save tallesairan/e7b80a7a5cd9203c0f38839f6ca6e76a to your computer and use it in GitHub Desktop.
Delete all WooCommerce products, terms, postmeta and relationships #wp #wpdb #intermediary
-- Delete all WooCommerce products
DELETE FROM wpcl_term_relationships WHERE object_id IN (SELECT ID FROM wpcl_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wpcl_postmeta WHERE post_id IN (SELECT ID FROM wpcl_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wpcl_posts WHERE post_type IN ('product','product_variation');
-- Delete all WooCommerce terms
DELETE a,c FROM wpcl_terms AS a
LEFT JOIN wpcl_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wpcl_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag';
-- Delete All WooCommerce relationships
DELETE a,c FROM wpcl_terms AS a
LEFT JOIN wpcl_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wpcl_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_cat'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment