Rule 1: one list of columns
Every column the plugin can export is declared once, in one catalog: its label, its group (order, billing, shipping, items), whether it is a per-line column, and how its value is read from the order. The column picker is drawn from that catalog, the export reads values through it, and a saved profile (Full edition) is a list of its keys. There is no second list, so the screen can never offer a column the export cannot fill.
When a profile is read, any column key the catalog no longer knows — say one an extension added and the extension has since been deactivated — is dropped rather than exported empty.
Rule 2: the export streams
A store with fifty thousand orders is exactly the store that wants an export, and loading fifty thousand orders into memory is how an export becomes a fatal error. So the plugin:
- writes the header row first;
- asks WooCommerce's
wc_get_orders()for 200 orders at a time, oldest (lowest id) first, using your status and date filters; - writes each order's row (or rows) straight to the file;
- asks for the next 200, until none are left.
Using wc_get_orders() means HPOS and the classic order tables are the same code path, and refunds are never exported as orders. The Containing product ID filter (Full edition) is applied to each batch after it is loaded, because WooCommerce has no "orders containing this product" query.
One row per order, or one per line
The shape of the file follows from the columns you chose:
- No item columns — one row per order. To see what was bought in one cell, use Items (one cell):
2 × Mug, 1 × Tea towel. - Any item column (Full edition) — one row per order line. The order's columns repeat on every row, so the file sorts and filters correctly in a spreadsheet. An order with no lines still gets one row.
Rule 3: the file is safe to open
A spreadsheet treats a cell beginning with =, +, - or @ as a formula. A customer who types =HYPERLINK(…) into their address is attacking whoever opens the export, not your website. So every cell beginning with one of those characters, or with a tab or carriage return, is written with a leading ', which spreadsheets show as text.
The file also begins with a UTF-8 byte order mark. Without it, Excel on Windows opens the file in the computer's local encoding and every accented name is mangled.
Downloading
Download CSV checks your permission and a security nonce, then sends the file straight to the browser, with no-cache headers, as orders-YYYYMMDD-HHMMSS.csv. Nothing is written to disk.
Scheduled delivery — Full edition
When at least one profile has a schedule, the plugin schedules one WordPress cron event, gmoe_scheduled_exports, that runs once a day (first run about an hour after the profile is saved). When it runs:
- Every Every day profile is exported.
- Every Monday profiles are exported only when the run falls on a Monday in your site's timezone.
- Each export is written to a temporary file in
wp-content/uploads/gmoe-exports/. The folder is given an emptyindex.htmland an.htaccessthat denies web access. - The file is attached to an email titled "Order export: {profile name}", saying how many orders were exported.
- The file is deleted the moment the email has been handed off. It is a list of your customers' names, addresses and phone numbers, and it does not stay on the server a moment longer than the email needs it.
The event is removed when no profile is scheduled any more.
What a scheduled export contains: the profile's saved columns and its status and product filters, over the period just ended — the rolling rule. A daily profile covers yesterday; a weekly one covers the seven days before the Monday it runs, both in your store's own calendar. The dates a profile was saved with are not used for a scheduled run: otherwise the same fixed range would be sent every morning, and a profile saved with no dates would send the shop's whole order history every day. A profile with no schedule keeps its dates and uses them when you click Download.
An empty Send to sends to the store's admin address.
Because WordPress cron runs when someone visits the site, a quiet site may send its daily email later in the day. A real server cron calling wp-cron.php makes the timing exact.
Worked example (full edition)
A warehouse wants each morning's packing list.
- Columns: Order number, Shipping name, Shipping address, Shipping city, Shipping postcode, Shipping country, Item SKU, Item quantity.
- Statuses: Processing.
- Name "Packing list", Every day, Send to
warehouse@example.com, Save profile. - Each morning the warehouse receives a CSV with one row per line of yesterday's orders that are still in Processing.
