Business Bloomer
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0
  • About
  • WooCommerce Blog
  • Online Courses
  • Login
  • 0

WooCommerce: Change User Role for New Customers

> Published: Mar 2017 - Revised: Dec 2020
> Blog Category: WooCommerce Tips
> Blog Tags: Customer Registration, My Account, User Roles
> Blog Comments: 12 Comments
Tweet

Join 17,000+ WooWeekly subscribers

If you don’t want to assign the WooCommerce user role “customer” to new… customers, there is simple PHP that can be added to your functions.php to achieve this. Enjoy!

Change WooCommerce user role upon registration

PHP Snippet: Change User Role for New Customers – WooCommerce

/**
 * @snippet       Change User Role for New Customers - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WC 4.6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
///////////////////////////////
// 1. ADD NEW ROLE
 
add_role( 'pending', __( 'Pending' ), array(
  'read' => true, 
));
 
///////////////////////////////
// 2. ASSIGN NEW ROLE
 
add_filter( 'woocommerce_new_customer_data', 'bbloomer_assign_custom_role' );
 
function bbloomer_assign_custom_role( $args ) {
  $args['role'] = 'pending';
  return $args;
}

Related posts:

  1. WooCommerce: Separate Login, Registration, My Account Pages
  2. WooCommerce: Deny Automatic Login Upon Registration @ My Account
  3. WooCommerce: File Upload @ My Account Registration Form
  4. WooCommerce: Login Redirect by User Role @ My Account
  5. WooCommerce: Disable Payment Gateway for Specific User Role
  6. WooCommerce: Add New Tab @ My Account Page
  7. WooCommerce: Add Select Field to “My Account” Register Form
  8. WooCommerce: Add Privacy Policy Consent @ My Account Registration
  9. WooCommerce: Allow Users to Edit Processing Orders
  10. WooCommerce: Rename “My Account” If Logged Out @ Nav Menu

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

Follow @rmelogli
Category: WooCommerce Tips
Tags: Customer Registration, My Account, User Roles

Post navigation

Previous post: WooCommerce: Add First & Last Name to My Account Register Form
Next post: WooCommerce: Display Height, Length, Width @ Shop Page

12 thoughts on “WooCommerce: Change User Role for New Customers”

  1. Dan
    May 29, 2020

    Is there a way to add the customer role, but only for the purchase of specific products? For example, we have a few subscription products and when users purchase these products, we want their user role to be Member. We installed the Woocommerce extension for Ultimate Member and it works when users checkout with credit card. However, users who checkout with mail-in check or ACH do not get their role changed when checking out.

    Reply
    1. Rodolfo Melogli
      June 2, 2020

      Hi Dan, did you try manually completing those orders?

      Reply
  2. David
    September 26, 2019

    Hey Rodolfo, you have an un-closed tag in your post. Thanks for the snippet!

    Reply
    1. Rodolfo Melogli
      September 30, 2019

      Thank you so much! Fixed.

      Reply
  3. daijiro
    June 9, 2019

    I have been testing this out and it worked. But i want new users to get ” support” level to send tickets throught awesome support, not gonna spend 50 euros on a ” intergration” but now i see after playing around with it for a few hours that it first create a new role and then applys it to a new costumer, is there a snipit that gives new costumers that registate the role support or above?

    Reply
    1. Rodolfo Melogli
      June 20, 2019

      Hi Daijiro, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  4. Eli
    June 4, 2018

    Hi, Rodolfo. I was looking for that, thank you so much.
    If I only want this to happen in register but not in checkout is that possible?

    Thank you.

    Reply
    1. Rodolfo Melogli
      June 6, 2018

      Hi Eli, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

      Reply
  5. Abd Ur Rehman
    March 5, 2017

    What is the benefit of add this role?

    Reply
    1. Rodolfo Melogli
      March 8, 2017

      Hey Abd, thanks for your comment! For example, my client needed to approve “Trade” users before allowing them to purchase (as normal customers). So this snippet changes that user role and give the Admin the option to approve them manually ๐Ÿ™‚

      Reply
      1. Abd Ur Rehman
        March 9, 2017

        Hi again, Thanks for replying. Sounds cool. Well, I didn’t get notification of your reply I came back to your site to check for reply. WP core version doesn’t send notification of comments you may consider using this plugin https://wordpress.org/plugins/comment-reply-email-notification/ that will allow your user to get notified when you post a reply. Regards, Abd Ur Rehman

        Reply
        1. Rodolfo Melogli
          March 11, 2017

          Thank you – it seems the others are receiving emails, weird ๐Ÿ™‚ Is the email address you entered correct, and if yes, is there anything in your spam?

          Reply
Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts
  • WooCommerce: Redirect Product Category Pages
  • WooCommerce: Close Button @ WooCommerce Checkout Notices
  • WooCommerce: Related Products Custom Heading & Subheading
  • WooCommerce: Display Stock Status For External Products
  • WooCommerce: Display Product Grid @ Order Emails e.g. Related Products
About Business Bloomer

With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.

Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.

Join 75,000+ Monthly Readers & 16,500+ Subscribers.

Become a Business Bloomer Supporter.

Join BloomerArmada and become an Official Business Bloomer Supporter:
easy-peasy, and lots of perks for you.
See your Benefits →
Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting
Latest Articles
  • WooCommerce: Redirect Product Category Pages
  • WooCommerce: Close Button @ WooCommerce Checkout Notices
  • WooCommerce: Related Products Custom Heading & Subheading
  • WooCommerce: Display Stock Status For External Products
  • WooCommerce: Display Product Grid @ Order Emails e.g. Related Products
Latest Comments
  • Rodolfo Melogli on The Ultimate Guide to WooCommerce Coupons
  • Rodolfo Melogli on Account Management & Privacy
  • Gary
    PRIORITY COMMENTER »
    on CustomizeWoo FREE
  • IAN
    PRIORITY COMMENTER »
    on Account Management & Privacy
Find Out More
  • Become a WooCommerce Expert
  • WooCommerce Blog
  • WooCommerce Online Courses
  • WooCommerce Weekly
  • Bloomer Armada
  • Affiliate Program
  • Contact
Contact Info

Ciao! I’m Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Email: [email protected]

Twitter: @rmelogli

Hire me by the hour: Get Quote ยป

VisaMastercardAmexPayPal Acceptance Mark
Business Bloomer © 2011-2023 - Terms of Use - Privacy Policy