Change user role while adding new user
-
Hello guys, I have a question.
I have a “sales agent” role that can add new users, bu I would like user to be added as “wholesale_customer” instead of classic “customer”. I’m doing something like the below code, but something is wrong. Could you please help me? Thanks, Mattia.
add_action( ‘woocommerce_created_customer’, function( $customer_id, $new_customer_data, $password_generated )
{
if ( is_user_logged_in() && wcb2bsa_has_role( get_current_user_id(), ‘sales_agent’ ) ){
$user = new WP_User( $customer_id );
$user->remove_role( ‘customer’ );
$user->add_role( ‘wholesale_customer’ );
}`
The topic ‘Change user role while adding new user’ is closed to new replies.