Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strangerstudios/b8f64e713d66583bdc71 to your computer and use it in GitHub Desktop.
Save strangerstudios/b8f64e713d66583bdc71 to your computer and use it in GitHub Desktop.
Sync name and level to Mailchimp with PMPro and PMPro Mailchimp
/*
Sync fields to MailChimp
Add this to a custom plugin or your active theme's functions.php file.
Make sure to add a "LEVEL" text merge field on the Mailchimp side.
*/
function my_pmpro_mailchimp_listsubscribe_fields($fields, $user)
{
if(!function_exists('pmpro_getMembershipLevelForUser'))
return;
$level = pmpro_getMembershipLevelForUser($user->ID);
if(!empty($level))
$level_name = $level->name;
else
$level_name = "None";
$new_fields = array(
"FNAME" => $user->first_name,
"LNAME" => $user->last_name,
"LEVEL" => $level_name,
);
$fields = array_merge($fields, $new_fields);
return $fields;
}
add_action('pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_fields', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment