Skip Navigation

[Resolved] Is there a field that will display a User Role?

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by martham 3 years ago.

Assisted by: Minesh.

Author
Posts
#2254297

We are setting up all these Woocommerce store order reports. That's why I'm having so many support tickets now because there seems to be A LOT to learn with this. I think once the Woocommerce store order reports are complete, things should settle down.

Anyway, on one of these reports, we want to have a column that will display the User Role for the customer that placed the order. But I'm not seeing User Role as one of the field options either among the fields already present or under the Front End Content | Hidden Custom Fields. I realize right now, this field will just return Customer. We are also working on setting up automatic role assignment for custom roles when each product is purchased, so that will change if we succeed in setting that up. We're either going to use your custom roles in Access for this, or we will have to use another plugin. Either way, different roles should be assigned to customers later in the development of the site, and we'd like to have User Role as a field on this specific report. Any assistance you can provide again here will be appreciated.

#2254551

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL where you want to display the user role and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2254637

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following custom shortcode to "Custom Code" section offered by Toolset:
=> hidden link

add_shortcode('get_user_role', 'get_user_role_func');
function get_user_role_func($atts, $content){
    $atts = shortcode_atts( array(
          'user_id' => 0,
    ), $atts );
    $user = new WP_User( $atts['user_id'] );
    $arr = array();
    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
        foreach ( $user->roles as $role )
            $arr[] = $role;
    }
    $res = implode(', ', $arr);
    return $res;
}

I've called the shrotcode within your view under the "User Role" column as given under:

<td>[get_user_role user_id="[wpv-post-field name='_customer_user']"] </td>

Can you please confirm it works as expected: hidden link

#2254659

Looks like it's working correctly. This is great. You guys are providing FANTASTIC support here. We're knocking out every issue one by one.

Your success here has now exposed another issue I'm going to have to resolve, but it is not related to Toolset. I'm seeing that customers aren't automatically getting a user account with the default Customer role, so I just have to go back through Woocommerce's settings to make that happen. I thought I had it set to do that, but I evidently overlooked that. I noticed that because the 2nd order on this view doesn't have a role showing. So I checked for that user account and it doesn't exist.

Thanks hugely again. Getting closer to having every issue working now. This one is now resolved.

#2254661

My issue is resolved now. Thank you!