Last active
March 21, 2018 14:41
-
-
Save strangerstudios/54b00c4046982ea966fe0babb112fa52 to your computer and use it in GitHub Desktop.
my_pmpro_mailchimp_listsubscribe_fields example for jslightham
This file contains hidden or 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 | |
*/ | |
function my_pmpro_mailchimp_listsubscribe_fields($fields, $user) | |
{ | |
//get level | |
$level = pmpro_getMembershipLevelForUser($user->ID); | |
//get order | |
$order = new MemberOrder(); | |
$order->getLastMemberOrder($user->ID); | |
//get vars | |
$first_name = $user->first_name; | |
$last_name = $user->last_name; | |
$bcity = get_user_meta($user->ID, 'pmpro_bcity', true); | |
$bstate = get_user_meta($user->ID, 'pmpro_bstate', true); | |
$membership_cost = $level->initial_payment; | |
$invoice_total = $order->total; | |
$membership_expiration = $level->enddate; | |
$new_fields = array( | |
"MERGE3" => $bcity, | |
"MERGE4" => $bstate, | |
"MERGE6" => $membership_cost, | |
"MERGE7" => $invoice_total, | |
"MERGE9" => $membership_expiration, | |
"MERGE8" => date('Y-m-d', current_time('timestamp'))); | |
$fields = array_merge($fields, $new_fields); | |
return $fields; | |
} | |
add_action('pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_fields', 10, 2); | |
/* | |
Tell PMPro MailChimp to always synchronize user profile updates. By default it only synchronizes if the user's email has changed. | |
*/ | |
add_filter('pmpromc_profile_update', '__return_true'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment