• Resolved maltfield

    (@maltfield)


    I’ve discovered that when a customer checks-out, the “Province” or “State” field (called billing_state or shipping_state in the code) will sometimes disappear depending on the “Country / Region” that’s selected.

    My question is: where can I find the list of countries that, when selected, the shipping_state field disappears?

    Ideally, I’d like a link to the correct file and line in the WooCommerce sourcecode that defines which countries require shipping_state and which do not.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter maltfield

    (@maltfield)

    As far as I can tell, any country that’s assigned an empty array in this file does not require a billing_state or shipping_state

    More logic can be found here (see get_states() function)

    Thread Starter maltfield

    (@maltfield)

    I still haven’t found the relevant code, but it appears that there’s three cases (but I could be wrong)

    1. The user is presented with a drop-down to choose the State/Province
    2. The field is removed and the user cannot enter a State/Province
    3. The filed is a free-form County?(optional) input box, and the user can type what they want

    My theory is that #1 happens when the array in the above-linked file contains some values (eg US), #2 when the array in the above-linked file is empty (eg EE), and #3 when the country doesn’t appear in the above-linked file at all (eg GB).

    • This reply was modified 1 year, 6 months ago by maltfield.
    Thread Starter maltfield

    (@maltfield)

    Actually, it looks like some get_country_locale() function declares if the state is required or not, and it also defines the human-readable label that appears to the user at checkout (eg County, Province, State, Canton, District, Department, Parish, Region, Prefecture, Municipality, State / Zone, or Municipality / District).

    In addition to required, some countries’s state is defined as hidden. For example, the country of Estonia (EE) is hidden and not required

    'EE' => array(
      'postcode' => array(
        'priority' => 65,
      ),
      'state' => array(
        'required' => false,
        'hidden'   => true,
      ),
    ),

    EDIT: My theory about this was wrong. I did a quick check of all the countries whose state is set to 'hidden' => true, and I got this list

    AF, AT, AX, BA, BE, BH, BI, CZ, DE, DK, EE, FI, FR, GP, GF, IS, IL, IM, KR, KW, LB, MF, MQ, MT, NL, NO, PL, PR, PT, RE, SG, SK, SI, LK, LU, SE, VN, YT

    While some of these countries (eg Estonia = EE) don’t show the State input field at checkout, at least one on this list (eg Germany = DE) *does* show the State input dropdown when selecting it at checkout.

    …so I’m still not sure exactly how to figure out which countries do and which countries do not prompt the user for a State/Province at checkout ??

    • This reply was modified 1 year, 6 months ago by maltfield.
    • This reply was modified 1 year, 6 months ago by maltfield.
    • This reply was modified 1 year, 6 months ago by maltfield.
    • This reply was modified 1 year, 6 months ago by maltfield.
    • This reply was modified 1 year, 6 months ago by maltfield.

    Hi there @maltfield ??

    My question is: where can I find the list of countries that, when selected, the shipping_state field disappears?

    Thanks for reaching out, happy to help you with this.

    From what I gather, this is about customizing further the checkout page here, correct?

    Just to note, the Checkout Field Editor helps optimize your checkout process by adding, removing or editing fields to suit your needs.

    I hope that helps, otherwise let us know!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Which countries (don’t) require State/Provience (billing_state shipping_state)’ is closed to new replies.