I want to delete completed all orders in woocommerce by using a single my sql query. Because, I\'m having a problem with my WordPress Dashboard
UPDATE wp_posts
SET post_status = 'trash'
WHERE post_type = 'shop_order'
AND post_status = 'wc-completed'
This code does not completely eliminate the system or base of Order data, send it to the trash.
Woocommerce > Orders > Trash and click Empty Trash.
- wc-completed
- wc-pending
- wc-processing
- wc-on-hold
- wc-cancelled
- wc-refunded
- wc-failed
And you are specifying them inside the clause IN ('status')
UPDATE wp_posts
SET post_status = 'trash'
WHERE post_type = 'shop_order'
AND post_status IN ('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-cancelled', 'wc-refunded', 'wc-failed')
My solution would be just deleting all the orders(If you're moving from a shop with demo data to your new site). You can do this using following SQL-queries.
DELETE FROM wp_woocommerce_order_itemmeta
DELETE FROM wp_woocommerce_order_items
DELETE FROM wp_comments WHERE comment_type = 'order_note'
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' )
DELETE FROM wp_posts WHERE post_type = 'shop_order'
I solved this by first setting all the relevant orders to trash:
UPDATE wp_posts SET post_status = 'trash' WHERE post_type = 'shop_order';
If you have too many posts to get through when pressing Empty Trash and you get a PHP error, you can run the following SQL to remove them instead:
DELETE FROM wp_posts
WHERE post_type = 'shop_order'
AND post_status = ‘trash’
Woocommerce orders are stored in the post
table, postmeta
table, woocommerce_order_items
, and woocommerce_order_itemmeta
tables. Various parts of an order are stored in different tables. addition to that the order status is managed through the taxonomies
which stores the order status list.
Anyone who is/will be writing this query have to write at least 5-6 queries minimum or
single large join query.
So, my suggestion to you should uninstall WooCoommerce, if you don't have much larger product setup. To do this you can follow this link which will delete the data
To use the native Woocommerce functionality by the maximum, you can do it following way. Move all orders to trash with SQL:
UPDATE wp_posts SET post_status = 'trash' WHERE post_type = 'shop_order';
And then go to Woocommerce -> Orders -> Trash and click Empty Trash.