Put Your Main Countries First in Gravity Forms
Moves the countries you sell to most to the top of Gravity Forms address and country drop-downs, so most visitors find theirs without scrolling.
Opens WPIDE on
Code
$wpide_gf_top_countries = array( 'United States', 'Canada', 'United Kingdom' );
$wpide_gf_only_listed = false; // True = offer only the countries above.
add_filter( 'gform_countries', function ( $countries ) use ( $wpide_gf_top_countries, $wpide_gf_only_listed ) {
$countries = (array) $countries;
$top = array_values( array_intersect( $wpide_gf_top_countries, $countries ) );
if ( $wpide_gf_only_listed ) {
return $top;
}
return array_merge( $top, array_values( array_diff( $countries, $top ) ) );
} );
Notes
Use the English country names exactly as Gravity Forms lists them; set $wpide_gf_only_listed to true to offer only those countries.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.