Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete completed orders in woocommerce using a my sql query

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. I can't view the completed orders from the back-end. It's getting blank. I have 7,823 Completed Orders. I hope that's why I seen white page when I'm going to view the Completed Orders.

Is there have a way to, That I can delete all Completed Orders using MySQL query. So, that I can run it in PHPMYADMIN.

Have any suggestions.

like image 388
yeshansachithak Avatar asked Jul 23 '14 07:07

yeshansachithak


People also ask

How do I mass delete orders in WooCommerce?

If you need to clean up your WooCommerce order history, bulk deleting orders is a quick and easy way to do it. Simply navigate to the Orders page, select the orders you want to delete, and then click on the Bulk Actions > Delete menu item.

Where are WooCommerce orders stored in the database?

Are WooCommerce Orders Stored in the Database? Yes, they are stored in the wp_posts table. WooCommerce orders are a Custom Post Type (CPT) so they're located in the wp_posts table. If you search the post_type field for 'shop_order', your SQL query will retrieve all your WooCommerce orders.

Can we use order by in delete query?

You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the condition in the WHERE clause. You cannot use ORDER BY or LIMIT in a multiple-table DELETE .


2 Answers

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 the 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';
like image 67
Mauran Muthiah Avatar answered Oct 23 '22 15:10

Mauran Muthiah


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.

like image 37
Eugene Ionichev Avatar answered Oct 23 '22 15:10

Eugene Ionichev