Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在自定义签出字段上设置特定的显示顺序_Php_Wordpress_Woocommerce_Checkout_Custom Fields - Fatal编程技术网

Php 在自定义签出字段上设置特定的显示顺序

Php 在自定义签出字段上设置特定的显示顺序,php,wordpress,woocommerce,checkout,custom-fields,Php,Wordpress,Woocommerce,Checkout,Custom Fields,我正在向woocommerce结帐计费部分页面添加20个自定义结帐字段。它以前工作得很好。但最近我们发现字段的显示顺序混乱。我希望有人能帮助我显示自定义字段的顺序,他们被添加 我已禁用除woocommerce之外的所有插件。我用的是219主题。我删除了所有自定义字段,然后一次添加一个。奇怪的是,我能够添加11个按顺序显示的字段。当我们添加12个或更多字段时,显示混乱。我用一个简单测试字段的多个副本替换了所有定制字段,但问题仍然存在 以下代码已添加到themes functions.php add

我正在向woocommerce结帐计费部分页面添加20个自定义结帐字段。它以前工作得很好。但最近我们发现字段的显示顺序混乱。我希望有人能帮助我显示自定义字段的顺序,他们被添加

我已禁用除woocommerce之外的所有插件。我用的是219主题。我删除了所有自定义字段,然后一次添加一个。奇怪的是,我能够添加11个按顺序显示的字段。当我们添加12个或更多字段时,显示混乱。我用一个简单测试字段的多个副本替换了所有定制字段,但问题仍然存在

以下代码已添加到themes functions.php
add_filter( 'woocommerce_checkout_fields' , 
'custom_override_checkout_fields',10,3 ); 

function custom_override_checkout_fields( $fields ) {

//unset the unwanted billing fields

unset($fields['order']['order_comments']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_phone']);

//add custom fields

$fields['billing']['billing_test1'] = array(
    'label'       => __('test1', 'woocommerce'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => true,
    'clear'       => true,
    'class'     => array('form-row'),
    );

$fields['billing']['billing_test2'] = array(
    'label'       => __('test2', 'woocommerce'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => true,
    'clear'       => true,
    'class'     => array('form-row'),
    );

//a further 18 copies of the above field test3->test20

 return $fields;

}
布局应为:-

First name    Last name
Email address
test1
test2 
test3
....
test20
实际布局为:-

First name
test10
test19
test18
test17
test16
test15
test14
test13
test12
test11
Last name
test9
test8
test7
test6
test5
test4
test3
test2
test1

您错过了表单字段“
priority
”参数,该参数允许对表单字段重新排序…在下面的代码中,我使用
for
循环动态生成20字段(仅用于测试,因为它是最快的)

在这里,第一个表单字段的优先级从200开始,每个表单字段的优先级增加10

守则:

add_filter( 'woocommerce_checkout_fields', 'customizing_checkout_fields', 10, 1 );
function customizing_checkout_fields( $fields ) {

    ## 1. unset the unwanted billing fields

    unset($fields['order']['order_comments']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);

    ## 2. Add 20 form fields (from "Test 1" to "Test 20")

    // Using a for loop to make the 20 fields dynamically
    for ( $i = 1, $j = 0; $i <= 20; $i++, $j += 10 ) {

        $fields['billing']['billing_test' . $i] = array(
            'label'       => __('Test', 'woocommerce') . ' ' . $i,
            'placeholder' => _x('', 'placeholder', 'woocommerce'),
            'required'    => true,
            'clear'       => true,
            'class'       => array('form-row'),
            'priority'    => (200 + $j) // <== The priority starting at 200 and increasing by 10 each time
        );
    }

    return $fields;
}
add_filter('woocommerce_checkout_fields','customize_checkout_fields',10,1);
函数自定义\u签出\u字段($fields){
##1.取消设置不需要的计费字段
未设置($fields['order']['order_comments']);
未设置($fields['billing']['billing_company']);
未设置($fields['billing']['billing_address_1']);
未设置($fields['billing']['billing_address_2']);
未设置($fields['billing']['billing_city']);
未设置($fields['billing']['billing_postcode']);
未设置($fields['billing']['billing_state']);
未设置($fields['billing']['billing_phone']);
##2.添加20个表单字段(从“测试1”到“测试20”)
//使用for循环动态生成20个字段
对于($i=1,$j=0;$i____;('Test','woocommerce')。$i,
'占位符'=>x('','占位符',''),
“必需”=>true,
“清除”=>正确,
'class'=>array('form-row'),
“优先级”=>(200+$j)/uuu(‘测试1’,‘商业’),
'占位符'=>x('','占位符',''),
“必需”=>true,
“清除”=>正确,
'class'=>array('form-row'),
“优先级”=>200//true,
“清除”=>正确,
'class'=>array('form-row'),

'priority'=>210//非常感谢,我已经实现了priority字段,并且签出表单显示正确。
add_filter( 'woocommerce_checkout_fields', 'customizing_checkout_fields', 10, 1 );
function customizing_checkout_fields( $fields ) {

    ## 1. unset the unwanted billing fields

    unset($fields['order']['order_comments']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);

    ## 2. Add 20 form fields (from "Test 1" to "Test 20")

    $fields['billing']['billing_test1'] = array(
        'label'       => __('Test 1', 'woocommerce'),
        'placeholder' => _x('', 'placeholder', 'woocommerce'),
        'required'    => true,
        'clear'       => true,
        'class'       => array('form-row'),
        'priority'    => 200 // <== <== <== priority
    );

    $fields['billing']['billing_test2'] = array(
        'label'       => __('Test 2', 'woocommerce'),
        'placeholder' => _x('', 'placeholder', 'woocommerce'),
        'required'    => true,
        'clear'       => true,
        'class'       => array('form-row'),
        'priority'    => 210 // <== Increased by 10
    );

    // A further 18 copies of the above field from "Test 3" to "Test 20"

    return $fields;
}