Created
September 2, 2015 15:39
-
-
Save strangerstudios/b8f64e713d66583bdc71 to your computer and use it in GitHub Desktop.
Sync name and level to Mailchimp with PMPro and PMPro Mailchimp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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