56

How to Set WooCommerce Default User Registration Role

Powered by WPCodeBox

Learn how to set the default user registration role in WooCommerce with this simple code snippet. Perfect for managing new customer roles on your e-commerce site.


/**
 * Author: WP Turned UP
 * Author URI: https://wpturnedup.com
 */
 
//// In our example here, we are setting the default role to the 'Subscriber' role, and you can set your desired role 
//// by editing the '$args['role'] = 'subscriber';' entry.

----------------- CODE SNIPPET IS BELOW THIS LINE - REMOVE THIS LINE AND ABOVE ----------------- 

// Set Woocommerce Default User Registration Role
add_filter('woocommerce_new_customer_data', 'wc_assign_custom_role', 10, 1);
 
function wc_assign_custom_role($args) {
  $args['role'] = 'subscriber';
  
  return $args;
}

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.