Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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: 1
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
/*
copyright (c) 2020 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) {
$countries['USA'] = 'US';
return $countries;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment