Support » Plugin: WooCommerce » TIP: How to delete all your orders and save you time

  • Resolved SelfOutlet

    (@selfoutlet)


    Two days ago i had to delete all my WC orders (more than 2.000 orders) because i wanted to do a clean importation of orders.

    The problem is when you have a lot of orders, you can lose hours deleting per 50 orders every time and later doing the same cleaning the trash, because more than this in the same request, the WP/Server will give you an error.

    Some people propose to edit server settings, things you can’t if you’re not the owner… So, i share with you the solution and hope that saves your time:

    1 – Make all orders as “trash”:

    With this sql request: update wp_posts set post_status = 'trash' where post_type = 'shop_order';

    You can execute it on phpMyAdmin or from the DB plugin if you have one that lets you to execute requests, like “WP-DBManager”.

    2 – Clean the trash

    For this i’ve used the plugin “Quick Empty Trash”. You have only to go to the Woocomerce Trash and clique “Empty Trash”.

    NOTE: IF you have a lot of orders to clean, it’s probably that you’ll have an error page seconds after clicking the “Empty Trash”. ยกDon’t panic! The web will give you this error after that the plugin had cleaned about 1.000 or 2.000 orders from trash. You have just to go back to Orders page and you’ll see that the trash was cleaned for 1K-2K orders. Repeat the operation clicking “Empty Trash” if you have more orders on trash… until you clean it at all.

    That’s all! You can import your saved orders or receive new orders… and the time saved you can dedicate it to something else.

    Hope that helps someone.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Postdata: You need to change the prefix of “wp_posts” by your table’s prefix.

    I recommend WP-CLI for this, you can run a command to delete all posts of a specific type, and if you add the --force directive, this avoids trash altogether.

    See:

    https://developer.wordpress.org/cli/commands/post/delete/

    For example, the following command would delete all shop-order posts, bypassing trash altogether.

    wp post delete $(wp post list --post_type='shop-order' --format=ids) --force

    Try this in a test site first!

    indrek_k

    (@indrek_k)

    There are a couple of typos in the previous post. The command that actually works for me with WP CLI v2.3.0 is:

    wp post delete $(wp post list --field=ID --post_type="shop_order") --force

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.