How To Bulk Delete Pending Payment Orders from Managed WooCommerce Hosting

Reading Time: 2 minutes

There may be times when bulk deleting orders becomes necessary, such as orders which have been moved to the trash, or orders with the status of payment pending on a store. Deleting orders from wp-admin can be a slow, tedious process, even if you increase the number of orders that load at one time from the default value of 20 in the screen options.

This is where using the WP-CLI comes in handy, using the wp post delete command (for detailed directions on this command, see wp post delete).

Preparing to Run Commands

First, you will need to login to your portal via SSH. For directions on generating credentials for sFTP/SSH creds from your site manager, see Finding Your SFTP/SSH Credentials in Managed WordPress Portal. For help using SSH, see Logging into Your Server via Secure Shell (SSH).

  1. Log in, then enter:

cd html

This will change the directory to the html directory where you can run the WP-CLI commands.

  1. To create a database backup before bulk deleting pending payment orders, run this command;

wp db export

  1. You can use the gzip compress down the resulting sql file.

gzip sitebackup.sql

Cleaning Up Your Pending Orders

  1. To completely delete only orders which have a post status of wc-pending, using this WP-CLI command;

wp post delete $(wp post list --post_type='shop_order' --post_status=wc-pending --format=ids --force)

  1. If you do not want to skip moving those orders to the trash, you can run this command;

wp post delete $(wp post list --post_type='shop_order' --post_status=wc-pending --format=ids)

  1. To delete any orders which have been moved to the trash, essentially “emptying the trash folder”, run this command;

wp post delete $(wp post list --post_type='shop_order' --post_status=trash --format=ids --force)

Using the WP-CLI command will be a much faster method than trying to manually bulk delete those orders from wp-admin on the site, saving you time to spend on the real work of running your business. See our website for more information about our Managed WooCommerce Hosting.

Author Bio

About the Author: Luke Cavanagh

WooCommerce Specialist at Liquid Web. Devoted husband and Tween wrangler. Synthwave enthusiast. Jerry Goldsmith fan. Doctor Who fan and related gubbins.

Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support