Do you want to make some checkout fields not required such as phone number or the first name? Use this snippet below to do this.
In the above we are making the billing first name, last name, phone number, email and country as not required.
To add more you need to just add the HTML names of the fields. You can use inspect to check the names on the checkout page. For your reference we have added them below.
Likewise you can change the text “false” to be “true” to make them required.
Billing Fields
- billing_first_name
- billing_last_name
- billing_company
- billing_country
- billing_address_1
- billing_address_2
- billing_city
- billing_state
- billing_postcode
- billing_phone
- billing_email
Shipping Fields
- shipping_first_name
- shipping_last_name
- shipping_company
- shipping_country
- shipping_address_1
- shipping_address_2
- shipping_city
- shipping_state
- shipping_postcode
Order Fields
- order_comments
Seems ‘default address fields’ are treated differently, this worked for me:
// Remove default_address_fields from checkout
add_filter( ‘woocommerce_default_address_fields’ , ‘custom_override_default_address_fields’ );
function custom_override_default_address_fields( $address_fields ) {
$address_fields[‘address_1’][‘required’] = false;
$address_fields[‘address_2’][‘required’] = false;
$address_fields[‘city’][‘required’] = false;
$address_fields[‘state’][‘required’] = false;
$address_fields[‘postcode’][‘required’] = false;
return $address_fields;
}
https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
Thanks for the code – I am sure it will help others too so really appreciate the comment.
Have a great day Mike!
It works with the fields in the example.
But not for
billing_address_1
billing_city
billing_postcode
They remain required.
Where do I add this code? Do I upload a new PHP file with the code or just paste it somewhere?
Please add this in your functions.php file in a child theme