WooCommerce Orders Column Showing Total Orders By That Customer

WooCommerce orders table showing column with the total number of orders that customer has made previously

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

Taken from my earlier guide, add a custom column to the orders table, this code snippet adds a column to allow the store admin to quickly see how many orders have been placed with the same email address.

This saves a lot of time having to drill-down or exporting into excel to find duplicates.

				
					/**
 * Snippet Name:	WooCommerce Order Column Showing 
 * Snippet Author:	ecommercehints.com
 */

add_filter( 'manage_edit-shop_order_columns', 'ecommercehints_add_order_count_column', 20 );
function ecommercehints_add_order_count_column( $columns ) {
    $columns['email_order_count'] = __( 'Order Count (Email)', 'woocommerce' );
    return $columns;
}

// Populate column with order count
add_action( 'manage_shop_order_posts_custom_column', 'ecommercehints_populate_new_column' );
function ecommercehints_populate_new_column( $column ) {
    global $post;
    if ( 'email_order_count' === $column ) {
        $billing_email = get_post_meta( $post->ID, '_billing_email', true );
        if ( $billing_email ) {
            $customer_orders = get_posts( array(
                'numberposts' => -1,
                'meta_key'    => '_billing_email',
                'meta_value'  => $billing_email,
                'post_type'   => wc_get_order_types(),
                'post_status' => array_keys( wc_get_order_statuses() ),
            ) );
            $order_count = count( $customer_orders );
            echo $order_count;
        }
    }
}
				
			

Snippet Benefits

  • Quickly see from a top-level view, whether a customer has ordered previously and the number of orders they have made in the past without having to drill-down.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

Your email address will not be published. Required fields are marked *

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers