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