How to change the order of additional checkout fields?
-
Hi all,
I’m trying to add an additional checkout field to the billing and shipping forms. I’m using the Checkout Fields block to output the fields to my template.
I’ve been able to add my field with
woocommerce_register_additional_checkout_field
function following the Cart and Checkout – Additional checkout fields.Now all I need to do is to place the field in the proper order: the new field is a House number field that should be positioned next to the Address field. However, I’m not able to find how to change the order and add the additonal field between the already existing fields.
I’ve added my code below:
add_action('woocommerce_init', function () {
woocommerce_register_additional_checkout_field(
[
'id' => 'tda/houseNumber',
'label' => __('House Number', 'tda'),
'optionalLabel' => __('House Number (optional)', 'tda'),
'type' => 'text',
'location' => 'address',
'required' => true,
'attributes' => [
'autocomplete' => 'house-number',
'aria-label' => __('House Number', 'tda'),
'pattern' => '[A-Z0-9]{5}', // A 5-character string of capital letters and numbers.
'title' => __('House Number', 'tda'),
'data-custom' => 'custom data',
],
'sanitize_callback' => function ($field_value) {
return sanitize_text_field($field_value);
},
'validate_callback' => function ($field_value) {
return is_numeric($field_value);
}
],
);
});In summary: how can I change the order of the checkout fields while using the WC Checkout Fields block?
I’m using the following versions:
- WP 6.7
- WooCommerce 9.3.3
Thanks in advance for your time.
With kind regards,
Emiel – The Developer’s Agency
- You must be logged in to reply to this topic.