Hi Jose,
Thank you for using our plugin,
1) Indeed, instead of WP roles, we are using the plugin’s own ‘Groups’ (which you can find in the backend in B2BKing -> Groups – you can add, edit, or delete groups here).
These groups are a custom post type and we reference a group by its post ID. Groups are stored in the user meta key ‘b2bking_customergroup’.
So for example, if you want to get the group ID of a specific user, you can use:
$group_id = get_user_meta($user_id,'b2bking_customergroup', true);
To get the name of the group:
$group_name = get_the_title($group_id);
2) Why we are doing this instead of WP roles is because in WooCommerce it’s best for a customer to have the ‘Customer’ role. We could add multiple roles, but WordPress UI shows only 1 role by default, so that could be confusing and create issues.
3) You can return true for this filter: b2bking_use_wp_roles
Then deactivate and reactivate the B2BKing plugin. Now after reactivating it, you will see the plugin has created a WP role for each group.
Initially the roles are not synced for users, but after you save a user profile, it should then sync automatically for that user (and for future users).
The purpose of this filter is just compatibility with other plugins, like in your example,
Kind regards,
Stefan
Hi Stefan,
thank you very much for your fast reply.
I’ve already tried to deactivate and re-activate again the plugin, but the same it didn’t work.
I understand that you need to give the possibility to have also the standard role “customer”, but I’m afraid if you don’t use the standard roles you will have issues with some plugins. For example, those plugins for customization by user role.
I think it’s possible to assign multiple roles to the same user.
Have a look at the answer that was given here: https://stackoverflow.com/questions/33537603/how-to-assign-multiple-roles-to-a-single-user-in-wordpress
I didn’t test it, but I think it should work.
In any case, I will also try to find a different solution to make detect the role by user meta.
Thank you very much for providing the name of the user meta.
I wish you all the best with your plugin.
Have a great day!
Jose
Hi Jose,
That filter only exists in the Pro version of the plugin (no reason really, just didn’t get around to adding it to the Core version yet), so unless you’re using the Pro plugin, that would be why it doesn’t work. If it helps you with development, I can send you a copy of the Pro one, let me know.
It does work to use $user->add_role to add multiple roles, but it creates a lot of confusion for customers (because WP shows only 1 role in the user profile), and also other plugins mess with roles, so it’s just simpler to keep this entirely separate as user meta – helps avoid a lot of conflicts and support tickets.
Good luck, have a nice day!