0

How can I change/remove some states from Shopping Cart and Checkout page?

For example. I need to remove:

  • American Samoa;
  • Virgin Islands;
  • Armed Forces Africa (Americas, Canada, Europe, Middle East, Pacific);
  • etc

enter image description here

0

1 Answer 1

1

This issue has already been asked and resolved here - How to change state list for USA in Magento 2?

Quoting it for your reference;

You can filter out the options using a Plugin for the toOptionArray() method of Magento\Directory\Model\ResourceModel\Region\Collection:

class StateFilter
{
    protected $disallowed = [
        'Guam',
        'Puerto Rico',
        'Palau',
        'Virgin Islands',
        'Northern Mariana Islands',
        'Marshall Islands',
        'Federated States Of Micronesia',
        'American Samoa',
        'Armed Forces Africa',
        'Armed Forces Americas',
        'Armed Forces Canada',
        'Armed Forces Europe',
        'Armed Forces Middle East',
        'Armed Forces Pacific',
        'Hawaii',
        'Alaska'
    ];

    public function afterToOptionArray($subject, $options)
    {
        $result = array_filter($options, function ($option) {
            if (isset($option['label']))
                return !in_array($option['label'], $this->disallowed);
            return true;
        });

        return $result;
    }
}

To get the Plugin working, add this to your module's frontend di.xml:

<type name="Magento\Directory\Model\ResourceModel\Region\Collection">
    <plugin name="MyCompany_MyModule_Limit_State_Filter_Plugin" type="MyCompany\MyModule\Plugin\StateFilter"/>
</type>

[More information about creating Plugins in Magento 2 here][1].

[1]: http://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.