• Resolved owyvan

    (@owyvan)


    I’ve had this problem for some time now. In some countries (Sweden, France) State Field is hidden in checkout. If you choose GB or USA, State Field shows up. I Need to make State Field to always show up on all countries but have no clue how to fix it.

    Example State Field Shown – https://imgur.com/DRj6xB5

    Example State Field Hidden – https://imgur.com/ut5sAuk

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Same problem here but for WC sites in Chile.

    Tested for WC sites in Argentina and No problem.

    Another user has reported the same problem for WC sites in Brazil. https://goo.gl/8EpQQB

    Thanks!

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    WooCommerce shows shipping and billing address fields that are relevant for that country. Sweden (as an example) doesn’t usually use the state in addresses, which is why it’s not included.

    If you’d like to modify the behavior for your specific site, then here’s a good place to get started:
    https://www.xadapter.com/enable-shipping-state-field-for-specific-countries-during-woocommerce-checkout/

    If you feel this is a bug, please do report it on the WooCommerce Github repo:
    https://github.com/woocommerce/woocommerce/issues/new/choose

    @sebaros – can you please start your own topic? While it sounds like it may be related, it’s far easier to troubleshoot one issue per thread.

    Thread Starter owyvan

    (@owyvan)

    @fernashes
    @sebaros

    I Did try the code,

    function xa_filter_woocommerce_states( $states ) { 
        unset( $states['AF'] );
        var_dump( $states ) ;
        return $states;
    };
    add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 );
    
    function xa_filter_woocommerce_get_country_locale( $locale ) { 
        $locale['AF']['state']['required'] = true;
        return $locale; 
    };
    add_filter( 'woocommerce_get_country_locale', 'xa_filter_woocommerce_get_country_locale', 10, 1 );
    

    But it was messy. I got a lot of random text on my checkout page. Instead I used,

    
    add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 );
    

    which made it possible to show State Field on all countries. Hope this helps anyone else having the same issue.

    • This reply was modified 6 years ago by owyvan.
    • This reply was modified 6 years ago by owyvan.

    @owyvan Thanks!

    @owyvan

    The functions.php code below does work, but it causes two issues:

    1. The dropdown list for countries with states, such as the United States, are overridden and do not appear as they did before this code was added. This forces the customer to manually enter their state instead of selecting it from the dropdown list.

    2. The focus remains on the country field instead of the country field being hidden upon country selection.

    add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 );

    Does anyone know how to adopt this solution while preventing the two issues above? Thanks in advance for any help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce Checkout Hidden State Field’ is closed to new replies.