• Resolved moonfolk

    (@moonfolk)


    Hi admin, I followed your guide (https://woocommerce-b2b-plugin.com/docs/how-to-use-wp-roles-with-b2bking/) and have successfully added B2BKing’s user roles to WordPress.

    I also have a page with the wholesale login / registration form, using the shortcode – [b2bking_b2b_registration registration_role_id=18916]. The URL for the “B2B” user role is – …/wp-admin/post.php?post=18916&action=edit

    Currently, when a user registers, it is “unapproved” and has the user role of “Customer”.

    After it is approved, the user then only has the user role of “B2B” + “Customer”

    Question: When the user signs up via the wholesale registration page, how can the user role be “B2B” immediately (and not “Customer”) but remain “unapproved”? Is there a way to implement this via functions.php?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WebWizards

    (@webwizardsdev)

    Hi there,

    I believe that’s achievable with a code snippet in functions.php:

    add_action('woocommerce_created_customer', function($user_id){
    
    	$group_id = 1234;
    	$user_status = get_user_meta($user_id, 'b2bking_account_approved', true)
    	;
    	if($user_status === 'no'){
    		b2bking()->update_user_group($user_id, $group_id);
    		$user_obj = new WP_User($user_id);
    		$user_obj->add_role('b2bking_role_'.$group_id);
    
    	}
    
    }, 10000, 1);

    You would need to change 1234 with the B2B group ID. To get that, go to the groups page , click on the group, and the number in the URL such as ?post=123 is the ID.

    Thread Starter moonfolk

    (@moonfolk)

    Hi admin. Thank you for your code snippet! It works!

    Note to other readers: Get the Group ID from B2BKing > Groups > B2B Groups > B2B Group List, and not from Registration Roles

    • This reply was modified 2 years, 1 month ago by moonfolk.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change user role to “B2B” upon user registration (but remain un-approved)’ is closed to new replies.