Last active
May 28, 2022 13:08
-
-
Save NickMkrtchyan/93deed6274226acd6e66df9243c49d6e to your computer and use it in GitHub Desktop.
Adding role selection during registration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @snippet WooCommerce Role Select During Registration | |
* @how-to https://woohacks.github.io/ | |
* @author Nick Mkrtchyan | |
* @compatible WooCommerce 5.0 | |
*/ | |
function register_role_select_option() { | |
global $wp_roles; ?> | |
<p class="form-row form-row-wide"> | |
<label for="reg_billing_phone"><?php echo __( 'Student or Instructor', 'woocommerce' ) ?></label> | |
<select name="role" class="input"> | |
<?php | |
foreach ( $wp_roles->roles as $key=>$value ) { | |
// Exclude roles like Admin, Author and etc... | |
if ( ! in_array( $value['name'], [ 'Administrator', 'Author', 'Editor', 'Contributor'] ) ){ | |
echo '<option value="'.$key.'">'.$value['name'].'</option>'; | |
} | |
} | |
?> | |
</select> | |
</p> | |
<?php | |
} | |
add_action( 'woocommerce_register_form', 'register_role_select_option' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment