Admin Dashboard

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.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER