Created
January 19, 2024 21:41
-
-
Save webaware/397a20016f5cf97ac004ac76645abe28 to your computer and use it in GitHub Desktop.
GF Address Enhanced: Filter USA states to only have the Lower 48 + DC. Add this to a plugin, or functions.php in your theme.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter USA states to only have the Lower 48 + DC | |
*/ | |
add_filter('gf_address_enhanced_smart_states_script_data', function(array $script_data) : array { | |
if (isset($script_data['states']['United States'])) { | |
// Alaska, Hawaii, and the Armed Forces codes | |
$remove = ['AK', 'HI', 'AA', 'AE', 'AP']; | |
// filter out states with unwanted codes | |
$contiguous = array_filter($script_data['states']['United States'], function($state) use ($remove) { | |
return !in_array($state[0], $remove); | |
}); | |
// reset array keys to a natural sequence before adding back | |
$script_data['states']['United States'] = array_values($contiguous); | |
} | |
return $script_data; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment