• Resolved zedhmem

    (@zedhmem)


    After selecting country, State field disappears. It is happening with few countries not for all.

    e.g. When i am going to select “United States”, State Field shows all states of United States. But after selecting other country like “Poland, Sri Lanka and few others”, State Field disappears.

    And On submitting the form, it gives the alert “State is required” whereas State field is disappears.

    • This topic was modified 8 years, 2 months ago by zedhmem.
    • This topic was modified 8 years, 2 months ago by zedhmem.
Viewing 1 replies (of 1 total)
  • I’ve had the same issue – doesn’t appear to check any logic to see if the state is required in certain countries.

    I’ve developed this hook which appears to do the job if you’re interested – goes in your functions.php file:

    add_filter( 'woocommerce_checkout_fields' , function($fields) {
        $WC = WC();
        $WC_Countries = new WC_Countries();
        $states = $WC_Countries->get_states($WC->customer->get_country());
        if($states !== false && !count($states)) {
            $fields['billing']['billing_state']['required'] = false;
        }
        $states = $WC_Countries->get_states($WC->customer->get_shipping_country());
        if($states !== false && !count($states)) {
            $fields['shipping']['shipping_state']['required'] = false;
        }
        return $fields;
    });

    Hope this helps

Viewing 1 replies (of 1 total)
  • The topic ‘State Field Disappears’ is closed to new replies.