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.
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.