Last active
June 7, 2017 23:24
-
-
Save tripflex/ae0170c60c7e753cda3230a1effea883 to your computer and use it in GitHub Desktop.
Custom max selected based on selected packages for WP Job Manager Field Editor
This file contains 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
<?php | |
add_filter( 'submit_job_form_fields', 'smyles_custom_max_selected_fields_per_package', 101 ); | |
function smyles_custom_max_selected_fields_per_package( $fields ){ | |
$max_packages = array( | |
// The key should be the ID of the product | |
'11130' => array( | |
'job_category' => 3, | |
'job_region' => 1, | |
'main_image' => 1, | |
), | |
// So below, the product ID is 11189 | |
'11189' => array( | |
'job_category' => 5, | |
'job_region' => 1, | |
'main_image' => 1, | |
), | |
'12515' => array( | |
'job_category' => 10, | |
'job_region' => 3, | |
'main_image' => 1, | |
), | |
'12439' => array( | |
'job_category' => 10, | |
'job_region' => 3, | |
'main_image' => 1, | |
), | |
); | |
$product_id = isset( $_REQUEST['wcpl_jmfe_product_id'] ) ? intval( $_REQUEST['wcpl_jmfe_product_id'] ) : ''; | |
$job_package = isset( $_REQUEST['job_package'] ) ? sanitize_text_field( $_REQUEST['job_package'] ) : $product_id; | |
$job_id = isset( $_REQUEST['job_id'] ) ? intval( $_REQUEST['job_id'] ) : FALSE; | |
// Product/Package Handling, get job_package from post meta | |
if ( $job_id && empty( $job_package ) && class_exists( 'WP_Job_Manager_Field_Editor_Package_WC' ) ) { | |
$job_package = WP_Job_Manager_Field_Editor_Package_WC::get_post_package_id( $job_id ); | |
} | |
if( ! empty( $job_package ) && array_key_exists( $job_package, $max_packages ) ){ | |
// job_category max selected set | |
if( array_key_exists( 'job', $fields ) && array_key_exists( 'job_category', $fields['job'] ) ){ | |
$fields['job']['job_category']['max_selected'] = $max_packages[ $job_package ][ 'job_category' ]; | |
} | |
// job_region max selected set | |
if( array_key_exists( 'job', $fields ) && array_key_exists( 'job_region', $fields['job'] ) ){ | |
$fields['job']['job_region']['max_selected'] = $max_packages[ $job_package ][ 'job_region' ]; | |
} | |
// main_image max selected set | |
if( array_key_exists( 'company', $fields ) && array_key_exists( 'main_image', $fields['company'] ) ){ | |
$fields['company']['main_image']['max_uploads'] = $max_packages[ $job_package ][ 'max_uploads' ]; | |
} | |
} | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment