It’s mandatory for the online store to use the State/Province field in their system. But in some countries, there is no need to include a few states at the time of checkout.

In this article, I will show you how to restrict some US States in the checkout. For this, I have created a US State restriction selection drop-down in the admin panel system configuration. In the example below, you may find Dckap as Namespace and CustomerAddresses as ModuleName.

Step 1

We have to create a system configuration in the admin panel for getting the allowed US states for checkout. Create a system.xml file in the path below and the configuration will be displayed in Stores → Configuration → Sales → Checkout

Path: app/code/Dckap/CustomerAddresses/etc/adminhtml/system.xml

<section id="checkout" translate="label" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">




    <group id="state_filter" translate="label" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">

          <label>Allowed US States in Checkout</label>

          <field id="us_state_filter" translate="label comment" type="multiselect" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">

                <label>Allowed US States in Checkout </label> <source_model>Dckap\CustomerAddresses\Model\Config\Region\ RegionInformationProvider</source_model>




First of all, we need to get the list of the allowed states, so we will need to gather such details from the Magento\Directory\Model\ResourceModel\Region\Collection. From this collection, we will be able to get the allowed country name, and by using the country details, we will get the states’ data, so we will have to override some files for collecting such information.

Path: app/code/Dckap/CustomerAddresses/etc/frontend/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

      <type name="Magento\Directory\Model\ResourceModel\Region\Collection">

           <plugin name="Dckap_CustomerAddresses_Limit_State_Filter_Plugin" type="Dckap\CustomerAddresses\Plugin\StateFilter\StateFilter"/>



Then we will have to update the US state list in that multi-select box form using below class.


Path : Dckap\CustomerAddresses\Model\Config\Region\RegionInformationProvider

namespace Dckap\CustomerAddresses\Model\Config\Region;

class RegionInformationProvider



   * @var \Magento\Directory\Api\CountryInformationAcquirerInterface


  protected $countryInformationAcquirer;

  protected $addressRepository;

  public function __construct(

      \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformationAcquirer

  ) {

         $this->countryInformationAcquirer = $countryInformationAcquirer;


  public function toOptionArray()


        $countries = $this->countryInformationAcquirer->getCountriesInfo();

        foreach ($countries as $country) {

            // Get regions for this country:
            $regions = [];

            if ($availableRegions = $country->getAvailableRegions()) {

                 foreach ($availableRegions as $region) {

                      $regions[] = [

                         'value' => $region->getName(),

                         'label' => $region->getName()




        return $regions;



Planning to implement Magento 2

Our Magento-certified experts come up with best-in-class solutions to improve conversions, increase sales and also provide a great user experience.

Get In Touch

Step 2

In Magento2 admin panel, go to Stores → Configuration from the left-side navigation panel. Then Goto General section → General → Country options → Choose ‘United States’ in Allowed Countries. Because we only list the allowed countries states in our custom system configuration field.

Magento 2 Checkout

And then select the US States from the Allowed US States in Checkout drop-down which you will want to display in the checkout form.

Magento 2 Checkout

Step 3

To get the chosen allowed US States for the checkout page by using the below set of code, we must override the Magento\Directory\Model\ResourceModel\Region\Collection for the checkout form State/Province drop down.


namespace Dckap\CustomerAddresses\Plugin\StateFilter;

class StateFilter



   * @var \Magento\Framework\App\Config\ScopeConfigInterface


  protected $scopeConfig;

  protected $allowedUsStates;


   * StateFilter constructor.

   * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig


  public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)


      $this->scopeConfig = $scopeConfig;


  public function afterToOptionArray($subject, $options)


      $allowedStates = $this->scopeConfig->getValue('checkout/state_filter/us_state_filter', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

      $this->allowedUsStates = explode(",", $allowedStates);

      $result = array_filter($options, function ($option) {

          if (isset($option['label'])){

              return in_array($option['label'], $this->allowedUsStates);


          return true;


      return $result;




$this->allowedUsStates => This variable has an array of allowed US state values.

$option => This variable has all the US states.

By using the above after function, we must compare both the state values and return the chosen state value, if that was present in the $option.

Step 4

Open your terminal and go to the Magento 2 root. Run from there with the following command:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
php bin/magento cache:flush

Finally, the chosen states will show up in the checkout page state/province selection dropdown.

If you found this blog helpful, then please do let us know if you have any queries.

You can focus on achieving your business goals.
Still Wondering who will take care of Magento Support and Maintenance ?
The answer is “Us” – Get in touch! Let’s talk about how!


  • Rama Lekshmi

    Rama Lekshmi enjoys solving complex problems and turning them into a simple and perfect coding structure. She is very fond of the logic and structure of coding and has always strived to write smart and efficient code, whether be it WordPress, CodeIgniter and Magento 2. When she isn't coding, she likes taking a tour all over India.


Ready to drive online revenue

Get In Touch

4 thoughts on “How to restrict specific US states in checkout – Magento 2

  1. Hi Rama,
    I ‘ve followed your method but it’s not working for me. I can’t make the configuration show on the checkout backend.

  2. Hello and thank you for this module.
    Is there a way to show all states regarding to what i choose in the module on billing form?

    Thank you again

  3. Thanks for this great tutorial.

    Well, there is one more step that you can mention in your post i,e Running CLI Commands.

    As running some CLI commands are necessary like:

    php bin/magento setup:upgrade
    php bin/magento setup:di:compile
    php bin/magento setup:static-content:deploy -f
    php bin/magento cache:clean
    php bin/magento cache:flush

    Keep up the good work 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *