Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/44b1447804fc120f0eeba3935d4cb1bf to your computer and use it in GitHub Desktop.
Save kimcoleman/44b1447804fc120f0eeba3935d4cb1bf to your computer and use it in GitHub Desktop.
Example of using the pmpro_mailchimp_listsubscribe_fields filter to send extra fields to Mailchimp. The fields must be created in Mailchimp first, or you must used the pmpro_mailchimp_merge_fields filter to create them.
<?php
/**
* Sync additional user fields to Mailchimp.
* You must create the fields in Mailchimp first.
* Or, you can use the `pmpro_mailchimp_merge_fields` filter to create them through the API.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
*/
function my_pmpro_mailchimp_listsubscribe_fields( $fields, $user ) {
$new_fields = array(
"TITLE" => $user->title,
"COMPANY" => $user->company,
"ADDRESS" => $user->address,
"CITY" => $user->city,
"STATE" => $user->state,
"ZIPCODE" => $user->zipcode,
"COUNTY" => $user->county,
"REGION" => $user->region,
"INDUSTRY" => $user->industry,
"PHONE" => $user->phone
);
$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 (optional).
* Requires PMPro Mailchimp v2.0.3 or higher.
*/
add_filter( 'pmpromc_profile_update', '__return_true' );
@kimcoleman
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment