Created
October 14, 2020 09:02
-
-
Save mikaelz/8bd95a1c9b984ebc2893496ef476e146 to your computer and use it in GitHub Desktop.
Delete old (not current year) WooCommerce shop orders
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
DELETE | |
FROM wp_postmeta | |
WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND YEAR(post_date) != YEAR(NOW())); | |
DELETE | |
FROM wp_commentmeta | |
WHERE comment_id IN (SELECT comment_ID | |
FROM wp_comments | |
WHERE comment_post_id IN | |
(SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND YEAR(post_date) != YEAR(NOW())) | |
); | |
DELETE | |
FROM wp_comments | |
WHERE comment_post_id IN | |
(SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND YEAR(post_date) != YEAR(NOW())); | |
DELETE | |
FROM wp_woocommerce_order_itemmeta | |
WHERE order_item_id IN | |
(SELECT order_item_id | |
FROM wp_woocommerce_order_items | |
WHERE order_id IN | |
(SELECT ID | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND YEAR(post_date) != YEAR(NOW()))); | |
DELETE | |
FROM wp_woocommerce_order_items | |
WHERE order_id IN | |
(SELECT ID | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND YEAR(post_date) != YEAR(NOW())); | |
DELETE | |
FROM wp_wcpdf_invoice_number | |
WHERE order_id IN | |
(SELECT ID | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND YEAR(post_date) != YEAR(NOW())); | |
DELETE | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND YEAR(post_date) != YEAR(NOW()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment