Support

Account

Home Forums General Issues How to sync ACF-field with Mailchimp?

Solving

How to sync ACF-field with Mailchimp?

  • Hi!

    I’m syncing my WordPress users with a contact list (an “audience”) in Mailchimp. I’m currently only syncing native WordPress information like firstname, lastname, e-mail (these are synced by default) and role. I’ve tried to add ACF-field values to the sync (see attached image) but it doesn’t work. Is it even possible?

    The original developer of my site has hidden ACF from the backend so I can’t see the id of the field in question. I’ve tried a couple values (“5cdde36032dd0” and “field_5cdde36032dd0”) which show up in the address bar when I sort my users by the field. Does any of these look right, or does the actual id have a different format?

    Thanks!

  • The second value you listed above (field_5cdde36032dd0) is the correct format for the key for an ACF field. ACF field keys always start with field_ followed by the string that is the unique identifier.

    I took a look at the Mail Chimp documentation (https://www.mc4wp.com/kb/syncing-custom-user-fields-mailchimp/) and I am not sure if the send additional fields feature (shown in your screenshot above) can be used with ACF fields. Theoretically this should work as ACF stores the custom field as part of the user meta. Try using both the field key and the field name in the send additional fields form and see if that works.

    If not you could also try the filter outlined at the bottom of the Mail Chimp documentation (under the heading Advanced Fields). I haven’t tested this but here is an example of how this filter might be used:

    
    add_filter( 'mc4wp_user_sync_subscriber_data', function( $subscriber, $user ) {
        //Get the user id
        $user_id = $user->ID;
        //Format the user id for ACF
        $acf_user_id = 'user_' . $user_id;
        //Get the value for your custom field using the field name
        $my_custom_field_value = get_field('my_custom_field_name', $acf_user_id);
        //Sync the custom field value with the Mail Chimp field you want to store it in
        $subscriber->merge_fields['MY_FIELD'] = $my_custom_field_value;
        return $subscriber;
    }, 10, 2 );
    
    

    Hope this info is helpful! Note I am not on ACF support staff, someone from ACF may be able to provide you with a better answer.

  • I got a notification about an answer to my question. Why can’t I see it here?

  • Hi Rawland:

    I submitted a response this morning, I think my comment was held for moderation. I kept accidentally submitting my response before I was finished typing, I think I submitted too many edits in a short time period. Here is my response again:

    The second is the correct format for your field key (field_5cdde36032dd0). All ACF field keys begin with “field_” followed by the unique identifier string.

    I checked the Mail Chimp documentation (https://www.mc4wp.com/kb/syncing-custom-user-fields-mailchimp/) and it looks like theoretically ACF fields should be able to be synced using the Send Additional Fields feature of the Mail Chimp plugin (shown in your screenshot), as ACF stores fields attached to users as user meta. Try using both the field key and the field name in the form and see if that works.

    If not you could try the filter solution outlined at the bottom of the Mail Chimp documentation under the heading Advanced Fields. Here is an example of how this filter might be used:

    
    add_filter( 'mc4wp_user_sync_subscriber_data', function( $subscriber, $user ) {
        //Get the user id
        $user_id = $user->ID;
        //Format the user id for ACF
        $acf_user_id = 'user_' . $user_id;
        //Get the value for your custom field using the field name
        $my_custom_field_value = get_field('my_custom_field_name', $acf_user_id);
        //Sync the custom field value with the Mail Chimp field you want to store it in
        $subscriber->merge_fields['MY_FIELD'] = $my_custom_field_value;
        return $subscriber;
    }, 10, 2 );
    

    Hope that information is helpful! I am just a community member and am not part of ACF staff (I am just pawn in game of ACF). Someone from the staff may be able to better advise you if this info doesn’t work.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How to sync ACF-field with Mailchimp?’ is closed to new replies.