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

  • I think I should FOREACH a part of the array. ? Is that a correct thinking?

    Although this does not work, could you help me please? This is the last part in a long journey to develop my own booking system:

    // 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)
        $rows = get_field('bookings_settings_disabled_exceptions', 'bookings');
    
    	if( $rows ) {
    
            foreach ( $rows as $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);
    
                $arrays =
                    array(
                        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
                        )
                    );
                }
    
                if ( $session == '1' ) {
                    $field['conditional_logic'] = array(
                        $arrays
                    );
                }
            }
    
            // Return
            return $field;
    
        }
    
    }