-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpaa-restrict-country-by-field.php
: Added new snippet.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
gp-address-autocomplete/gpaa-restrict-country-by-field.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Gravity Perks // Address Autocomplete // Restrict Country by Field | ||
* https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/ | ||
* | ||
* Restrict autocomplete results to a specific country (or countries) for a specific field. | ||
* | ||
* Instructions: | ||
* | ||
* 1. Install this snippet with our free Custom JavaScript plugin. | ||
* https://gravitywiz.com/gravity-forms-custom-javascript/ | ||
* | ||
* 2. Follow the inline instructions to configure this for your specific field. | ||
*/ | ||
gform.addFilter( 'gpaa_autocomplete_options', function( autocompleteOptions, gpaa, formId, fieldId ) { | ||
// Update "1" to your Address field ID. | ||
if ( formId != GFFORMID || fieldId != 1 ) { | ||
return autocompleteOptions; | ||
} | ||
if ( typeof autocompleteOptions.componentRestrictions !== 'object' ) { | ||
autocompleteOptions.componentRestrictions = {}; | ||
} | ||
// Update "DE" to the country to which you would like to restrict results. | ||
autocompleteOptions.componentRestrictions.country = [ 'DE' ]; | ||
return autocompleteOptions; | ||
} ); |