Skip to content

Instantly share code, notes, and snippets.

@yousufansa
Created May 28, 2020 05:22
Show Gist options
  • Save yousufansa/aebd5b2c257293e8b0c42db9378be806 to your computer and use it in GitHub Desktop.
Save yousufansa/aebd5b2c257293e8b0c42db9378be806 to your computer and use it in GitHub Desktop.
Front Jobs - Enable User Role Dropdown On WooCommerce Register Form
if( ! function_exists( 'front_child_woocommerce_register_form_role_dropdown' ) ) {
function front_child_woocommerce_register_form_role_dropdown() {
if( apply_filters( 'front_register_user_role_enabled', true ) && front_is_wp_job_manager_activated() ) {
?>
<div class="form-group">
<label class="form-label" for="reg_front_user_role"><?php _e( 'I want to register as', 'jobhunt' ); ?></label>
<select name="front_user_role" id="reg_front_user_role" class="input chosen-select">
<option value="candidate"<?php if( isset( $_POST['front_user_role'] ) && $_POST['front_user_role'] === 'candidate' ) echo esc_aatr( ' selected' ) ?>><?php echo esc_html__( 'Candidate', 'jobhunt' ); ?></option>
<option value="employer"<?php if( isset( $_POST['front_user_role'] ) && $_POST['front_user_role'] === 'employer' ) echo esc_aatr( ' selected' ) ?>><?php echo esc_html__( 'Employer', 'jobhunt' ); ?></option>
</select>
</div>
<?php
}
}
}
add_action( 'front_myaccount_woocommerce_register_form_custom_field_after', 'front_child_woocommerce_register_form_role_dropdown' );
add_action( 'woocommerce_register_form', 'front_child_woocommerce_register_form_role_dropdown' );
if( ! function_exists( 'front_child_woocommerce_new_customer_data_role_update' ) ) {
function front_child_woocommerce_new_customer_data_role_update( $args ) {
if( apply_filters( 'front_register_user_role_enabled', true ) && front_is_wp_job_manager_activated() ) {
$default_role = 'customer';
$available_roles = array( 'customer' );
if ( front_is_wp_job_manager_activated() ) {
$available_roles[] = 'employer';
}
if ( front_is_wp_resume_manager_activated() ) {
$available_roles[] = 'candidate';
$default_role = 'candidate';
}
$user_role = ! empty( $_POST["front_user_role"] ) && in_array( $_POST["front_user_role"], $available_roles ) ? sanitize_text_field( $_POST["front_user_role"] ) : $default_role;
$args['role'] = $user_role;
}
return $args;
}
}
add_filter( 'woocommerce_new_customer_data', 'front_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