We are running Magento 2.1.6.
We want to set predefined regions and areas as drop down lists in addresses, just like when you select country us, you have the states pre selected, etc..
For example, we want to add when people select UAE as the country to have the region field in address prepopulated with the 7 states in the UAE, and if for example the user select the state Dubai, we want to have a Area prepopulated with all the different areas known in Dubai what we would populate manually.
Any thoughts on how to do this ?
Best Answer
In order to show the region fields should be shown for non required state :
(can be configured from Stores / Configuration / General / State Options / Allow to Choose State if it is Optional for Country)
vendor/magento/module-directory/Helper/Data.php:268
In order to set the region required for a country :
(can be configured from Stores / Configuration / General / State Options / State is Required for)
vendor/magento/module-directory/Helper/Data.php:281
Then to add a new country and region :
directory_country
directory_country_region
related with the country_id column.directory_country_region_name
Add these information from a setup script. You can based on the Magento Directory Setup Data : vendor/magento/module-directory/Setup/InstallData.php:17