I am adding 20 custom checkout fields to the woocommerce checkout billing section page. It was previously working fine. But recently we discovered the display order of the fields has been jumbled. I am hoping someone can help me display the custom fields in the order they are added.
I have disabled all plugins except woocommerce. I am using the twenty-nineteen theme. I removed all the custom fields, then added them back one at a time. Curiously I was able to add 11 fields which displayed in order. When 12 or more fields we added the display was jumbled. I replaced all the tailored custom fields with a multiple copies of a simple test field but the problem still persists.
The following code was added to the 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;
}
The layout should be:-
First name Last name
Email address
test1
test2
test3
....
test20
The actual layout is:-
First name
test10
test19
test18
test17
test16
test15
test14
test13
test12
test11
Last name
test9
test8
test7
test6
test5
test4
test3
test2
test1