Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active September 30, 2023 02:38
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/edba921af11f06bdfd5147bab806f591 to your computer and use it in GitHub Desktop.
Save webaware/edba921af11f06bdfd5147bab806f591 to your computer and use it in GitHub Desktop.
change United States to USA in Gravity Forms addresses, with support for Gravity Forms Address Enhanced
<?php
/*
Plugin Name: GF Country USA
Plugin URI: https://gist.github.com/webaware/edba921af11f06bdfd5147bab806f591
Description: change United States to USA in Gravity Forms addresses
Version: 2
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
/*
copyright (c) 2020-2022 WebAware Pty Ltd (email : support@webaware.com.au)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* change United States to show as USA
* @param array $countries
* @return array
*/
add_filter('gform_countries', function($countries) {
$key = array_search('United States', $countries);
$countries[$key] = 'USA';
sort($countries);
return $countries;
});
/**
* change GF Address Enhanced's map of country names to country codes
* @param array $countries
* @return array
*/
add_filter('gf_address_enhanced_countries', function($countries) {
unset($countries[translate('United States', 'gravityforms')]);
$countries['USA'] = 'US';
return $countries;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment