- What Does wc_get_orders() Do?
- Syntax and Return Values
- Common Query Arguments
- Paginate Results
- wc_get_orders() Use-Cases
- 1. Send Payment Reminders for Pending Orders
- 2. Show a Customer’s Order History
- 3. Find Guest Orders by Email
- 4. Queue Orders for a Batch Job
- Common Mistakes
- FAQs About wc_get_orders()
- What Is the Difference Between wc_get_orders() and WC_Order_Query?
- Does wc_get_orders() Return Refunds?
- Can I Sort the Results?
- Conclusion
Reports, reminders, and account pages all need a list of orders, not just one. wc_get_orders() returns that list. You pass the filters you need, and WooCommerce runs the query for you.
This guide covers the arguments, the three return modes, pagination, and four practical use-cases.
What Does wc_get_orders() Do?
wc_get_orders() is a global WooCommerce function. It takes one array of query arguments, runs the query, and returns the matching orders. Internally it builds a WC_Order_Query, so the arguments match the ones that class accepts.
Syntax and Return Values
The signature is wc_get_orders( $args ). The return argument and the paginate flag control what you get back:
Return Modes: Objects, IDs, and Pages
| Setting | Returns |
|---|---|
'return' => 'objects' (default) | Array of WC_Order objects |
'return' => 'ids' | Array of order IDs. Faster when you only need IDs |
'paginate' => true | Object with orders, total, and max_num_pages properties |
Common Query Arguments
| Argument | Purpose | Example |
|---|---|---|
status | Order statuses to include | array( 'processing', 'completed' ) |
customer | Customer user ID | get_current_user_id() |
billing_email | Billing email address | '[email protected]' |
date_created | Creation date as a timestamp with an operator | '>' . ( time() - WEEK_IN_SECONDS ) |
type | Order type. Defaults to shop_order | 'shop_order_refund' |
limit | Results per page. -1 returns all | 50 |
page | Page number when paginating | 2 |
orderby / order | Sort field and direction | 'date' / 'DESC' |
Filter by Status and Date
Combine status and date_created to answer questions about a time window. This function counts paid orders from the last seven days. It asks for IDs only, so no order objects are built.
<?php
function my_weekly_order_count() {
$order_ids = wc_get_orders( array(
'status' => array( 'processing', 'completed' ),
'date_created' => '>' . ( time() - WEEK_IN_SECONDS ),
'limit' => -1,
'return' => 'ids',
) );
return count( $order_ids );
}Filter by Customer and Email
Pass customer with a registered user’s ID to get that person’s orders. Guest orders have no customer ID, so match them with billing_email instead. Use-case 3 below shows a guest lookup.
Paginate Results
Setting limit to -1 loads every match into memory. On a busy store, use pagination instead. Set paginate to true, and read $results->orders for the list and $results->max_num_pages for the page count.
<?php
function my_paginated_orders() {
$page = max( 1, absint( $_GET['paged'] ?? 1 ) );
return wc_get_orders( array(
'limit' => 20,
'page' => $page,
'paginate' => true,
) );
}wc_get_orders() Use-Cases
Each example runs one query and then acts on the results. Put the code in a site-specific plugin or a child theme’s functions.php.
1. Send Payment Reminders for Pending Orders
Customers sometimes leave an order unpaid. This function finds pending orders older than a day and emails each customer a link to pay. A meta flag stops the same order from getting a reminder twice. Schedule the event with wp_schedule_event() and wp_next_scheduled() so it runs once an hour.
<?php
add_action( 'my_pending_payment_reminders', 'my_send_pending_payment_reminders' );
function my_send_pending_payment_reminders() {
$orders = wc_get_orders( array(
'status' => array( 'pending' ),
'date_created' => '<' . ( time() - DAY_IN_SECONDS ),
'limit' => 100,
) );
foreach ( $orders as $order ) {
if ( $order->get_meta( '_my_reminder_sent' ) ) {
continue;
}
wp_mail(
$order->get_billing_email(),
'Complete your payment for order #' . $order->get_order_number(),
'Your order is still waiting for payment: ' . $order->get_checkout_payment_url()
);
$order->update_meta_data( '_my_reminder_sent', time() );
$order->save();
}
}2. Show a Customer’s Order History
A custom My Account section can list the logged-in customer’s latest orders. The query is limited to ten results, newest first, and includes only orders that are not cancelled or failed.
<?php
function my_customer_order_history() {
if ( ! is_user_logged_in() ) {
return array();
}
return wc_get_orders( array(
'customer' => get_current_user_id(),
'status' => array( 'completed', 'processing', 'on-hold' ),
'limit' => 10,
'orderby' => 'date',
'order' => 'DESC',
) );
}3. Find Guest Orders by Email
A support tool often needs to find orders placed without an account. Searching by billing email works for guests, and return => 'ids' keeps the result light. Sanitize the email before you pass it to the query.
<?php
function my_find_guest_orders( $email ) {
return wc_get_orders( array(
'billing_email' => sanitize_email( $email ),
'limit' => 20,
'return' => 'ids',
) );
}4. Queue Orders for a Batch Job
A nightly export can touch hundreds of orders, so do not process them inside the request. This function collects the IDs of processing orders and queues one job per order with Action Scheduler, which ships with WooCommerce. Register a my_export_order action to handle each job.
<?php
function my_queue_processing_orders() {
$order_ids = wc_get_orders( array(
'status' => array( 'processing' ),
'limit' => 200,
'return' => 'ids',
) );
foreach ( $order_ids as $order_id ) {
as_enqueue_async_action( 'my_export_order', array( 'order_id' => $order_id ) );
}
}Tip: Use
return => 'ids'whenever you only need IDs. WooCommerce skips building order objects, so the query is much lighter on large stores.
Common Mistakes
- Expecting refunds. The default type is
shop_order, so refunds stay out of the results. Settypetoshop_order_refundto query them. - Loading everything.
limit => -1loads every match into memory. Paginate large result sets. - Loading objects for IDs. Pass
return => 'ids'when you only need IDs.
FAQs About wc_get_orders()
What Is the Difference Between wc_get_orders() and WC_Order_Query?
wc_get_orders() creates a WC_Order_Query, runs it, and returns the results in one call. Use the class directly when you need to change the query between runs.
Does wc_get_orders() Return Refunds?
Not by default. The default type is shop_order. Set it to shop_order_refund to query refunds.
Can I Sort the Results?
Yes. Pass orderby and order. For example, 'orderby' => 'date' with 'order' => 'DESC' returns the newest orders first.
Conclusion
wc_get_orders() turns a list of orders into one function call. Filter with arguments, return IDs when you only need IDs, and paginate large sets so the server never loads the whole store at once.
Need a custom order report or integration built for your store? Hire a WooCommerce developer, or reach out to me directly.
