1

Before I describe my problem, just going to mention that I tried Commerce Addressbook and Commerce Extra (address populate) modules.

  • The first one is not suitable in general for my project (because it's based on billing address when the mother address used in this project is always user's one entered on registration) and
  • The latter is in alpha stage and has many issues (and still doesn't sort my problem)

The problem is that I cannot prepopulate County/State field on commerce checkout billing address form.

When using hook_form_alter, I can successfully prepopulate all fields, except county. The reason for this is that county drop down is loaded with ajax and dependent on Country value. It's getting created when the form is built so before the hook_alter_form is applied.

So for example let's say my billing address defaults to Ireland (one can setup a default value under customer profile -> billing information). A user registered using address in USA. When the user comes to billing form on checkout, gets all fields prepopulated with the address he/she registered with and country says United Stated, but county/state dropdown stays defaulted to Ireland (lists irish counties).

One needs to select other country than USA and then select USA again for ajax to load the proper county/states dropdown

I cannot seem to find a workaround for this. Any advice?

2

1 Answer 1

1

"So for example let's say my billing address defaults to Ireland (one can setup a default value under customer profile -> billing information)."

If I understand you correctly perhaps do not set a default value for the country in your addressfield options. I.e. do not select a country in the options illustrated below... this way the state options are generated after the user has selected their country...

enter image description here

Incidentally, if you could post whatever your hook_form_alter code is and where you put it... I'd find it really useful as I am also working to pre-populate addressfields with user-account details.

Thanks!

2
  • You can't not to set a default value on addressfields. Your image shows the list of available countries, not the same as default value (which is jus below format handlers section). I'll post the code in a while.
    – belinea
    Commented Jun 30, 2014 at 11:28
  • If you select one or more of the 'available countries' as illustrated in the screen cap, that selection will be all that's available, and if just one country is selected the addressfield will default to that value...hence 'hide the county value if just one is available'. Yes please, do paste the code. Thanks Commented Jun 30, 2014 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.