How to Get Region Code by Region ID in Magento 2

How to Get Region Code by Region ID in Magento 2

In the world of drone delivery, there is no boundary, and businesses can deliver products and services to the customers around the corner. With Magento, one can run an internationally operated online store.

In most instances, while developing extensions or customization based on delivery and payment gateway, you need to avail the region data. Earlier, I provided the solution to get region ID by region & country code in Magento 2.

Generally, it is a small matter of task, if the requirement is related to the region name. However, it’s a little bit tricky when the need arrives to get region code by region ID in Magento 2.

Ever faced an issue for getting a region code by region ID ? The below code shows the steps to get region code by region ID in Magento 2.

Steps to Get Region Code by Region ID in Magento 2

  1. Create Data.php in Vendor\Extension\Helper and use the following solution.
In this code, two methods are mentioned to load order. Just use with which you’re comfortable!

  • Using order ID
  • Using order increment ID

Here the returned region code is AN’.

$this->_logger->log(print_r($region->getData(), true)) prints array log as mentioned below:

Just use this returned array in the code where you required to get state code, state name, and other requirements.
Quite catchy but solved!
Any query? Feel free to mention in the Comments section below. I’d try to help you out asap.
Don’t forget to share the solution with Magento Community via social media.
Thank you.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

4.9
(based on 9 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.