# Make the State / County Field Optional

> Stops requiring the state, county or province at checkout for every country, for stores whose couriers do not need it.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, fields, address
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-optional-state-field/

## Code

```php
add_filter( 'woocommerce_get_country_locale', function ( $locales ) {
    foreach ( $locales as $country => $fields ) {
        if ( isset( $fields['state'] ) ) {
            $locales[ $country ]['state']['required'] = false;
        }
    }

    return $locales;
}, 20 );

add_filter( 'woocommerce_get_country_locale_default', function ( $fields ) {
    if ( isset( $fields['state'] ) ) {
        $fields['state']['required'] = false;
    }

    return $fields;
}, 20 );

add_filter( 'woocommerce_default_address_fields', function ( $fields ) {
    if ( isset( $fields['state'] ) ) {
        $fields['state']['required'] = false;
    }

    return $fields;
}, 20 );
```

## Notes

The field stays visible; customers can still fill it in.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Make the State / County Field Optional" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
