Display sales agent in customer area

Sunday, 17 May 2020

This feature is now integrated since version 1.1.1

One of WooCommerce B2B best features is to create sales agents and assign them to customers.

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 ( $sales_agent_id = get_the_author_meta( 'wcb2bsa_sales_agent', get_current_user_id() ) ) {
        $sales_agent = get_userdata( $sales_agent_id );
        echo '<div class="wcb2bsa-sales-agent">' . sprintf( __( 'Your sales agent: %s' ), $sales_agent->display_name ) . '</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