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

milesw’s picture

Tried 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.

rszrama’s picture

Component: User interface » Documentation
Status: Active » Closed (duplicate)

Yeah, 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.

j0rd’s picture

Status: Closed (duplicate) » Active

From what I can tell, this information on how to default country & state based of a GeoIP lookup was never added to the documentation.

rszrama’s picture

Status: Active » Closed (duplicate)

Right, that issue is still open, but this one is still linked from it to address.