Bulk Delete Pending Payment Orders In MWCH
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).
- Log in, then enter:
This will change the directory to the html directory where you can run the WP-CLI commands.
- To create a database backup before bulk deleting pending payment orders, run this command;
wp db export
- You can use the gzip compress down the resulting sql file.
Cleaning Up Your Pending Orders
- 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)
- 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)
- 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.
About the Author: Luke Cavanagh
Product Operations Manager at Liquid Web. Devoted husband and Tween wrangler. Synthwave enthusiast. Jerry Goldsmith fan. Doctor Who fan and related gubbins.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Guide on Connecting to Remote Servers Using SSH in Linux, Windows, or macOS SystemsRead Article
New User Tutorial: What is DNS?Read Article