How to connect exsisting user role with Wholesale

[ad_1]

Hey @2beards thanks for the message!

I’m guessing you might be migrating from another B2B system? If so you’ll need to do this with a custom snippet to migrate people across to the Wholesale Suite role. The best way is to just do it when they login like so:

function wwp_update_role_on_logins( $user_login, $user ) {
    
    //retrieve the user role for this user
    $user_meta = get_userdata($user_id);
	$user_roles = $user_meta->roles; //returns an array of roles the user is assigned to

        //now we check if the current user is a customer
        if ( in_array("customer", $user->roles) ) {

            //remove the customer role and add wholesale customer role to this customer
            $user->remove_role('customer');
            $user->add_role('wholesale_customer');
        }
        
    }
    
add_action('wp_login', 'wwp_update_role_on_logins', 10, 2);

Where it calls remove_role() the snippet says ‘customer’ … you can change this to the old role you want to migrate people from.

Where it calls add_role() with ‘wholesale_customer’ … this is the standard wholesale customer role we add in the free plugin here. If you’re on premium you can also add extra roles, so you could technically use the role slug of any of those if you want too.

You can install this into your theme’s functions.php file or you can use a plugin like WPCode to add this.

Hope this helps and good to have you on board!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer