Last active
February 27, 2019 07:09
-
-
Save yousufansa/c4aef3bfb7a7b273bbe63d5199cca20d to your computer and use it in GitHub Desktop.
Jobhunt - Create Custom Fields Based on Job Package
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( 'jobhunt_child_custom_submit_job_form_package_id_field' ) ) { | |
function jobhunt_child_custom_submit_job_form_package_id_field () { | |
$job_id = ! empty( $_REQUEST['job_id'] ) ? absint( $_REQUEST['job_id'] ) : 0; | |
if( ! empty( $job_id ) && $job_id > 0 && ! empty( get_post_meta( $job_id, '_package_id', true ) ) ) { | |
$package_id = get_post_meta( $job_id, '_package_id', true ); | |
} else { | |
$package_id = WP_Job_Manager_WCPL_Submit_Job_Form::get_package_id(); | |
} | |
?><input type="hidden" name="_package_id" value="<?php echo esc_attr( $package_id ); ?>" /><?php | |
} | |
} | |
add_action( 'submit_job_form_job_fields_end' , 'jobhunt_child_custom_submit_job_form_package_id_field', 20 ); | |
if ( ! function_exists( 'jobhunt_child_custom_save_submit_job_form_package_id_field' ) ) { | |
function jobhunt_child_custom_save_submit_job_form_package_id_field( $job_id ) { | |
$package_id = isset( $_POST['_package_id'] ) ? jobhunt_clean( $_POST['_package_id'] ) : ''; | |
update_post_meta( $job_id, '_package_id', $package_id ); | |
} | |
} | |
add_action( 'save_post', 'jobhunt_child_custom_save_submit_job_form_package_id_field', 20 ); | |
if ( ! function_exists( 'jobhunt_child_custom_submit_job_form_fields' ) ) { | |
function jobhunt_child_custom_submit_job_form_fields ($fields) { | |
if ( class_exists( 'WC_Paid_Listings' ) ) { | |
$job_id = ! empty( $_REQUEST['job_id'] ) ? absint( $_REQUEST['job_id'] ) : 0; | |
if( ! empty( $job_id ) && $job_id > 0 ) { | |
$package_id = get_post_meta( $job_id, '_package_id', true ); | |
} else { | |
$package_id = WP_Job_Manager_WCPL_Submit_Job_Form::get_package_id(); | |
} | |
$package = wc_get_product( $package_id ); | |
if ( ! is_object( $package ) ) { | |
$fields['job']['job_exclusive_field'] = array( | |
'label' => esc_html__( 'Exclusive Field', 'jobhunt' ), | |
'type' => 'text', | |
'placeholder' => 'Add Exclusive Text', | |
'priority' => 1, | |
'required' => false | |
); | |
} else { | |
$package_slug = $package->get_slug(); | |
if ( $package_slug == 'standard-jobs' ) { | |
$fields['job']['job_exclusive_field'] = array( | |
'label' => esc_html__( 'Exclusive Field', 'jobhunt' ), | |
'type' => 'text', | |
'placeholder' => 'Add Exclusive Text', | |
'priority' => 1, | |
'required' => false | |
); | |
} else { | |
unset( $fields['job']['job_exclusive_field'] ); | |
} | |
} | |
} | |
return $fields; | |
} | |
} | |
add_filter( 'submit_job_form_fields' , 'jobhunt_child_custom_submit_job_form_fields', 30 ); | |
if ( ! function_exists( 'jobhunt_child_custom_job_manager_job_fields' ) ) { | |
function jobhunt_child_custom_job_manager_job_fields ($fields) { | |
$fields['_job_exclusive_field'] = array( | |
'label' => esc_html__( 'Exclusive Field', 'jobhunt' ), | |
'placeholder' => 'Add Exclusive Text', | |
'type' => 'text' | |
); | |
return $fields; | |
} | |
} | |
add_filter( 'job_manager_job_listing_data_fields' , 'jobhunt_child_custom_job_manager_job_fields', 30 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment