1

I have a website that has customers and vendors. What is the proper way to let the new registered user choose between two specific roles the way they would like to have? Do they want to be as a customers and buy things or do they want to start selling.

I’m dreaming of a registration page where you could actually put your username, email and then select the role role. Don’t know is this possible to do. Please see the attached picture.

Customer or Vendor picture

1 Answer 1

1

see register_form action hook for modifying the registration form

add_action( "register_form", function() { $html = '<p>'.__('Do you want to buy or sell?<br>Choose your role').'</p>'; $html .= '<p>'; $html .= '<label for="_customer"><input type="radio" name="user_role" id="_customer" value="customer"/>'.__('Customer').'</label><br>'; $html .= '<label for="_vendor"><input type="radio" name="user_role" id="_vendor" value="_vendor"/>'.__('Customer').'</label>'; $html .= '</p>'; echo $html; } ); 

you can use user_register action to save selected user role.

add_action( "user_register", function( $user_id ) { $allowed = array( 'customer', 'vendor' ); if( isset( $_POST['YourFieldName'] ) && in_array( $_POST['YourFieldName'], $allowed ) ){ $user = new WP_User( $user_id ); $user->set_role($_POST['YourFieldName']); } } ); 

check WP_User class reference document for more information;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.