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;
}