Title: Change user role while adding new user
Last modified: January 4, 2022

---

# Change user role while adding new user

 *  Resolved [gastbrand](https://wordpress.org/support/users/gastbrand/)
 * (@gastbrand)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/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’ ); }`

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

 *  [Abiola Ogodo](https://wordpress.org/support/users/oaoyadeyi/)
 * (@oaoyadeyi)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/change-user-role-while-adding-new-user/#post-15221292)
 * [@gastbrand](https://wordpress.org/support/users/gastbrand/)
 * I found a helpful guide here: [https://wedevs.com/blog/98266/add-custom-user-roles-wordpress/](https://wedevs.com/blog/98266/add-custom-user-roles-wordpress/)
 *  [Joey – a11n](https://wordpress.org/support/users/jricketts4/)
 * (@jricketts4)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/change-user-role-while-adding-new-user/#post-15241566)
 * We haven’t heard back from you in a while, so I’m going to mark this as resolved–
   we’ll be here if and/or when you are ready to continue.

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

The topic ‘Change user role while adding new user’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [Joey – a11n](https://wordpress.org/support/users/jricketts4/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/change-user-role-while-adding-new-user/#post-15241566)
 * Status: resolved