Display customer group in user area

Thursday, 07 May 2020

One of WooCommerce B2B best features is to create groups and assign them to customers, to apply different prices, minimum purchase amount, products category visibility, shipping and payment methods and so on.
If you need to show assigned group in customer my account area, edit functions.php file that you find in your site’s FTP space in:

 wp-content/themes/{YOUR_ACTIVE_THEME}/functions.php

and insert this code:

add_action( 'woocommerce_account_navigation', function() {
    if ( ! in_array( 'customer', get_userdata( get_current_user_id() )->roles ) ) { return; }
    if ( $wcb2b_user_group = get_the_author_meta( 'wcb2b_group', get_current_user_id() ) ) {
        echo '<div class="wcb2b-customer-group">' . sprinft( __( 'Your group: %s' ), $wcb2b_user_group ) . '</div>';
    }
} );
WARNING! Before making any changes, make sure you have made a complete backup of site files and database.
It is advisable not to edit the theme files directly, but to use a child theme.
For more information on child themes, please read: WordPress Official guide on Child Themes