Support » Plugin: WooCommerce » Changing the order of fields in checkout with priority doesn’t work

  • Resolved camilomejia

    (@camilomejia)


    I need to change the fields order in the checkout form and tried the solution described here “Change order of billing fields on checkout page” but it doesn’t work.

    This is the code I’m using to test

    
    function change_default_address_fields( $fields ) {
      $fields['city']['priority'] = 0;
      $fields['state']['priority'] = 200;
      return $fields;
    }
    add_filter( 'woocommerce_default_address_fields', 'change_default_address_fields' ); 
    
    function change_checkout_fields( $fields ) {
      $fields['billing']['billing_country']['priority'] = 0;
      $fields['billing']['billing_phone']['priority'] = 200;
      $fields['shipping']['shipping_country']['priority'] = 0;
      $fields['shipping']['shipping_phone']['priority'] = 200;
      return $fields;
    }
    add_filter( 'woocommerce_checkout_fields', 'change_checkout_fields' );
    

    According to the previous question about this, changing the priority is the official way to do that, but I can’t find the way to make it work. On the plugin code I doesn’t found something using the priority to render the fields in a custom order.

    The only way I found to change the order was altering the order fields in the array in class-wc-countries.php but that’s not the best idea. Changing priority in that file also doesn’t work.

    I’m using WooCommerce 3.1.2

    • This topic was modified 1 year, 8 months ago by  camilomejia.
    • This topic was modified 1 year, 8 months ago by  camilomejia.
Viewing 1 replies (of 1 total)
  • This work with the woocommerce_default_address_fields filter. I was unseting another field on that filter and that was causing problems.

    
    function change_default_address_fields( $fields ) {
      // unset( $fields['postcode'] ); <- this must be done on another filter like woocommerce_checkout_fields
      $fields['city']['priority'] = 80;
      $fields['state']['priority'] = 70;
      return $fields;
    }
    add_filter( 'woocommerce_default_address_fields', 'change_default_address_fields' );
    
    • This reply was modified 1 year, 8 months ago by  camilomejia.
Viewing 1 replies (of 1 total)
  • The topic ‘Changing the order of fields in checkout with priority doesn’t work’ is closed to new replies.