I would like to check in my WP PHP plugin to what B2B group the logged-in user belongs or check if a user is part of a specific B2B Group.
- Is there a B2BKing function I can call to retrieve the B2B group ID and/or the B2B group's name? (Something like $groupID = get_user_meta(get_current_user_group_ID(), true); )
- Is there an overview of all B2BKing hooks and variables?
Elaborated usage scenario: I have coded a custom free product offering plugin that should automatically add and remove some free products if certain conditions are met. These combinations are too complex too implement with the current B2BKing dynamic rules. Because they vary over the different B2B Groups, I need a way to distinguish these groups in my script and trigger different functions based on this information.
I would like to check in my WP PHP plugin to what B2B group the logged-in user belongs or check if a user is part of a specific B2B Group.
- Is there a B2BKing function I can call to retrieve the B2B group ID and/or the B2B group's name? (Something like $groupID = get_user_meta(get_current_user_group_ID(), true); )
- Is there an overview of all B2BKing hooks and variables?
Elaborated usage scenario: I have coded a custom free product offering plugin that should automatically add and remove some free products if certain conditions are met. These combinations are too complex too implement with the current B2BKing dynamic rules. Because they vary over the different B2B Groups, I need a way to distinguish these groups in my script and trigger different functions based on this information.
Hi Martin,
You can get the group id for a user with this line:
You can get the group name with this line:
Another thing: if this is a mixed b2b/b2c site, I would recommend you also check that the user is B2B. The final code would look like this:
Generally, for information about the meta keys B2BKing uses to set users / group and how to set users programmatically, please see the following article: https://woocommerce-b2b-plugin.com/docs/how-to-set-user-group-programmatically-during-import-in-bulk-with-scripts/
Let me know if I can help with anything,
Kind regards,
Stefan