On the admin side, you might need to display WooCommerce information inside the users table (WordPress Dashboard > Users). For example, their billing country. Or maybe some custom calculation e.g. the number of completed orders.

Either way, this is super easy. First, we add a new column – second, we tell what content should go inside it. Enjoy 🙂

Display a custom column @ Users WordPress Dashboard

Snippet (PHP): Show a Custom WooCommerce Column @ WordPress Admin Users Table


/**
 * @snippet       Custom Column @ WordPress Admin Users Table
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=101309
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.3
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */ 

add_filter( 'manage_users_columns', 'bbloomer_add_new_user_column' );
 
function bbloomer_add_new_user_column( $columns ) {
    $columns['billing_country'] = 'Billing Country';
    return $columns;
}
 
add_filter( 'manage_users_custom_column', 'bbloomer_add_new_user_column_content', 10, 3 );
 
function bbloomer_add_new_user_column_content( $content, $column, $user_id ) {
   
    if ( 'billing_country' === $column ) {
	$customer = new WC_Customer( $user_id );
        $content = $customer->get_billing_country();
    }
	
    return $content;
}

Share:

Leave a Reply