Last active
October 28, 2024 04:07
-
-
Save mikaelz/d574457cb22f1f79f337 to your computer and use it in GitHub Desktop.
Remove all WooCommerce products from database via SQL
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
<?php | |
require dirname(__FILE__).'/wp-blog-header.php'; | |
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')"); | |
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'"); | |
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)"); | |
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))"); | |
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))"); | |
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')"); | |
$wpdb->query("DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL"); |
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
-- 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 |
Does anyone know how to delete all products, with image data etc, before a specific date? Like the creation date of the product?
Insert product query from CSV in Mysql for woocommerce?
Is it available/
I run some queries like all of you mentioned. But ORDERS still there. Missing that :))
Woocommerce changed the orders structure in the database and now saved at
different tables
…On Wed, 1 Nov 2023, 11:01 Nguyễn Minh Khôi, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I run some queries like all of you mentioned. But ORDERS still there.
Missing that :))
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/mikaelz/d574457cb22f1f79f337#gistcomment-4745733>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA22HDVYZFS6K7DISS6AOEDYCIFXRBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTANBUGM2TGNFHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
hello i need help i want to remove my all out of stock product anyone can guide me
how i can do this through any plugin or through any way?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! @ruscon
I have added a custom taxonomy product_brand to the list.