Querying WooCommerce Orders by Date and Status with WC_Query
Filtering WooCommerce orders by both date and status is a common reporting requirement. A direct WC_Query is useful when orders are stored as WordPress posts because it provides familiar arguments for post_type, post_status, date_query, sorting and pagination. The following example returns only matching orders instead of loading the complete order history into PHP.
Modern WooCommerce can use High-Performance Order Storage, where orders are not stored as shop_order posts. That change makes a direct query appear empty even when matching orders exist. The reliable approach is to identify the active storage model, use WC_Query for legacy post-backed stores and WC_Order_Query for HPOS. Status slugs, time zones and pagination also need careful handling, particularly for Australian stores.
How the underlying WooCommerce query model works
WC_Query extends WordPress’s WP_Query class and normally powers WooCommerce product searches. It still works as a low-level query builder for legacy order posts because shop_order is a registered WordPress post type. The order details then come from WooCommerce order objects rather than ordinary posts.
Legacy WooCommerce installations store orders as posts with a post type of shop_order. Their lifecycle states appear in post_status with a wc- prefix, while the associated products and totals live in order metadata. A direct query therefore needs WordPress arguments rather than the product arguments normally passed to WC_Query.
HPOS stores order data in dedicated WooCommerce tables. A query looking for shop_order posts cannot see those records. This is why an apparently correct WC_Query can produce zero results on a modern site, and why storage compatibility should be checked before troubleshooting dates or statuses.
Building a date and status filter
The following query returns processing and on-hold orders created during July 2025 from a legacy post-backed store:
$args = array(
'post_type' => 'shop_order',
'post_status' => array( 'wc-processing', 'wc-on-hold' ),
'posts_per_page' => 25,
'paged' => 1,
'orderby' => 'date',
'order' => 'DESC',
'date_query' => array(
array(
'column' => 'post_date',
'after' => '2025-06-30 23:59:59',
'before' => '2025-08-01 00:00:00',
'inclusive' => false,
),
),
);
$wc_query = new WC_Query( $args );
$orders = $wc_query->get_posts();
The post_type argument limits the search to orders, while post_status accepts either one status or an array. The date_query uses the order creation date stored in post_date. With exclusive boundaries, the example includes every second in July but excludes orders created exactly at midnight on 1 August.
Each returned object is still a WordPress post. Use wc_get_order() to obtain the WooCommerce order object and read its totals or customer details:
foreach ( $orders as $order_post ) {
$order = wc_get_order( $order_post->ID );
if ( ! $order ) {
continue;
}
$created = $order->get_date_created();
$date = $created ? $created->date_i18n( 'Y-m-d H:i:s' ) : '';
printf(
'#%d — %s — %s — %s',
$order->get_id(),
esc_html( $date ),
esc_html( wc_get_order_status_name( $order->get_status() ) ),
wp_kses_post( wp_strip_all_tags( $order->get_formatted_order_total() ) )
);
}
Always pass the post ID to wc_get_order() rather than treating the returned post as the complete order. This also gives the report access to WooCommerce totals, payment details and status labels.
Handling Australian time zones and date windows
WordPress stores legacy order dates in both local site time and UTC. The post_date column follows the time zone selected under the WordPress general settings, which is normally the best choice for a report showing Australian local dates. Stores using post_date_gmt need boundaries converted to UTC instead.
The distinction matters in cities such as Sydney, Melbourne and Brisbane, which change between AEST and AEDT. Perth remains on AWST, while Adelaide uses a half-hour offset. A fixed UTC reporting window can therefore start or finish at different local times depending on the date and the store’s configured zone.
For a business with one location, configure the WordPress time zone to the Australian city where the store operates. For a store serving several states, decide whether the report represents the site’s chosen zone or a national Australian window, then apply that rule consistently. Daylight-saving changes should be included in automated reconciliation tests.
A Melbourne venue preparing compliance records should also check the applicable poker tournament rules before treating gaming-related orders as a special reporting class. An event report may need to separate deposits, refunds and cancelled registrations rather than treating every positive order as income.
Selecting reliable order status values
Legacy queries use machine-readable status values such as wc-pending, wc-processing, wc-on-hold, wc-completed, wc-cancelled, wc-refunded and wc-failed. These are not the translated labels shown in the WordPress administration area. Passing Completed instead of wc-completed will not match the stored value.
An array is appropriate when the report combines operational states:
'post_status' => array(
'wc-processing',
'wc-on-hold',
'wc-completed',
),
This is useful for an operations report covering orders that have progressed but have not been cancelled or refunded. A finance report may instead need only completed orders, followed by a separate calculation of refunds.
Custom order statuses registered through wc_register_order_status() also receive the wc- prefix in legacy post records. The status should be confirmed with wc_get_order_statuses() rather than guessed from its visible label.
For an Aussie merchant, a “fair go” report should show every relevant order in the selected period without silently excluding refunds or cancellations. Status filters should therefore reflect the accounting purpose of the report, not simply the statuses currently visible on one administration screen.
Sorting, paginating and reading results
The legacy query uses orderby and order to control the sequence. Setting orderby to date sorts by the order post date, while order to DESC places the newest matching order first. This is often preferable for a support screen because recent activity appears immediately.
Pagination information is available from the query object after it runs:
$page = max( 1, absint( $_GET['order_page'] ?? 1 ) );
$total_items = $wc_query->found_posts;
$total_pages = $wc_query->max_num_pages;
Add the page number to the original arguments and use max_num_pages to build navigation. Avoid requesting every order with posts_per_page => -1 on a busy store. A large result set can consume substantial memory and slow down both WordPress and the database.
For exports, process the results in batches and release each batch before requesting the next one. The same principle applies to JSON endpoints and REST resources: return a limited page with stable ordering rather than an unbounded collection. Consumers can request subsequent pages using the returned pagination metadata.
Adapting the query for HPOS and WC_Order_Query
When HPOS is enabled, use WC_Order_Query or wc_get_orders() because these APIs understand WooCommerce’s order tables. The status values no longer need the wc- prefix, and the date argument refers to the order’s creation date rather than a WordPress post column.
A typical current-release query uses the following shape:
$args = array(
'status' => array( 'processing', 'on-hold' ),
'limit' => 25,
'page' => 1,
'orderby' => 'date_created',
'order' => 'DESC',
'date_created' => array(
'from' => '2025-07-01 00:00:00',
'to' => '2025-08-01 00:00:00',
),
'return' => 'objects',
);
$order_query = new WC_Order_Query( $args );
$orders = $order_query->get_orders();
The date range syntax can vary between older WooCommerce releases, so the installed version’s WC_Order_Query query variables should be checked before deployment. Keep the installation and WooCommerce version current rather than relying on undocumented arguments from an old plugin.
A migration should run the legacy and modern implementations against the same known orders and compare IDs, creation dates, statuses and totals. Differences around the boundaries are often caused by mixed time zones, while missing results usually indicate that HPOS is active and the legacy shop_order query is still being used.
Production safeguards for order reporting
Order reports can expose customer names, addresses, payment references and internal order totals. Run administrative reports only after checking current_user_can( 'manage_woocommerce' ), and validate pagination, status and date inputs before they enter the query. Nonces are still required for actions that expose or export report data in an administration interface.
Hosting deserves the same attention as application code, and server hardening guidance can help protect a WooCommerce installation used for Australian payments. Australian stores commonly process AUD amounts with GST included, so backups, database access controls and audit logs should cover both customer data and accounting records. Logs should avoid recording card numbers, security keys or unnecessary personal information.
Before running the report
- Confirm whether the store uses HPOS or legacy order posts.
- Verify the site time zone and daylight-saving handling.
- Restrict access to users who can manage WooCommerce orders.
- Use bounded pages instead of loading the full order history.
During verification
- Compare several known order IDs against both query methods.
- Test the first and last second of the selected date window.
- Confirm that cancelled and refunded orders appear where intended.
- Record the WooCommerce version, time zone and status values used.
The result should be a query that follows the active storage model, uses unambiguous status slugs and applies date boundaries consistently with the store’s Australian operating time zone. This produces dependable reports for administration, reconciliation and customer support without relying on an accidental full-table scan.