
Viewing Customer Order History on the WooCommerce Single Order Management Page
In this article, I will show you how to add a feature to the WooCommerce single order management page that allows you to view a customer’s order history. With a simple PHP code snippet, you can display the customer’s last 10 orders, including order IDs, dates, purchased products, and statuses. This feature helps merchants manage orders more efficiently and gain insights into customer purchasing behavior.
The Missing Feature in WooCommerce: Viewing Order History on the Single Order Management Page
WooCommerce has long lacked a feature to view a customer’s order history directly on the single order management page. This functionality allows merchants to quickly check past purchases, view what products a customer bought, how much they spent, and how frequently they make purchases.
In fact, all you need is a simple PHP code snippet to add this feature. Below, I’ll walk you through the steps to implement this functionality and provide the necessary PHP code to display detailed order history on the order management page.
How to Display Customer Order History in WooCommerce
We’ll add a new “meta box” to the single order management page, which will contain the last 10 orders for the customer based on the current WooCommerce customer ID.
Code Explanation
- Add the Meta Box:
Using theadd_meta_boxes
hook, we will add a meta box to the WooCommerce order management page. Theadd_meta_box
function will set the title as “Customer Order History” and associate it with theshop_order
post type. - Display the Order History:
Thewprs_display_order_history
function will be triggered when the meta box is loaded. It collects the relevant customer order history and outputs it in a table format. - Order Retrieval:
The code retrieves the current order’s customer ID, then loads the customer’s previous orders (up to 10) by using'return' => 'ids'
to only fetch the order IDs, which speeds up the query. - Formatted Output:
For each past order, the code displays the order ID, date, product names (separated by a|
), and the order status. This provides an organized view of the customer’s order history on the single order management page.
PHP Code:
add_action( 'add_meta_boxes', function() {
add_meta_box( 'order_history', 'Customer Order History', 'wprs_display_order_history', 'shop_order', 'normal', 'default' );
}, 1 );
function wprs_display_order_history() {
global $post;
$order = wc_get_order( $post->ID );
if ( ! $order ) return;
$orders = array();
if ( $id = $order->get_customer_id() ) {
$orders = wc_get_orders( [ 'customer_id' => $id, 'return' => 'ids', 'limit' => 10 ] );
}
if ( ! $orders ) return;
echo '<table style="width:100%"><thead><tr><th>ID</th><th>DATE</th><th>ITEMS</th><th>STATUS</th></tr></thead><tbody>';
foreach ( $orders as $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) continue;
$items = array();
foreach ( $order->get_items() as $item_id => $item ) {
$items[] = $item->get_name();
}
echo '<tr><td>' . $order_id . '</td><td>' . wc_format_datetime( $order->get_date_created() ) . '</td><td>' . implode( ' | ', $items ) . '</td><td>' . $order->get_status() . '</td></tr>';
}
echo '</tbody></table>';
}
How to Implement
- Copy the above PHP code.
- Paste it into your theme’s
functions.php
file or a custom plugin. - Once the code is added, when viewing a single order in the WooCommerce admin, a new “Customer Order History” meta box will appear. This box will show the last 10 orders made by the customer, including order ID, date, product names, and status.

Why This Feature Is Useful
By displaying the customer’s past orders directly on the order management page, you can easily access important information like:
- What products the customer purchased.
- When they made these purchases.
- What their purchase frequency is.
- Their order statuses.
This helps merchants make informed decisions without having to leave the order management page, which can be a huge time-saver.
Future Enhancements
While this feature already adds great value, it can be further expanded. For example:
- You could show additional customer information like total spend, frequency of purchases, or other metadata.
- You could integrate custom filtering options, such as filtering by product category or order status.
If you need assistance implementing any of these features or have any questions, feel free to ask in the comments below. I’ll be happy to help you enhance this functionality further!