Positioning the zip code field at Woocommerce checkout

1

I need to position the field of zip before the address because I will load the address using the api of the mails, I can position the other fields, but the "billing_postcode" does not obey the order, what can 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');
    
asked by anonymous 28.09.2018 / 14:17

1 answer

0

A friendlier way of dealing with this type of problem related to field priority is by evaluating through your browser's element inspector the priority on which the current fields are, so you can get more quickly oriented. In the element inspector, search for data-priority="NÚMERO DA PRIORIDADE DO CAMPO"

On a standard WooCommerce checkout page address_1 has priority of 50, so just put the postcode at 50 and the address_1 at 55, for example. From what I noticed in your code, you're trying to change the priority through woocommerce_checkout_fields, but in this case it's woocommerce_default_address_fields that you need to change the priority, then a solution for 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 you take a look at WooCommerce documentation to better understand how all of this works.

I hope I have helped,

Hugs!

    
03.10.2018 / 16:28