I am using this module in my Drupal Commerce store. I need to be able to hide certain states, since I only ship to continental USA. I don't want to allow the option of Alaska and Hawaii for example.

Thank you!

Tom

Comments

rszrama’s picture

Issue summary: View changes
Priority: Critical » Normal
Status: Active » Closed (won't fix)

Hey Tom, I don't see us adding this as a feature to this module directly. There isn't really a good place for us to support the filtering of available administrative areas like there is for available countries. Your best bet will be a simple form alter to remove the states you don't want to show when US is selected as a country.

mrP’s picture

Ran across this in my search for a solution restricting states to the continental US. Based on @rszrama feedback, here is what I implemented to achieve this with Drupal Commerce:


/**
 * Implements hook_form_alter().
 */
function custom_mods_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'commerce_checkout_form_checkout') {
    // Restrict to Continental US only
    $continental_us = array(
      ''   => t('--'),
      'AL' => t('Alabama'),
      'AZ' => t('Arizona'),
      'AR' => t('Arkansas'),
      'CA' => t('California'),
      'CO' => t('Colorado'),
      'CT' => t('Connecticut'),
      'DE' => t('Delaware'),
      'DC' => t('District Of Columbia'),
      'FL' => t('Florida'),
      'GA' => t('Georgia'),
      'ID' => t('Idaho'),
      'IL' => t('Illinois'),
      'IN' => t('Indiana'),
      'IA' => t('Iowa'),
      'KS' => t('Kansas'),
      'KY' => t('Kentucky'),
      'LA' => t('Louisiana'),
      'ME' => t('Maine'),
      'MD' => t('Maryland'),
      'MA' => t('Massachusetts'),
      'MI' => t('Michigan'),
      'MN' => t('Minnesota'),
      'MS' => t('Mississippi'),
      'MO' => t('Missouri'),
      'MT' => t('Montana'),
      'NE' => t('Nebraska'),
      'NV' => t('Nevada'),
      'NH' => t('New Hampshire'),
      'NJ' => t('New Jersey'),
      'NM' => t('New Mexico'),
      'NY' => t('New York'),
      'NC' => t('North Carolina'),
      'ND' => t('North Dakota'),
      'OH' => t('Ohio'),
      'OK' => t('Oklahoma'),
      'OR' => t('Oregon'),
      'PA' => t('Pennsylvania'),
      'RI' => t('Rhode Island'),
      'SC' => t('South Carolina'),
      'SD' => t('South Dakota'),
      'TN' => t('Tennessee'),
      'TX' => t('Texas'),
      'UT' => t('Utah'),
      'VT' => t('Vermont'),
      'VA' => t('Virginia'),
      'WA' => t('Washington'),
      'WV' => t('West Virginia'),
      'WI' => t('Wisconsin'),
      'WY' => t('Wyoming'),
    );
    $form['customer_profile_billing']['commerce_customer_address']['und']['0']['locality_block']['administrative_area']['#options'] = $continental_us;
    $form['customer_profile_shipping']['commerce_customer_address']['und']['0']['locality_block']['administrative_area']['#options'] = $continental_us;

  }
}

nitheesh’s picture

This can be achieved by hook_addressfield_administrative_areas_alter()

See my comment on https://www.drupal.org/project/addressfield/issues/1483628#comment-12716255