NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

WooCommerce: Displaying Stats Under The Client Column
Intermediate

---- Last modified : Nov 18 2021

Estimated reading time : 1 minute, 43 seconds - 151 words

With this tutorial, we will show you how to display your WooCommerce customer stats; for example the number of orders or the amount of money a customer spent on your online store.

Woocommerce is the number 1 e-commerce WordPress plugin for online stores.

WooCommerce Hooks for:
Displaying the total number of orders: wc_get_customer_order_count
The amount of money spent on your store: wc_get_customer_total_spent

Now that we know which hooks to use, we will create two columns in the user tables with the manage_users_columns and the manage_users_custom_column filters where the former will display both columns and the latter will allow us to generate the results.

Woocommerce : Afficher des informations dans la colonne utilisateur

///////////////////////////////// Woocommerce users results columns /////////////////////////// 
function add_user_details_columns($columns) {
$columns['user_orders'] = 'Orders';
$columns['user_total_spent'] = 'Total Spent';
return $columns;
}
 
function show_user_details_column_content($value, $column_name, $user_id) {
if ('user_orders' == $column_name)
return wc_get_customer_order_count($user_id);
else if ('user_total_spent' == $column_name)
return wc_price(wc_get_customer_total_spent($user_id));
return $value;
}
 
function add_order_details_to_user_list() {
add_filter('manage_users_columns', 'add_user_details_columns');
add_action('manage_users_custom_column', 'show_user_details_column_content', 10, 3);
}
 
add_action('admin_init', 'add_order_details_to_user_list');
 
////////////////////////////////////////////////////////////////////////////////////////////////

Alternatively, you can also use various plugins to display your WooCommerce stats such as Woocommerce Classement or Sales Report for WooCommerce.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>