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);
@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