I am working on a wholesale site and want the site to automatically change the user role from customer to wholesale customer after login. This will allow the wholesale customers to see wholesale pricing. I have customized this code (below) and have added it in the Code Snippet plugin, but it doesn't seem to be working. Could anyone help me see what I'm missing?
function uiwc_change_role()
{
// get WP_user object
$user = wp_get_current_user();
// if the this is a registered user and this user is not an admin
if (false !== $user && !user_can($user, 'administrator')) {
//set the new role to our customer
$user->set_role('wholesale-customer');
}
}
add_action('wp_login', 'uiwc_change_role', 100, 0);
Thanks so much for any help you can provide!