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;