If you are looking to re-order the checkout fields on the final order details page of woocommerce, then this can be quite easily changed.
You may be using the WooCommerce Checkout Field Editor plugin, but depending on the theme re-ordering the checkout fields using the drag tool may not work if there are other sorting functions within the theme.
Here’s how to change the order of your fields using priority by adding the following code into the childs theme functions.php. The code uses the built in add_filter(“woocommerce_checkout_fields” woocommerce filter.
In the code below, you can see we have added some additional fields, “po-number2”, “account-number2”, “nc2”. Each field is given a priority and the fields are ordered using the function ‘custom_order_fields’. The following code was tested using a custom theme and woocommerce version 3.4.3
add_filter("woocommerce_checkout_fields", "custom_order_fields");
function custom_order_fields($fields) {
$order = array(
“billing_first_name”,
“billing_last_name”,
“billing_email”,
“billing_phone”,
“billing_country”,
“billing_company”,
“billing_address_1”,
“billing_address_2”,
“billing_city”,
“billing_postcode”,
“po-number2”,
“account-number2”,
“nc2”,
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields[“billing”][$field];
}
$fields[“billing”] = $ordered_fields;
$fields[‘billing’][‘billing_first_name’][‘priority’] = 10;
$fields[‘billing’][‘billing_last_name’][‘priority’] = 20;
$fields[‘billing’][‘billing_email’][‘priority’] = 30;
$fields[‘billing’][‘billing_phone’][‘priority’] = 40;
$fields[‘billing’][‘billing_country’][‘priority’] = 50;
$fields[‘billing’][‘billing_company’][‘priority’] = 60;
$fields[‘billing’][‘billing_address_1’][‘priority’] = 70;
$fields[‘billing’][‘billing_address_2’][‘priority’] = 80;
$fields[‘billing’][‘billing_city’][‘priority’] = 90;
$fields[‘billing’][‘billing_postcode’][‘priority’] = 95;
$fields[‘billing’][‘po-number2’][‘priority’] = 100;
$fields[‘billing’][‘account-number2’][‘priority’] = 101;
$fields[‘billing’][‘nc2’][‘priority’] = 102;
return $fields;
}
Leave a Reply
You must belogged in to post a comment.