=== CatCode Order Archive for WooCommerce ===
Contributors: catcodestudio
Tags: woocommerce, orders, archive, hpos, performance
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Move old orders out of the WooCommerce order tables into a compact archive. Analytics, customer totals and privacy requests keep counting them.

== Description ==

Years of orders make the orders screen, order searches and every plugin that queries orders slower. Deleting old orders is not an option: you lose reports, customer history and the records you have to keep.

Order Archive moves orders older than a period you choose (for example 24 months) out of the order tables into one compact archive table — and back with one click.

= What happens to an archived order =

* Every row of the order — order data, addresses, meta, line items, order notes and refunds — is packed into one compressed record. The copy is read back and checked before a single row is removed, and each order moves in its own database transaction.
* WooCommerce Analytics keeps counting archived orders: its own tables are not touched. In the Orders report archived orders keep their order number.
* Customers keep their downloads, their order count and their "total spent", so loyalty and role plugins see the same numbers.
* Privacy: Tools → Export Personal Data includes archived orders; Erase Personal Data anonymises them when WooCommerce is set to remove order data on request; the WooCommerce retention periods (anonymise completed and refunded orders, trash failed and cancelled orders) apply to archived orders too.
* The archive has its own search (order number, e-mail, name, phone, company, product, SKU) and a read-only view of each order. A search on the orders screen tells you when archived orders match, and old links to an archived order open its archived copy.
* Restore puts the very rows back with their own IDs. To refund or edit an archived order, restore it first.

= What stays where it is =

* Pending, processing and on-hold orders are never archived.
* An order with a payment, completion or refund inside the period stays.
* Orders tied to a subscription (WooCommerce Subscriptions parent and renewal orders) stay.

= Storage =

Works with High-Performance Order Storage (HPOS), with the classic posts storage and with compatibility mode. If you switch WooCommerce between the two after archiving, restored orders are copied into the storage WooCommerce uses at that moment.

= Free features =

* Archive by age and status, in short steps with a progress bar (no time-outs on large shops)
* Search, order view, restore one order or all of them
* Analytics, customer totals, privacy export, erasure and retention support
* Put archived orders back into Analytics after "Delete previously imported data"


= Before you start =

Make a database backup before the first large run. Deleting the plugin keeps the archive table, so nothing is lost — but archived orders stay out of sight until the plugin is back. Use Tools → "Restore all archived orders" if you want to leave the plugin.


== Installation ==

1. Install and activate the plugin (WooCommerce must be active).
2. Open WooCommerce → Order archive → Move to archive.
3. Choose the age and the statuses, save, and press "Archive matching orders".

== Frequently Asked Questions ==

= Will my reports change? =

No. WooCommerce Analytics keeps its own tables and they are not touched. Only "Delete previously imported data" under Analytics → Settings removes archived orders from Analytics, because the re-import that follows sees live orders only. Tools → "Put archived orders back into Analytics" fixes that.

= What about the old WooCommerce reports (WooCommerce → Reports)? =

The legacy reports read the order tables directly, so they do not include archived orders.

= Can I refund an archived order? =

Restore it first (one click on the archived order), then refund it as usual.

= Do customers see archived orders? =

Not in the free version: My account → Orders lists live orders only, and order links in old e-mails stop working until the order is restored.

= What about other plugins that keep order IDs? =

Invoices, shipping labels and similar records of other plugins stay; when they look an archived order up, WooCommerce answers that it does not exist. Exclude orders from archiving with the `catcode_oarc_can_archive` filter if a plugin needs them.

If another plugin saves an archived order anyway (for example a payment webhook that loaded the order just before it was archived), the order is first restored from the archive and the change lands on the full order, with an order note about it. A payment notification that only looks the order up (a refund or chargeback months later) finds nothing — restore the order before handling such a case; that is why the default age is 24 months.

= Is it safe? =

Each order moves in one database transaction (InnoDB): the copy is written, read back and compared before the rows are removed, and a failure rolls everything back. Restore refuses to overwrite: if the order ID is taken by something else, the order stays in the archive.

== Changelog ==

= 1.0.0 =
* First release.
