Skip to content

Instantly share code, notes, and snippets.

@Nav-Appaiya
Last active February 7, 2024 09:36
Show Gist options
  • Save Nav-Appaiya/cc21ae8e5a8111c9ac02f3be79d0caeb to your computer and use it in GitHub Desktop.
Save Nav-Appaiya/cc21ae8e5a8111c9ac02f3be79d0caeb to your computer and use it in GitHub Desktop.
Delete all woocommerce orders before a specific data [with SQL]
DELETE FROM wp_woocommerce_order_items WHERE order_id IN ( SELECT ID FROM wp_posts WHERE post_date BETWEEN '2019-01-01' AND '2023-01-01');
DELETE FROM wp_comments WHERE comment_type = 'order_note' AND comment_post_ID IN ( SELECT ID FROM wp_posts WHERE post_date BETWEEN '2019-01-01' AND '2023-01-01' AND post_type='shop_order');
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_date BETWEEN '2019-01-01' AND '2023-01-01' AND post_type = 'shop_order');
@Nav-Appaiya
Copy link
Author

DELETE FROM wp_woocommerce_order_items WHERE order_id IN ( SELECT ID FROM wp_posts WHERE post_date >= '2019-01-01')

DELETE FROM wp_comments WHERE comment_type = 'order_note' AND comment_post_ID IN ( SELECT ID FROM wp_posts WHERE post_date BETWEEN '2019-01-01' AND '2023-01-01')

DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_date BETWEEN '2019-01-01' AND '2023-01-01')

DELETE FROM wp_posts WHERE post_type = 'shop_order' AND post_date BETWEEN '2019-01-01' AND '2023-01-01';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment