How to reorder the woocommerce checkout form fields?
author
,
Aspirant Programmer

In wordpress while using woocommerce to develope ecommerce website if we want to customize the checkout form by moving some fields from its default position. How to reorder the woocommerce checout fields?

  • Total 1 Answer
  • 294
Can You answer this question?
author
,
Aspirant Programmer

Woocommerce is one of very popular plugin to create ecommerce plate form in wordpress. Developing a website in woocommece requires less time, effort and cost until any customization is made. We can get a plenty of built in themes with attractive designs and features.

But sometime we don't go with readymade themes instead we ask designer to create design and get the web pages ready in bootstrap. To integrate the design in woocommerce specially checkout form requires programming knowledge of woocomerce. So, to reorder the checkout form fields we can use below hook and get it done as per our requirement easily. Write the below code in functions.php of wordpress or create a custom plugin for the same:

add_filter("woocommerce_checkout_fields", "custom_form_fields");

function custom_form_fields($fields) {

    $field_order = array(
        "billing_first_name", 
        "billing_last_name", 
        "billing_company", 
        "billing_address_1", 
        "billing_address_2", 
        "billing_postcode", 
        "billing_country", 
        "billing_email", 
        "billing_phone"

    );
    foreach($field_order as $field)
    {
        $ordered_fields[$field] = $fields["billing"][$field];
    }

    $fields["billing"] = $ordered_fields;
    return $fields;

}