Okay
  Public Ticket #2808284
Display user role name on account page
Closed

Comments

  •  3
    Cathy started the conversation

    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,217
    WebWizards replied

    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
    Cathy replied

    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


  •   WebWizards replied privately
  •   Cathy replied privately
  •   WebWizards replied privately
  •  3
    Cathy replied

    Hi Stefan,

    Thank you so much for your help. It works perfectly now.

    Regards,

    Cathy