• Resolved Blue2 GmbH

    (@blue2shop)


    Hello,
    our customers have assigned multiple roles. We would now like to display which roles the user had when placing an order.
    How could this be accomplished?

    Thanks a lot and
    kind regards,
    Johannes

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Dina S.

    (@themehighsupport)

    You can achieve your requirement by creating a Hidden field type and providing a Default Value to it using the ‘woocommerce_checkout_fields’ filter.

    Please refer to the sample code snippet provided below, which can be used for a hidden field that is created inside the billing section.

    add_filter('woocommerce_checkout_fields','th9e_override_checkout_field');
    function th9e_override_checkout_field($fields){
    
       if(isset($fields['billing']['hidden_field_name']['default'])){
           $current_user = wp_get_current_user();
           if($current_user->exists() && count($current_user->roles)) {
               $user_role = $current_user->roles[0];
               $fields['billing']['hidden_field_name']['default'] = $user_role;
           }
       }
    
       return $fields;
    }

    In the above code, please replace ‘hidden_field_name’ with your hidden field name added in the billing section.

    Thank you!

Viewing 1 replies (of 1 total)
  • The topic ‘How are the user roles displayed in emails’ is closed to new replies.