Gravity Forms address to Mailchimp - country and state not getting through

In the interest of asking for no more information than is strictly needed, I want to use Gravity Forms to get the State and Country, then pass that along to Mailchimp.

When I use the Gravity Forms address field and only display the state and country fields, Mailchimp won’t accept the record because the address does not have all the fields and I am trying to put it into an address field. However, it appears to be uploading the country as a two character ISO country code (this is relevant later)

The logs show:
[merge_fields] => Array
(
[ADDRESS] => Array
(
[addr1] =>
[addr2] =>
[city] =>
[state] => CA
[zip] =>
[country] => US
)

[message] => Please enter a complete address

As a possible workaround I created a new merge field in Mailchimp - as a drop down with options of “US” or “CA”. Mailchimp rejects the entry as Gravity forms is sending the country as “United States”, which does not match “US”, even though the internal representation seems to be “US”

the logs show:
[merge_fields] => Array
(
[ADDRESS] => Array
(
[addr1] =>
[addr2] =>
[city] =>
[state] =>
[zip] =>
[country] => US
)

        [COUNTRY] => United States


[message] => Value must be one of: US, CA (not United States)

I will be using the Mailchimp country code to sync with other databases, so I would prefer it to use the 2 letter country code consistently through out.

Mailchimp support suggests reaching out to Gravity Forms.

Hello @wordpress1

You can add the following code snippet to your WordPress theme’s functions.php file:

add_filter( 'gform_countries', function () {
    $countries = GF_Fields::get( 'address' )->get_default_countries();
    asort( $countries );
    return $countries;
} );

This code will modify the way Gravity Forms handles country codes, ensuring that the two-letter ISO code is sent to Mailchimp.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.