Support

Account

Home Forums Front-end Issues Multiple date-conditions via array

Solved

Multiple date-conditions via array

  • Yes I’m still trying and no I still haven’t found the answer.

    I have posted multiple times on the ACF forms, I even created an official ACF ticket, I posted multiple times on Stack…

    Really don’t understand why people are not willing to help me with the few lines of code but I guess that’s just the way it works 🙁

    My final try and then I have to quit. Not because I want, but because I have to because the final key is missing to complete the puzzle.

    What if I send you $75,- via PayPal (up front) would you then help me?

    This working code:

    // 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){
    
        if ( have_rows('booking_setting_exceptions', 'booking_settings') ) {
            while ( have_rows('booking_setting_exceptions', 'booking_settings') ) {
                the_row();
    			
    			if (get_sub_field('booking_setting_exceptions_session', 'booking_settings') == '1' ) {
    				$date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings')));
    
    				// Bail early if no option date found
    				if (empty($date)) {
            			return $field;
    				}
    
    				// Add the condition to the field
    				$field['conditional_logic'] = array(
    
    					array(
    
    						array(
    							'field'     => 'field_5ed4181bd63dc', // Time field session 1 in the form
    							'operator'  => '==', // If Value is different, then show the field
    							'value'     => '1', // Compare against session option page value
    						),
    
    						array(
    							'field'     => 'field_5ed4178dd63d7', // Time field session 1 in the form
    							'operator'  => '!=', // If Value is different, then show the field
    							'value'     => $date, // Compare against date option page value
    						)
    
    					)
    
    				);
    			}
    
            }
    
        }
    
        // Return
        return $field;
    
    }

    gives me this data-condition output:

    data-conditions="[[{"field":"field_5ed4181bd63dc","operator":"==","value":"1"},{"field":"field_5ed4178dd63d7","operator":"!=","value":"20200625"}]]"

    20200625 is the last date (row) of 3 rows in the repeater field.

    I simply want this part [{"field":"field_5ed4181bd63dc","operator":"==","value":"1"},{"field":"field_5ed4178dd63d7","operator":"!=","value":"20200625"}] multiple times separated with comma so all conditions will be active.

    Can I hire you this? Someone with your knowledge of ACF should fix this in no time 🙂

    If not… Anybody else around I can hire for this?

  • I really cannot tell what you’re trying to accomplish. I have reread your previous topic as well, but I cannot get a clear enough picture of it with the information you’ve provided.

    With that in mind, here is a guess. If this does not work then you’ll need to give a clearer picture of what you are working with.

    
    // 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();
          if (get_sub_field('booking_setting_exceptions_session') == '1') {
            $date = date_i18n('Ymd', strtotime(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_5ed4181bd63dc', // Time field session 1 in the form
                'operator'  => '==', // If Value is different, then show the field
                'value'   => '1', // Compare against session option page value
              ),
              array(
                'field'   => 'field_5ed4178dd63d7', // Time field session 1 in the form
                'operator'  => '!=', // If Value is different, then show the field
                'value'   => $date, // Compare against date option page value
              )
            );
          } // end if (get_sub_field('booking_setting_exceptions_session') == '1')
        } // end while have_rows
      } // end if have_rows
      $field['conditional_logic'] = $conditions;
      // Return
      return $field;
    }
    
  • 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;
    }
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Multiple date-conditions via array’ is closed to new replies.