Created
March 19, 2020 05:39
-
-
Save yousufansa/e282b9b84d650f19d269b2b13f0ba906 to your computer and use it in GitHub Desktop.
Jobhunt - Enable User Role Dropdown On WooCommerce Register Form
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
if( ! function_exists( 'jh_child_woocommerce_register_form_role_dropdown' ) ) { | |
function jh_child_woocommerce_register_form_role_dropdown() { | |
if( apply_filters( 'jobhunt_register_user_role_enabled', true ) && jobhunt_is_wp_job_manager_activated() ) { | |
?> | |
<p class="form-row form-row-wide"> | |
<label for="reg_jh_child_user_role"><?php _e( 'I want to register as', 'jobhunt' ); ?></label> | |
<select name="jh_child_user_role" id="reg_jh_child_user_role" class="input chosen-select"> | |
<option value="candidate"<?php if( $_POST['jh_child_user_role'] === 'candidate' ) echo esc_aatr( ' selected' ) ?>><?php echo esc_html__( 'Candidate', 'jobhunt' ); ?></option> | |
<option value="employer"<?php if( $_POST['jh_child_user_role'] === 'employer' ) echo esc_aatr( ' selected' ) ?>><?php echo esc_html__( 'Employer', 'jobhunt' ); ?></option> | |
</select> | |
</p> | |
<div class="clear"></div> | |
<?php | |
} | |
} | |
} | |
add_action( 'woocommerce_register_form', 'jh_child_woocommerce_register_form_role_dropdown' ); | |
if( ! function_exists( 'jh_child_woocommerce_new_customer_data_role_update' ) ) { | |
function jh_child_woocommerce_new_customer_data_role_update( $args ) { | |
if( apply_filters( 'jobhunt_register_user_role_enabled', true ) && jobhunt_is_wp_job_manager_activated() ) { | |
$default_role = 'customer'; | |
$available_roles = array( 'customer' ); | |
if ( jobhunt_is_wp_job_manager_activated() ) { | |
$available_roles[] = 'employer'; | |
} | |
if ( jobhunt_is_wp_resume_manager_activated() ) { | |
$available_roles[] = 'candidate'; | |
$default_role = 'candidate'; | |
} | |
$user_role = ! empty( $_POST["jh_child_user_role"] ) && in_array( $_POST["jh_child_user_role"], $available_roles ) ? sanitize_text_field( $_POST["jh_child_user_role"] ) : $default_role; | |
$args['role'] = $user_role; | |
} | |
return $args; | |
} | |
} | |
add_filter( 'woocommerce_new_customer_data', 'jh_child_woocommerce_new_customer_data_role_update' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment