How to set user GROUP programmatically / during import / in BULK / with scripts.

Move all users to a group

First of all, if you want to move all users to a group, such as the site's B2B group, there is a simple way to do it, by going to B2BKing->Tools->Bulk Editor and using the button "Move all users to group":

This is an easy way to move a large number of users, useful especially when you first set up the site.

Set Group Programmatically / in Bulk

To set a user's group all you have to do is set 2 meta keys:

  • b2bking_b2buser

Value should be yes for b2b users and no for b2c or other users

  • b2bking_customergroup

Value should be the group id (e.g. 253, 13, 19, etc).

You can get the group ID by going to B2BKing->Groups->Business Groups and clicking on the group. The Number in the URL is the group ID.

Example how this all looks:

The example above is taken from the database. The user is a b2b user and is part of the group with ID 14. If we want to see what group that is, we go to Groups and find the one with 14 in the link:

This is useful if you are importing a large number of users. For example if you are importing users with a tool such as WP ALL IMPORT, you can set these 2 meta keys during import and the users will be added to the appropriate group.

Did you find this article useful?