How to Add New Region for Specific Country in Magento 2
Magento 2 store owner requires customers’ address for shipping the ordered items.
Also, while creating a new customer account before ordering anything, it is good to get customers’ address data upfront so that they can quickly place the orders once the items are selected.
Moreover, it may happen that it is important to have the customers’ region data even for downloadable products in order to apply the tax according to region-specific rules.
For such address requirements, the default Magento 2 offers the database from which a customer can select their country, state, or city from the frontend.
However, a developer may require to add new region for specific country in Magento 2 database when a new region is created or it may be missing from the database for some reasons.
In this scenario, simply follow the below solution and let the customer select their region while creating a new account or placing an order in Magento 2 store:
Method to Add New Region for Specific Country in Magento 2:
Run the below SQL query:
INSERT INTO
directory_country_region
(country_id
, code
, default_name
) VALUES ("country_code","region_code","region_name");
For example, I want to add a new region “Ladakh” for India as shown below:
The above example can be implemented with the below SQL query:
INSERT INTO directory_country_region(country_id, code, default_name) VALUES ("IN","Leh","ladakh");
That’s it!
Any doubts in the above solution can be mentioned in the Comments section below.
I’d be happy to help.
Also, do share the post with Magento Community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Update Product Attribute Value Programmatically in Magento 2
How to Change Category Page Layout in Magento 2
Next