In Woocommerce, I need to set the default ordering priority (sorting) of three fields on the checkout page:
The first change depends on the choice of the 'IT' country code:
- postcode - 'priority' => 91,
The other two are free of conditions, I just need to set the default priority:
- billing_email - 'priority' => 30,
- billing_phone - 'priority' => 40,
By editing the file directly, class-wc-countries.php core file as shown below, I get what I need. But clearly at each update of the plugin I lose the changes.
Now I'm looking for a hook to get this done in a clean way.
In class-wc-countries.php (around line 935) from:
IT' => array(
'postcode' => array(
'priority' => 65, // <============= HERE
),
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
),
I change the 'priority' value from 65 to 91:
IT' => array(
'postcode' => array(
'priority' => 91, // <============= HERE
),
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
),
And arround line 1203 in:
// Add email and phone fields.
if ( 'billing_' === $type ) {
$address_fields['billing_phone'] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => true,
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'tel',
'priority' => 100, // <============= HERE
);
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete'=>'no'===get_option
('woocommerce_registration_generate_username' )
? 'email' : 'email username',
'priority' => 110, // <============= HERE
);
}
I change the 'priority' values to:
// Add email and phone fields.
if ( 'billing_' === $type ) {
$address_fields['billing_phone'] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => true,
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'tel',
'priority' => 40, // <============= HERE
);
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete'=>'no'===get_option
('woocommerce_registration_generate_username' )
? 'email' : 'email username',
'priority' => 30, // <============= HERE
);
}
Any help is appreciated.