In my commerce store, I would like to populate the country field with a preselected global address filter (which is determined by GEOIP).
Will a form alter do the trick? Any guidance is appreciated.
In my commerce store, I would like to populate the country field with a preselected global address filter (which is determined by GEOIP).
Will a form alter do the trick? Any guidance is appreciated.
Comments
Comment #1
milesw commentedTried to do the same thing but this doesn't seem possible right now. AddressField data always includes a country, even on a brand new form. There's no reliable way to know whether that country is a stored value or just a default. If it's a stored value, and you set the country using geoIP, you end up overwriting the user's setting.
Comment #2
rszrama commentedYeah, it has to be older than a form alter, because the country used to construct the form is a dependency of some of the form elements that may appear on the form. I'll address how to alter the widget in the documentation at #1267292: Document the user interface, API, and working with the form element.
Comment #3
j0rd commentedFrom what I can tell, this information on how to default country & state based of a GeoIP lookup was never added to the documentation.
Comment #4
rszrama commentedRight, that issue is still open, but this one is still linked from it to address.