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

    (@webwizardsdev)

    Hi there,

    Are you using B2BKing’s WP Roles? Or do you have a custom role named ‘B2B’ for example?

    If you have a custom role named B2B, and you want to give all b2b users that register this role, you can simply use this PHP code snippet:

    add_action('woocommerce_created_customer', function($user_id){
    
    	$user_status = get_user_meta($user_id, 'b2bking_account_approved', true);
    	
    	if($user_status === 'no'){
    		$user_obj = new WP_User($user_id);
    		$user_obj->add_role('b2b_role');
    	}
    
    }, 10000, 1);
    

    This snippet does not depend on the group. It will give every user with ‘manual approval’ the ‘b2b_role’ role. (you need to rename ‘b2b_role’ to the name of your desired role)

    Thread Starter Johan Peeters

    (@cosmedia)

    Sorry the title was copied from other post.. Should have edited that a bit.

    We have 3 groups made in the B2BKing which they can choose from when they register for an account. See image below

    When they register we see the customer user roles:
    Left is customer group, right is roles

    We need it to go directly to the chosen user role. Before and after approval, no customer group.

    Thank you for the fast reply!

    • This reply was modified 3 years, 3 months ago by Johan Peeters.
    Plugin Author WebWizards

    (@webwizardsdev)

    Thank you for getting back to me,

    By default B2BKing does not use WP roles like ‘customer’, ‘subscriber’, etc.

    Did you already follow the guide here to make it use WP roles? https://woocommerce-b2b-plugin.com/docs/how-to-use-wp-roles-with-b2bking/

    Thread Starter Johan Peeters

    (@cosmedia)

    I have. But does not work. How do I get rid of customer rol? Is it another plugin that could inject this? It’s not Woocommerce that does this?

    Plugin Author WebWizards

    (@webwizardsdev)

    By default we do not remove the ‘customer’ role, because normally every customer in WooCommerce (b2c or b2b customer) should also have the ‘customer’ role. So we give the user multiple roles.

    If you want to remove the ‘customer’ role for B2B users, you could use this snippet:

    This snippet removes the customer role, but it will work only for users who register with MANUAL approval. The snippet works during user registration.

    add_action('woocommerce_created_customer', function($user_id){
    
    	$user_status = get_user_meta($user_id, 'b2bking_account_approved', true);
    	
    	if($user_status === 'no'){
    		$user_obj = new WP_User($user_id);
    		$user_obj->remove_role('customer');
    	}
    
    }, 10000, 1);
    Plugin Author WebWizards

    (@webwizardsdev)

    If you are not able to set this up or it does not work for you for any reason, we can also assist directly and look into it on your site.

    For that please open a ticket with us at https://webwizards.ticksy.com

    Thread Starter Johan Peeters

    (@cosmedia)

    Thanks for the reply.

    The reason i try to disable the customer role is because of this bug:

    I have some extra registration fields added. In registration they look fine. But in checkout the Field Names are missing. Then, when i remove the customer role, the field names show up.

    Plugin Author WebWizards

    (@webwizardsdev)

    I am not sure what causes that but I would be happy to check it directly on your site if you’d like. Could you share a backend login to the site / staging site with us?

    You can open a ticket with us at https://webwizards.ticksy.com – if you support period expired, no problem, just open the ticket in the B2BKing Pre-Sales category (that category doesn’t require it) and I will look into it,

    Thread Starter Johan Peeters

    (@cosmedia)

    Just opened a ticket: https://webwizards.ticksy.com/ticket/3196654

    Thanks for checking this 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Change user role to “B2B” upon user registration not customer’ is closed to new replies.