UserWoocommerce

Show Total Amount spent in admin user list

with this snippet, you can add a new column in the user list of wordpress, to show the total amount spent by each user. This requires to use woocommerce.

    
// Add a custom column to the user list. add_filter( 'manage_users_columns', 'custom_user_list_column' ); function custom_user_list_column( $columns ) { // Add a new column with a custom heading. $columns['total_spent'] = 'Total Amount Spent'; return $columns; } // Display total amount spent in list custom. add_action( 'manage_users_custom_column', 'display_total_spent_column_content', 10, 3 ); function display_total_spent_column_content( $value, $column_name, $user_id ) { if ( 'total_spent' === $column_name ) { // Get the WC_Customer object for the user. $customer = new WC_Customer( $user_id ); // Get the total amount spent. $total_spent = $customer->get_total_spent(); return wc_price( $total_spent ); // Format the numberas a price. } return $value; // Return other column values }

Leave a Reply

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