{"id":798,"date":"2020-01-31T05:33:35","date_gmt":"2020-01-31T05:33:35","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/01\/31\/magento-2-get-region-id-by-region-country-code\/"},"modified":"2025-05-22T15:04:03","modified_gmt":"2025-05-22T09:34:03","slug":"magento-2-get-region-id-by-region-country-code","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-get-region-id-by-region-country-code\/","title":{"rendered":"How To Get Region ID By Region &#038; Country Code In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 store owners implement various tactics based on different conditions to maximize profits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a store owner can offer discounts on shipping to certain regions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, to implement this condition, the developer needs to <strong>get region ID by region &amp; country code in Magento 2<\/strong>. The below code shows how to do so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another scenario where this solution can be useful is when the customer address is to be collected. Also <a href=\"https:\/\/meetanshi.com\/blog\/get-region-code-by-region-id-magento-2\/\">get region code by region ID in Magento 2<\/a> which is used to retrieve the specific region code associated with a given region ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method To Get Region ID By Region &amp; Country Code In Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Magento\\Directory\\Model\\RegionFactory;\n\nprotected $regionFactory;\n\npublic function __construct(RegionFactory $regionFactory) \n{\n    $this->regionFactory = $regionFactory;\n}\n\npublic function getRegionId($stateCode, $countryId)\n{\n    return $this->regionFactory->loadByCode($stateCode, $countryId)->getRegionId();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with Magento developers out there via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 store owners implement various tactics based on different conditions to maximize profits. For example, a store owner can offer discounts on shipping to&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-798","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"predecessor-version":[{"id":15105,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/798\/revisions\/15105"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}