Admin Dashboard, My Account

WooCommerce Change User Role On Registration

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This code snippets changes the user role upon registration. By default, users are assigned the “Customer” user role. This snippet allows you to change that and assign a different user ole. In this specific example, we change the user role to “Contributor”. If you wish to assign a custom user role, you will first need to create this role. Search our guides on user roles to see how to create new user roles and apply certain capabilities.

/**
 * Snippet Name:	WooCommerce Change User Role On Registration
 * Snippet Author:	ecommercehints.com
 */

// Change the default 'Customer' role to 'Contributor'.
add_filter( 'woocommerce_new_customer_data', 'ecommercehints_change_user_role_on_registration' );
function ecommercehints_change_user_role_on_registration( $args ) {
  $args['role'] = 'contributor';
  return $args;
}

Snippet Benefits

  • Automatically change the user role upon registration

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER