Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active January 23, 2022 06:44
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/2a9e72a94290fa8a9c7d6d60c9ae052a to your computer and use it in GitHub Desktop.
Save webaware/2a9e72a94290fa8a9c7d6d60c9ae052a to your computer and use it in GitHub Desktop.
restrict Gravity Forms addresses to USA, Canada; with support for GF Address Enhanced
<?php
/*
Plugin Name: GF Countries Restrict
Plugin URI: https://gist.github.com/webaware/2a9e72a94290fa8a9c7d6d60c9ae052a
Update URI: gf-countries-restrict
Description: restrict Gravity Forms addresses to USA, Canada
Version: 1
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
/*
copyright (c) 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.
*/
use function webaware\gf_address_enhanced\get_country_name;
if (!defined('ABSPATH')) {
exit;
}
/**
* restrict which countries are available in Address field
* @param array $countries
* @return array
*/
add_filter('gform_countries', function($countries) {
return [
get_country_name('US'),
get_country_name('CA'),
];
});
/**
* restrict which countries have Smart States data loaded for them
* @param array $countries
* @return array
*/
add_filter('gf_address_enhanced_smart_states_countries', function($countries) {
return [
get_country_name('US') => 'US',
get_country_name('CA') => 'CA',
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment