SQL for deleting old orders
-
Hi!
I’m going to delete 50K old orders from a webshop. I have searched for a plugin for the task, but didn’t find any.
So I have decided to delete orders directly in the database. And have written these SQLs.
Are they correct or should I delete more data in other tables?DELETE FROM wp_woocommerce_order_itemmeta
WHERE meta_id > 0 and order_item_id IN (
SELECT oi.order_item_id
FROM wp_posts as p
LEFT JOIN wp_woocommerce_order_items AS oi
ON p.id = oi.order_id
WHERE p.post_type = “shop_order” AND YEAR(p.post_date) < 2017
);DELETE FROM wp_woocommerce_items
WHERE order_item_id > 0 AND order_id in(
SELECT post_id FROM wp_posts
WHERE post_type = “shop_order” AND YEAR(post_date) < 2017
);DELETE FROM wp_posts WHERE post_type = “shop_order” AND YEAR(post_date) < 2017;
Best regards
Lars Jorgensen
- The topic ‘SQL for deleting old orders’ is closed to new replies.