Created
April 23, 2021 08:08
-
-
Save nunomorgadinho/ede41db70ed40c358c9c95073bbd49d9 to your computer and use it in GitHub Desktop.
SQL query to remove old orders in WooCommerce
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 | |
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_date < '2017-01-01' | |
) | |
) | |
DELETE | |
FROM wp_woocommerce_order_items | |
WHERE order_id IN ( | |
SELECT ID | |
FROM wp_posts | |
WHERE post_date <= '2017-01-01' | |
) | |
DELETE | |
FROM wp_comments | |
WHERE comment_type = 'order_note' | |
AND comment_post_ID IN ( | |
SELECT ID | |
FROM wp_posts | |
WHERE post_date <= '2017-01-01' | |
) | |
DELETE | |
FROM wp_postmeta | |
WHERE post_id IN ( | |
SELECT ID | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND post_date <= '2017-01-01' | |
) | |
DELETE | |
FROM wp_posts | |
WHERE post_type = 'shop_order' | |
AND post_date <= '2017-01-01' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Delete the children items first and then remove the parents last. DO NOT RUN THIS WITHOUT TESTING FIRST. I accept no responsibility for lost data.