# Returning Customer Info on the Order Screen

> Shows how many previous orders the customer has placed and their total spend on the order edit screen, so you can recognize loyal buyers.

- Type: PHP
- Runs: Admin only
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, admin, orders, customers
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-returning-customer-badge/

## Code

```php
add_action( 'woocommerce_admin_order_data_after_order_details', function ( $order ) {
    $email = $order->get_billing_email();

    if ( ! $email ) {
        return;
    }

    $args = array(
        'limit'   => -1,
        'return'  => 'ids',
        'type'    => 'shop_order',
        'status'  => array( 'wc-completed', 'wc-processing', 'wc-on-hold' ),
        'exclude' => array( $order->get_id() ),
    );

    if ( $order->get_customer_id() ) {
        $args['customer_id'] = $order->get_customer_id();
    } else {
        $args['billing_email'] = $email;
    }

    $ids   = wc_get_orders( $args );
    $spent = 0;

    foreach ( $ids as $id ) {
        $previous = wc_get_order( $id );
        $spent   += $previous ? (float) $previous->get_total() : 0;
    }

    echo '<p class="form-field form-field-wide" style="clear:both;padding-top:8px;">';

    if ( $ids ) {
        printf( '<strong>Returning customer:</strong> %1$d previous orders, %2$s spent.', count( $ids ), wp_kses_post( wc_price( $spent ) ) );
    } else {
        echo '<strong>New customer:</strong> first order.';
    }

    echo '</p>';
} );
```

## Notes

Guest orders are matched by billing email.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Returning Customer Info on the Order Screen" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
