• Resolved Amir Hossein Karimi

    (@amirhossein7464)


    Hi, I am trying to change fields order in WooCommerce checkout page.
    Firstly I has changed order with following code:

    add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields', 40);
    function custom_override_checkout_fields($fields)
    {
        $fields['billing']['billing_state']['priority'] = 21;
        $fields['billing']['billing_city']['priority'] = 22;
        $fields['billing']['billing_postcode']['priority'] = 61;
        unset($fields['billing']['billing_address_2']);
        unset($fields['shipping']);
        return $fields;
    }

    After that I checked the source code of page and order was applied.
    But I have understand after page load some JavaScript codes will change the fields order.
    I found the wp-content/plugins/woocommerce/assets/js/frontend/address-i18n.min.js will do something which that change fields order.
    I found above this script injection in source code a variable with name: wc_address_i18n_params which looks like this hold locale format of countries, But I found the value of this variable is not which I applied and confirmed in HTML source code.
    I tried to deenqueue and deregister this script, But looks likes some other WooCommerce script need this script to run.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    I’m not a developer, so I can’t comment on your code. However, you could rearrange the fields using the Checkout Field Editor plugin:
    https://woocommerce.com/products/woocommerce-checkout-field-editor/

    Thread Starter Amir Hossein Karimi

    (@amirhossein7464)

    Hi @fernashes , Thanks for your reply, But I am a developer, I do not want to use any plugin to fix this problem, Also any plugins will drain some resource and add more time to response.
    Thank you anyway.

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there!

    Code is code at the end of the day – but that’s a completely different rabbit hole that we could go down. ??

    I’ll leave this thread open for a bit to see if anyone else can chime in to help you out with this.

    Thread Starter Amir Hossein Karimi

    (@amirhossein7464)

    Finally I used woocommerce_default_address_fields filter instead of woocommerce_checkout_fields filter and its work…

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Thanks for letting us know how you solved it!

    Amir, thanks bro for the answer.

    Since Hannah was unhelpful, the woocommerce_checkout_fields bug still exists in the i18n layer in wc 4.4.1. Your workaround helped me out.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change fields order in checkout page’ is closed to new replies.