Orders and Total Spent Columns in the Users List
Adds "Orders" and "Total spent" columns to Users > All Users, so you can spot your best customers and accounts that never ordered.
Opens WPIDE on
Code
add_filter( 'manage_users_columns', function ( $columns ) {
$columns['wpide_orders'] = 'Orders';
$columns['wpide_spent'] = 'Total spent';
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $value, $column, $user_id ) {
if ( 'wpide_orders' === $column ) {
$count = wc_get_customer_order_count( $user_id );
return $count ? sprintf( '<a href="%1$s">%2$d</a>', esc_url( admin_url( 'admin.php?page=wc-orders&_customer_user=' . $user_id ) ), $count ) : '0';
}
if ( 'wpide_spent' === $column ) {
return wp_kses_post( wc_price( wc_get_customer_total_spent( $user_id ) ) );
}
return $value;
}, 10, 3 );
Notes
Uses WooCommerce's cached customer totals, which update after each order.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.