How to make checkout “state” field not required/optional in Woocommerce ?

In this tutorial we’ll learn how to make state field on checkout page optional. First of all add some product(s) in cart and proceed to checkout after doing so. Here you can see that the state field is required.

woocommerce

If i click on place order, this order list will be displayed.

woocommerce1

Here you can see the state field error as well, which means that this field is required.

Now add following lines of code at the end of your theme’s functions.php file:

add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
 
add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
 
 
 
function woo_filter_state_billing( $address_fields ) {
 
                $address_fields['billing_state']['required'] = false;
 
                return $address_fields;
 
}
 
 
 
function woo_filter_state_shipping( $address_fields ) {
 
                $address_fields['shipping_state']['required'] = false;
 
                return $address_fields;
 
}

You can access functions.php file here:

woocommerce

This will make the state field optional.

Now if I click on place order button again you’ll see that state message is no longer in error list.

woocommerce

In this way you can make othere fields optional/required as well.

 

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

Your email address will not be published. Required fields are marked *