Oh snap! You are using an old version of browser. Update your browser to get new awesome features. Click for more details.

Magento 2 Load Region By Region Id


If you need region data by region id. check the below code.


/**
* @var \Magento\Directory\Model\RegionFactory
*/
protected $_regionFactory;

public function __construct(
    \Magento\Directory\Model\RegionFactory $regionFactory $regionFactory
) {
    $this->_regionFactory = $regionFactory;
}

function getRegionDataById($regionId){
//Ex. $regionId = 12;
$region = $this->_regionFactory->create();
        $region->load($regionId);
        echo '<pre>';print_r($region->getData());exit;
}

Output
Array
(
    [region_id] => 12
    [country_id] => US
    [code] => CA
    [default_name] => California
    [name] => California
)

hope so it will help.

1 comment

  1. hi thanks for the nice article.
    i wonder there is a type mistake. \Magento\Directory\Model\RegionFactory $regionFactory $regionFactory. Please remove the repeating $regionFactory.

    ReplyDelete