How do precheck some items in multicheck?
-
I have a multicheck which I populate with the dates of the next 7 days e.g.
25-04-2020 => Saturday 25 April 2020
26-04-2020 => Sunday 26 April 2020
27-04-2020 => Monday 27 April 2020
etcI would like to always have Monday and Tuesday checked.
How can I do that?
I tried using a ‘default_cb’ callback but didn’t know what to return.add_action( 'cmb2_admin_init', 'sab_delivery_dates_availability' ); function sab_delivery_dates_availability() { $cmb_options = new_cmb2_box( array( 'id' => 'delivery_dates', 'title' => 'Delivery Dates Availability', 'object_types' => array( 'options-page' ), 'option_key' => 'delivery_dates', // The option key and admin menu page slug. 'icon_url' => 'dashicons-calendar-alt', // Menu icon. Only applicable if 'parent_slug' is left empty. 'capability' => 'edit_posts', // Capability required to view this options page. 'position' => 2, // Menu position. Only applicable if 'parent_slug' is left empty. 'save_button' => 'Save Dates', ) ); // Create the checkbox list of dates. global $default_disable; // The index is the date (dd-mm-yyyy format) and the checkbox text is a readable date for useability. $today = time(); $dates_array = array(); $secs_in_a_day = 60 * 60 * 24; for ( $i = 0; $i < 7; $i++ ) { $time = $today + ( $i * $secs_in_a_day ); // Add $i days to time. $date_info = getdate( $time ); // Index is dd-mm-yyyy (for DatePicker date exclusion) and then the readable date. $date_index = sprintf( '%02d-%02d-%d', $date_info['mday'], $date_info['mon'], $date_info['year'] ); $dates_array[ $date_index ] = sprintf( '%s %d %s %d', $date_info['weekday'], $date_info['mday'], $date_info['month'], $date_info['year'] ); } $cmb_options->add_field( array( 'desc' => 'Check dates that do <strong>NOT</strong> have delivery slots available.', 'type' => 'multicheck', 'id' => 'dates', 'select_all_button' => false, // Exclude the "Select All" button. 'options' => $dates_array, ) ); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How do precheck some items in multicheck?’ is closed to new replies.