Magento – How to Remove Certain States from State/Region List at Checkout or Registration

addresscheckoutmagento-1.9magento-enterprisestate

The list of regions for USA contains: Alaska, Hawaii, American Samoa, Guam, Marshall Islands, Micronesia and Armed American and so on.
This is the list that is available both during registration and on checkout.

So If someone want to remove the state/region named Alaska, Hawaii, American Samoa, Guam, Marshall Islands. How we can achieve this?

Best Answer

This can be easily achievable without removing from "directory_country_region" database table.

Just you need to follow below steps:

  1. Override _getRegions($storeId) method of Mage_Directory_Helper_Data class.
  2. Assign the Region Codes which you want to exclude into an array i.e $excludeRegions variable.
  3. Add logic for skip above region codes from available list

So the final code looks like as below:

    $excludeRegions = array('AK','AS','AF','AA','AC','AE','AM','AP','DC','FM','GU','HI','MH','MP','PW','PR','VI');
    foreach ($collection as $region) {
        if (!$region->getRegionId()) {
            continue;
        }
        //BOF Custom Logic Here
        $regionCode = $region->getCode();
        if (in_array($regionCode, $excludeRegions)) {
            continue;
        }
        //EOF Custom Logic Here
        $regions[$region->getCountryId()][$region->getRegionId()] = array(
            'code' => $region->getCode(),
            'name' => $this->__($region->getName())
        );
    }

Hoping this will help to someone.

Thanks,

Related Topic