Public Ticket #2808284

Display user role name on account page

Closed
Comments
3 Tickets 3
Cathy started the conversation 5 years ago on June 22, 2021 at 10:37am

Hello.

I would like to know if there is a snippet to display the user role name on account page? Since I would like my customers to know which group they are in.

I have tried some codes that I found, but none of them work.

Thank you in advance.

2,762
KingsPlugins replied 5 years ago on June 23, 2021 at 2:25am

Hi Cathy,

You can use the following PHP snippet:

add_action('woocommerce_account_content', function(){
    $user_id = get_current_user_id();
    $group_id = get_user_meta($user_id,'b2bking_customergroup', true);
    if (!empty($group_id)){
        $group_name = get_the_title($group_id);
        echo 'Your user is part of the group '.'<strong>'.$group_name.'</strong>';
    }
});


and the result will be this:

9485624868.png

Let me know if I can help,

Kind regards,

Stefan

3 Tickets 3
Cathy replied 5 years ago on June 25, 2021 at 7:43pm

Hi Stefan,

I have tried to use the snippet, but it did not work. I am not sure if I need to paste the snippet to other places.

Regards, 

Cathy


Sign In