Support

Account

Home Forums Front-end Issues Only the last condition outputs as data-condition Reply To: Only the last condition outputs as data-condition

  • Thanks for looking into my code.

    But it still only outputs 1 condition (session / date combi) although I have 3 entries in the option page… and the other entries don’t have any effect

    This is the condition output I get for for the field:

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

    The whole code is this:

    // Apply conditions to fields
    add_filter('acf/prepare_field/name=bookings_field_time_session_1', 'yl_check_booking_exeptions_session_1');
    function yl_check_booking_exeptions_session_1( $field ) {
    
        // Retrieve option values. Date value should be like: 20200611 (unformatted)
    	if( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) {
    		while ( have_rows('bookings_settings_disabled_exceptions', 'bookings') ) {
    			the_row();
    			$option_date = get_sub_field('bookings_settings_disabled_date', 'bookings', false);
    			$date = date_i18n('Ymd', strtotime($option_date));
    			$session = get_sub_field('bookings_settings_disabled_session', 'bookings', false);
    
    			if ( $session == '1' ) {
    				// Add the condition to the field
    				$field['conditional_logic'] = array(
    				  // the first nested array holds OR conditions
    				  // there would be a separate nested array for each OR condition
    				  array(
    					// the second nesting is AND conditions
    					array(
    					  'field'     => 'field_5ed4181bd63dc', // Time field session 1 in the form
    					  'operator'  => '!=', // If Value is different, then show the field
    					  'value'     => $session, // Compare against option page value
    					),
    					array(
    					  'field'     => 'field_5ed4178dd63d7', // Datepicker fiels in the form
    					  'operator'  => '!=', // If Value is different, then show the field
    					  'value'     => $date, // Compare against option page value
    					)
    				  ),
    				  array(
    					// this is an example, if there was an OR condition those would go here
    				  )
    				);
    			}
    
    		}
    
    	}
    
    	// Return
    	return $field;
    
    }