Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Created June 7, 2016 20:15
Show Gist options
  • Select an option

  • Save cartpauj/797ec5cf6e83d4725310b4231a743183 to your computer and use it in GitHub Desktop.

Select an option

Save cartpauj/797ec5cf6e83d4725310b4231a743183 to your computer and use it in GitHub Desktop.
Add custom MERGE fields using MemberPress and their MailChimp 3.0 integration
<?php
//hooks in to MemberPress $args array before sending new subscriber info to MailChimp
function mepr_add_my_tags($args, $member) {
$zip = get_user_meta($member->ID, 'mepr-address-zip', true);
$country = get_user_meta($member->ID, 'mepr-address-country', true);
if($zip) {
$args['merge_fields']['MMERGE6'] = $zip; //YOU'LL NEED TO CHANGE MMERGEX TO MAP THEM TO YOUR OWN TAG VALUES
}
if($country) {
$args['merge_fields']['MMERGE7'] = $country; //YOU'LL NEED TO CHANGE MMERGEX TO MAP THEM TO YOUR OWN TAG VALUES
}
return $args;
}
add_filter('mepr-mailchimptags-add-subscriber-args', 'mepr_add_my_tags', 11, 2);
@Mkvixj00
Copy link

Mkvixj00 commented Feb 1, 2020

Hi @cartpauj!
I have Memberpress with the addon for Mailchimp. I created a "Custom Field" in the Memberpress settings. I also created a column in the Mailchimp contacts with the same name as the "Custom Field". Unfortunately, the only thing that the Mailchimp addon for Memberpress can do is synchronize the type of subscription. How can I also synchronize my "Custom Field"? Where should I insert the PHP script above that you wrote? Thank you!

@cartpauj
Copy link
Author

cartpauj commented Feb 3, 2020

I like the Code Snippets plugin. You'd want to do a "run everywhere" snippet type.

@Mkvixj00
Copy link

Mkvixj00 commented Feb 3, 2020

Hi @cartpauj, Thanks!

@domridout
Copy link

Hi,

Thanks for this! Will it also work for dropdown and checkbox fields or just text fields?

Thanks,
Dom

@cartpauj
Copy link
Author

It should work for a dropdown field as long as it's not a multiselect field. I'm not sure if it would work for a checkbox field or not though.

@domridout
Copy link

That was a quick response, thanks!

Ok, I'll try it out and let you know.

@murrinmedia
Copy link

murrinmedia commented Jun 8, 2021

Hi @cartpauj

I'm trying to use this. Is the filter still mepr-mailchimptags-add-subscriber-args ?
I'm trying to get it working but it sends no data and I'm wondering if that filter is still accurate.

Just sending one field (state) to Mailchimp

@cartpauj
Copy link
Author

cartpauj commented Jun 8, 2021

@murrinmedia Yes, the 3 filters available are:
$args = MeprHooks::apply_filters( 'mepr-mailchimptags-add-subscriber-args', $args, $user );
$args = MeprHooks::apply_filters('mepr-mailchimptags-add-tag-args', $args, $contact);
$args = MeprHooks::apply_filters('mepr-mailchimptags-remove-tag-args', $args, $contact);

@murrinmedia
Copy link

Damn, Isn't working for me.

I can't tell if my code is incorrect or if the filter isn't even being used at all!

@ian-freakmusic
Copy link

At the moment this data is only passed to Mailchimp on a member's initial signup. This is not a failing of this piece of code - it's how Memberpress functions. Any subsequent edits to any user data is not passed to Mailchimp. Is there a way to do something to this code, with the web hook that is triggered when a member updates their profile details, so that you could sync the custom field data with MailChimp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment