0

是的,我还在尝试,不,我还没有找到答案。

我在 ACF 表单上发布过多次,我什至创建了官方 ACF 票证,我在 Stack 上多次发布过......

真的不明白为什么人们不愿意用几​​行代码来帮助我,但我想这就是它的工作方式:(

我的最后一次尝试,然后我不得不退出。不是因为我想要,而是因为我必须这样做,因为缺少完成拼图的最后一把钥匙。

如果我通过 PayPal(预先)向您汇款 75 美元,您会帮助我吗?

此工作代码:

// 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;

}

给我这个数据条件输出:

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

20200625 是转发器字段中 3 行的最后日期(行)。

我只是希望这部分 [{"field":"field_5ed4181bd63dc","operator":"==","value":"1"},{"field":"field_5ed4178dd63d7","operator":"!=","value":"20200625"}] 多次用逗号分隔,因此所有条件都将处于活动状态。

我可以雇你这个吗?了解 ACF 的人应该立即解决这个问题 :)

如果没有……我周围的其他人可以为此雇用吗?

4

1 回答 1

0

不确定您在这里期待什么,SO 不是编码服务。

但无论如何,在我看来你需要推动你的条件,现在你正在覆盖它们 - 我在这里做了一个小操场:https ://www.tehplayground.com/YIO6KLfKfxVHFYRQ看起来格式正确的地方。

<?php 
// 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') ) {
    //init the conditions array - When conditions are set, it need to be in array(array(array('conditions'))); format
    $field['conditional_logic'][0] = array();
    
    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)) {
                //set the conditions back to default 0
                $field['conditional_logic'] = 0;
                return $field;
            }

            // Add the condition to the field
            $field['conditional_logic'][0][] = 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
                    );
                    
            $field['conditional_logic'][0][] = 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;

}
?>

希望这对您有所帮助。

于 2020-06-24T07:11:59.017 回答