Created
April 21, 2021 08:18
-
-
Save twmbx/73fe4d63fdf592a3ae93673fdb4c8239 to your computer and use it in GitHub Desktop.
WooCommerce Delete All Products, Product Attachments and custom Product Attributes
This file contains 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
-- Products | |
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'); | |
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product'); | |
DELETE FROM wp_posts WHERE post_type = 'product'; | |
-- Product Attachments (also need to delete files physically) | |
DELETE FROM wp_postmeta | |
WHERE post_id IN | |
( | |
SELECT id | |
FROM wp_posts | |
WHERE post_type = 'attachment' | |
) | |
; | |
DELETE FROM wp_posts WHERE post_type = 'attachment'; | |
-- Attributes | |
DELETE FROM wp_terms WHERE term_id IN | |
( | |
SELECT term_id | |
FROM wp_term_taxonomy | |
WHERE taxonomy LIKE 'pa_%' | |
); | |
DELETE FROM wp_woocommerce_attribute_taxonomies WHERE attribute_name LIKE '%'; | |
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); | |
-- Nuke this, it's bothersome and sticky. | |
-- Stores attributes even after they've been deleted from the wp_attribute_taxonomies | |
DELETE FROM wp_options WHERE option_name LIKE '_transient_wc_attribute_taxonomies'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment