Archiving WooCommerce Orders Plugin
I found this plugin to be able to archive orders of WooCommerce.
https://github.com/woocart/woocommerce-archive-orders-table
This plugin makes it really easy to archive orders into another table to remove the load of the database.
I have added some of the functionality that is included in the plugin.
Migrating order data
After installing and activating the plugin, you’ll need to migrate orders from post meta into the newly-created orders table.
The easiest way to accomplish this is via WP-CLI, and the plugin ships with five commands to help:
Counting the orders to be migrated
If you’d like to see the number of orders that have yet to be moved into the orders table, you can quickly retrieve this value with the count
command:
$ wp wc orders-table count
Options
–duration=<no-of-days>Set the duration of days, starting today, to skip archiving of orders.For Ex: Setting this value to 45 will skip orders for the last 45 days from archiving.
Analysing extra meta keys added by plugins
The first step in the migration process is to analyse the extra meta keys added by the plugins based on which additional columns are created in the orders table.
$ wp wc orders-table optimize
Creating columns in the table for additional meta keys
The populate
command creates the additional columns in the database to accomodate data for the additional meta keys associated with the orders data.
$ wp wc orders-table populate
Migrate order data from post meta to the orders table
The migrate
command will flatten all post meta values for WooCommerce orders into a flat database table, optimized for performance.
$ wp wc orders-table migrate
Orders are queried in batches (determined via the --batch-size
option) in order to reduce the memory footprint of the command (e.g. “only retrieve $size
orders at a time”). Some environments may require a lower value than the default of 100.
Please note that migrate
will delete the original order post meta rows after a successful migration. If you want to preserve these, include the --save-post-meta
flag!
Options
–batch-size=<size>The number of orders to process in each batch. Default is 100 orders per batch.Passing `–batch-size=0` will disable batching.–duration=<no-of-days>Set the duration of days, starting today, to skip archiving of orders.For Ex: Setting this value to 45 will skip orders for the last 45 days from archiving.–save-post-metaPreserve the original post meta after a successful migration. Default behavior is to clean up post meta.
Copying data from the orders table into post meta
If you require the post meta fields to be present (or are removing the custom orders table plugin), you may rollback the migration at any time with the backfill
command.
$ wp wc orders-table backfill
This command does the opposite of migrate
, looping through the orders table and saving each column into the corresponding post meta key. Be aware that this may dramatically increase the size of your post meta table!
Options
–batch-size=<size>The number of orders to process in each batch. Default is 100 orders per batch.Passing `–batch-size=0` will disable batching.
Download Plugin: https://github.com/woocart/woocommerce-archive-orders-table