Categories

Saturday, April 27, 2024
#919814419350 therichposts@gmail.com
PhpWoocommerceWoocommerce HooksWordpress

How to Change order of billing fields on checkout page Woocommerce?

How to Change order of billing fields on checkout page Woocommerce?

Hello guys how are you? Welcome back to my channel. Today in this post I am going to show you How to Change order of billing fields on checkout page Woocommerce?

Guys I have used both latest versions WordPress 6.3 and WooCommerce 8.1.

Live Demo

Guys if you are new in WordPress or in WooCommerce then please check the below links for some good tutorials:

  1. WooCommerce Hooks
  2. WordPress Tricks
  3. WordPress Hooks
How to Change order of billing fields on checkout page Woocommerce?
How to Change order of billing fields on checkout page Woocommerce?

Guys here is the working code snippet and please use it carefully:

1. Guys here is the code snippet and you need to add your theme’s functions.php file:

function custom_override_checkout_fields( $fields ) {

  // Do things with your fields like setting the
  // priority, label, required, etc.
  // or removing them

  // Example: Set the priorities straight
  // Probably not meant for this since priority is something
  // totally different than order.
  $fields['billing']['billing_first_name']['priority'] = 0;
  $fields['billing']['billing_last_name']['priority'] = 5;
  $fields['billing']['billing_email']['priority'] = 10;
  $fields['billing']['billing_phone']['priority'] = 15;
  $fields['billing']['billing_country']['priority'] = 20;
  $fields['billing']['billing_state']['priority'] = 25;
  $fields['billing']['billing_address_1']['priority'] = 30;
  $fields['billing']['billing_address_2']['priority'] = 35;
  $fields['billing']['billing_postcode']['priority'] = 40;
  $fields['billing']['billing_city']['priority'] = 45;

  // Sort the fields based on their 'priority'
  usort($fields['billing'], function($a, $b) {
    return $a['priority'] <=> $b['priority'];
  });

  // Send the fields to the function that receives the fields data
  return $fields;
}
  • Reorder Woocommerce checkout fields
  • Change order of billing fields on checkout page woocommerce
  • Change order of billing fields on checkout page woo

This is it guys and if you will have any kind of query, suggestion or requirement then feel free to comment below.

Jassa

Developer’s King

Thanks

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.