chitezh / woocommerce_states_places

Woocommerce plugin that lists states, cities, local government areas and towns
https://wordpress.org/plugins/states-cities-and-places-for-woocommerce
GNU General Public License v3.0
50 stars 141 forks source link

Turn State Field REQUIRED, not optional. #221

Closed tws-x closed 2 years ago

tws-x commented 2 years ago

No solution to make this field required? If people do not fill the state it won't let fill the city. This must be required.

tws-x commented 2 years ago

Solved:

add_filter( 'woocommerce_get_country_locale', 'custom_country_locale_state_optional', 10, 1 );
function custom_country_locale_state_optional( $locale ) {
    foreach( $locale as $country_code => $state_field ) {
        if( isset($locale[$country_code]['state']) ) {
            $locale[$country_code]['state']['required'] = true;
        }
    }
    return $locale;
}