How to automatically delete old WooCommerce orders?

Would you like to automatically delete old WooCommerce orders? Old orders might be redundant and consume memory in your database. So, it’s a wise move to remove all redundant orders from the WordPress database. You can manually delete the old orders, but it takes time and is a hassle every day for you.

Let’s use the plugin for this. It’s a simple, set and forget WordPress plugin with no bloat whatsoever.

Get Started with WC Auto Delete Old Orders Plugin now. It automatically takes control of the old orders. You just install and the plugin takes your care.

Simple Pricing

$19

per year

Annual Package

Great for folks who are just getting started and prefers annual payment.

1 Site


1 Year of updates / billed yearly


7 days money back guarantee *


Priority Support

$39

one time

Lifetime Package

Great for professionals are confident and prefers lifetime purchase.

1 Site


Lifetime Updates


7 days money back guarantee *


Priority Support

Not convinced? We offer a 100% money back guarantee for all purchases. Try our product with confidence, and if you don’t like it, we’ll make it right.

* 100% refund when the product had a bug/problem I couldn’t resolve.

* Checkout and Payment are processed from Freemius – the reseller of the plugin.

Have pre-sale questions? Contact Us.

How does the plugin work?

The plugin automatically deletes old orders (orders older than 3 months by default, customizable in Settings). It uses the Action Scheduler to schedule the deletion. Every 5 minutes it checks if any order is older than 3 months (or specified in settings). Then it deletes maximum of 10 orders in an 5 minutes interval. So, you won’t be facing timeout in case of large number of orders.

You can see the tasks in Tools > Scheduled Actions, search for “wc_delete_old_orders_process”.

Settings

In the WooCommerce > Settings > General, you can set how many months old orders you want to get automatically deleted.

That’s all. If you like this plugin, check out our other plugins.

author avatar
Sanjeev Aryal
Sanjeev Aryal is the creative mind behind Mini Plugins, a brand dedicated to developing lightweight, efficient WordPress plugins. He also writes occasionally and contributes to WordPress community.

5 responses to “How to automatically delete old WooCommerce orders?”

  1. Mauro Gonçalves Avatar
    Mauro Gonçalves

    Very good code! Thanks for sharing it. Is it possible to change this to delete orders that have already been cancelled? What to change in the code?

  2. Carlos Vesta Avatar
    Carlos Vesta

    I’m using the plugin, but it only deletes 3 orders per action.
    How should I delete all orders for these 3 months?

    1. Sanjeev Aryal Avatar

      Hi Carlos, if you have so many old orders, the PHP script will time out before it could delete all order at once. Maybe you can just run the process in a 5 minutes interval than in a day?

      Hope that will help!

  3. Julian Grippo Avatar
    Julian Grippo

    hi? how are you?

    i need help trying to implement this code to bookings of woocommerce


    heres is the code:

    public function process_delete() {
    if ( ! function_exists( ‘get_wc_booking’ ) ) {
    return;
    }
    $args = array(
    ‘date’ => ‘update_status(‘completed’);
    \wp_update_post( $booking ->get_id() );
    }
    }
    }
    “”
    and this is the order code thats work
    “”
    public function process_delete() {
    if ( ! function_exists( ‘wc_get_orders’ ) ) {
    return;
    }
    $args = array(
    ‘date_created’ => ‘update_status(‘completed’);
    \wp_delete_post( $order->get_id() );
    }
    }
    “”
    I don’t know what’s wrong, if it’s a misspelled function or what.

    1. Sanjeev Aryal Avatar

      Hi Julian, thanks for reaching out. Unfortunately, it’s hard to debug without details on the booking plugin you’re using.

Leave a Reply

Your email address will not be published. Required fields are marked *