Support

Account

Home Forums Front-end Issues Multiple date-conditions via array Reply To: Multiple date-conditions via array

  • That’s exactly what I need!!!!!!!!!

    I only guess my conditional logic is not thought thru correctly… Because the date-conditions are all there (WOOOHOOOOOOO 😉 but the fields react different than what I was exception.

    OPTION PAGE has the following fields

    BOOKING EXCEPTIONS FIELD (repeater) with 2 sub fields:

    DATE FIELD = booking_setting_exceptions_date
    SESSION FIELD = booking_setting_exceptions_session

    FRONTEND FORM has the following fields

    DATE FIELD = field_5ed4178dd63d7
    SESSION FIELD = field_5ed4181bd63dc

    So what I want is that when the DATE and SESSION fields (from option page) match with the DATE and SESSION fields (from user input in frontend form) the field booking_time_session_1 should be hidden.

    In simple words: Within the option page I want to be able to disable specific dates with specific time sessions.

    // Apply conditions to fields
    add_filter('acf/prepare_field/name=booking_time_session_1', 'yl_check_booking_setting_exceptions');
    function yl_check_booking_setting_exceptions($field){
    	$conditions = array();
    	if (have_rows('booking_setting_exceptions', 'booking_settings')) {
    		while (have_rows('booking_setting_exceptions', 'booking_settings')) {
    			the_row();
    			$date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings')));
    			$session = get_sub_field('booking_setting_exceptions_date', 'booking_settings');
    			if (empty($date)) {
    				// no date, skip this row
    				continue;
    			}
    			// Add the condition to the field
    			$conditions[] =
    				array(
    					array(
    					'field'   => 'field_5ed4178dd63d7', DATE field in the form
    					'operator'  => '!=', // If Value is different, then show the field
    					'value'   => $date, // DATE option page value
    				),
    				array(
    					'field'   => 'field_5ed4181bd63dc', // SESSION field in the form
    					'operator'  => '!=', // If Value is different, then show the field
    					'value'   => $session, // SESSION option page value
    				)
    			);
    		} // end while have_rows
    	} // end if have_rows
    	$field['conditional_logic'] = $conditions;
    	// Return
    	return $field;
    }