WooCommerce 3.0 has added a “priority” field to each billing and shipping field. Now moving fields @ checkout is much easier!
Here are the default priorities of some of the Woocommerce checkout fields.
// default priorities:
// 'first_name' - 10
// 'last_name' - 20
// 'company' - 30
// 'country' - 40
// 'address_1' - 50
// 'address_2' - 60
// 'city' - 70
// 'state' - 80
// 'postcode' - 90
// 'phone' - 100
Now, it’s much easier to move any checkout field using the filter hook named woocommerce_default_address_fields
Here is an example of moving company field to the first of all fields.
add_filter(
'woocommerce_default_address_fields'
,
'mymentech_reorder_checkout_fields
'
);
function
mymentech_reorder_checkout_fields(
$fields
) {
// just assign priority less than 10
$fields
[
'company'
][
'priority'
] = 8;
return
$fields
;
}
Here is how we can re-order the email address field.
add_filter(
'woocommerce_billing_fields'
,
'mymentech_move_checkout_email_field
'
, 10, 1 );
function
mymentech_move_checkout_email_field(
$address_fields
) {
$address_fields
[
'billing_email'
][
'priority'
] = 5;
return
$address_fields
;
}