Skip to content

Instantly share code, notes, and snippets.

@webaware
Created January 19, 2024 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webaware/397a20016f5cf97ac004ac76645abe28 to your computer and use it in GitHub Desktop.
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.
<?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