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 certain regions.
However, to implement this condition, the developer needs to get region ID by region & country code in Magento 2. The below code shows how to do so.
Another scenario where this solution can be useful is when the customer address is to be collected.
Method To Get Region ID By Region & Country Code In Magento 2:
public function __construct(RegionFactory $regionFactory)
$this->regionFactory = $regionFactory;
public function getRegionId($stateCode, $countryId)
return $this->regionFactory->loadByCode($stateCode, $countryId)->getRegionId();
Any doubts in the above code? Please feel free to mention them in the Comments section below. I’d try to help you out asap.
Do share the solution with Magento developers out there via social media.