Forked from greathmaster/pmpro-mailchimp-merge-with-address-field.php
Created
August 29, 2016 11:53
-
-
Save strangerstudios/d473abb787ada311bd777e6ae0f587e6 to your computer and use it in GitHub Desktop.
How to do MailChimp MERGE field with ADDRESS type
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
<?php | |
//Address merge types must be handled in a very specific format | |
function my_pmpro_mailchimp_listsubscribe_fields($fields, $user) | |
{ | |
$user_info = get_userdata($user->ID); | |
$new_fields = array( | |
"FNAME" => $user->first_name, | |
"EMAIL" => $user->email, | |
"LNAME" => $user->last_name, | |
"ADDRESS" => array( 'addr1' => $user_info->pmpro_baddress1, | |
'addr2' => $user_info->pmpro_baddress2, | |
'city' => $user_info->pmpro_bcity, | |
'state' => $user_info->pmpro_bstate, | |
'zip' => $user_info->pmpro_bzipcode, | |
'country' => $user_info->pmpro_bcountry) | |
); | |
$fields = array_merge($fields, $new_fields); | |
return $fields; | |
} | |
add_action('pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_fields', 10, 2); |
This recipe is included in the blog post on "Send a Member’s Address Fields to Mailchimp" at Paid Memberships Pro here: https://www.paidmembershipspro.com/send-members-address-fields-mailchimp/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please also note that if the fields you are sending are new merge fields, they must first be created in Mailchimp.
You can do this manually through the Mailchimp dashboard or use the pmpro_mailchimp_merge_fields filter to create them through the API like the example recipe here: https://gist.github.com/dparker1005/13ab3295d92818b3e46c53b0ca0268ba