wordpress – Place the ZIP code field in the Woocommerce checkout


I need to position the zip code field before the address because I'm going to load the address using the post office api, I can position the other fields, but the "billing_postcode" does not obey the order, what can it be?

add_filter("woocommerce_checkout_fields", "order_fields", 30);
function order_fields($fields) {
    $fields["billing"]["billing_cpf_cli"]["priority"] = 8;
    $fields["billing"]["billing_rg_cli"]["priority"] = 9;
    $fields["billing"]["billing_postcode"]["priority"] = 10;
    $fields["billing"]["billing_address_1"]["priority"] = 11;
    $fields["billing"]["billing_num_cli"]["priority"] = 20;
    $fields["billing"]["billing_bairro_cli"]["priority"] = 21;  

    return $fields;

add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');


A friendlier way to deal with this type of problem related to the priority of the fields is to evaluate, through your browser's element inspector, the priority where the current fields are, so you can find your way around faster. In the element inspector, look for data-priority="NÚMERO DA PRIORIDADE DO CAMPO"

In a standard WooCommerce checkout page address_1 has priority 50, so just put the postcode in 50 and address_1 in 55, for example. From what I noticed in your code, you are trying to change the priority through woocommerce_checkout_fields , but in this case it is woocommerce_default_address_fields that you need to change the priority, so a solution to your problem would be:

add_filter( 'woocommerce_default_address_fields', 'woocommerce_default_address_fields_reorder' );

function woocommerce_default_address_fields_reorder( $fields ) {
    $fields['postcode']['priority'] = 50; // antes era o address_1 que ocupava esta prioridade baseado no padrão WooCommerce de prioridades.
    $fields['address_1']['priority'] = 55;

    return $fields;

I recommend that you take a look at the WooCommerce documentation itself to better understand how all this works.

Hope this helps,


Scroll to Top