• Resolved Pramathesh

    (@paramathesh)


    The latest update has made the State/County field as optional. How can I change it make it mandatory?

Viewing 6 replies - 1 through 6 (of 6 total)
  • AJ a11n

    (@amandasjackson)

    Hi there @paramathesh

    By default, State and Country fields should be required in WooCommerce core. I am running version 3.4.3 on my test site, and these fields are required (with only WooCommerce active). It sounds like there may be something interfering with this default behaviour.

    This kind of problem is usually caused by either a conflict with your theme or with another plugin.

    The best way to determine if the issue is being caused by a theme and/or plugin is to temporarily switch your theme to Storefront and disable all plugins except for WooCommerce. If you can install plugins, install Health Check. On the troubleshooting tab, you can click the button to disable all plugins and change the theme for you while you’re logged in to that session without affecting normal visitors to your site. Note that Health Check may not count Storefront as a default theme, so you can also use Twenty Seventeen as well.

    If that resolves the issue, then one-by-one you can switch back your theme and re-enable your plugins, testing in between, until you find the one causing the conflict.

    AJ a11n

    (@amandasjackson)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Clean WordPress 4.9.7 / Woocommerce 3.4.3 / Storefront install.
    County still appears as optional.

    Also using this plugin, state field appears as not required by default.

    Partially solved with filter. But you have to make priority 999

    add_filter( 'woocommerce_billing_fields', 'formulare_filter_billing_state', 10, 999 );
    function formulare_filter_billing_state( $address_fields ) {
    	$address_fields['billing_state']['required'] = true;
    	return $address_fields;
    }

    I say partially because the filter makes the field required, but when the state field is input after label it has * and it’s required , when state field is select after label it has (optional) and is required.

    I use clean WordPress 4.9.7 / Woocommerce 3.4.3 / Storefront install. No other plugins.

    Found the issue. Not for all countries, state is required. For example: country Romania, in class-wc-countries.php we have this

    'RO' => array(
       'state' => array(
         'label'    => __( 'County', 'woocommerce' ),
         'required' => false,
       ),
    ),
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Make State/County Mandatory’ is closed to new replies.