Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexmoise/39101395ca2502ed32fe45058f04bca8 to your computer and use it in GitHub Desktop.
Save alexmoise/39101395ca2502ed32fe45058f04bca8 to your computer and use it in GitHub Desktop.
Sync name and level to Mailchimp with PMPro and PMPro Mailchimp
<?php
/**
* Plugin Name: Paid Memberships Pro - Sync fields to MailChimp
* Plugin URI: https://gist.github.com/alexmoise/
* Description: A simple plugin to sync fields between MailChimp and Paid Memberships Pro - MailChimp Add On. Only works with Paid Memberships Pro and MailChimp Add On installed and configured. Created as plugin out of https://gist.github.com/strangerstudios/b8f64e713d66583bdc71
* Version: 1.0.0
* Author: Alex Moise
* Author URI: http://moise.pro
*/
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