In this post I am going to explain how to get region id and region name by region code in Magento 2.
Use this below code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 | $regionCode = 'CA'; $countryCode = 'US'; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $region = $objectManager->create('Magento\Directory\Model\Region'); $regionId = $region->loadByCode($regionCode, $countryCode)->getId(); echo $regionId; $regionName = $region->loadByCode($regionCode, $countryCode)->getName(); echo $regionName; |
Thats it. Enjoy Magento 2!!
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
Leave a Reply