Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active June 7, 2017 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/ae0170c60c7e753cda3230a1effea883 to your computer and use it in GitHub Desktop.
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
<?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