I am trying to reorder the billing fields on the checkout page but everything I tried so far is not working.
Here is the snippet I am currently trying:
To change woocommerce checkout fields you need to also change field order and required class base on display. you can add below code in functions.php and it work.
add_filter("woocommerce_checkout_fields", "woocommerce_reorder_checkout_fields", 9999);
if ( ! function_exists( 'woocommerce_reorder_checkout_fields' ) ) {
function woocommerce_reorder_checkout_fields( $fields ) {
/* To reorder state field you need to add this array. */
$order = array(
"billing_first_name",
"billing_last_name",
"billing_country",
"billing_state",
"billing_address_1",
"billing_address_2",
"billing_email",
"billing_phone"
);
foreach($order as $field) {
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
/* To change email and phone number you have to add only class no need to add priority. */
$fields['billing']['billing_email']['class'][0] = 'form-row-first';
$fields['billing']['billing_phone']['class'][0] = 'form-row-last';
return $fields;
}
}
See attached image For more info check this link