Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Forked from ipokkel/pmpro-mc-merge-enddate.php
Last active August 17, 2021 10:59
Show Gist options
  • Select an option

  • Save MaryOJob/f9381c8bb0ee1e2a69735a32ccd3b4c0 to your computer and use it in GitHub Desktop.

Select an option

Save MaryOJob/f9381c8bb0ee1e2a69735a32ccd3b4c0 to your computer and use it in GitHub Desktop.
Add the enddate to Mailchimp Merge fields if it exists otherwise return "N/A"
<?php // do not copy this line
/**
* Add this to a PMPro customizations or Code Snippets Plugin: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
**/
add_action( 'pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_fields', 10, 2 );
function my_pmpro_mailchimp_listsubscribe_fields( $fields, $user ) {
// Get user level
$level = pmpro_getMembershipLevelForUser( $user->ID );
// Declare variable and set default
$expiration_date = 'N/A';
// Update variable value if level has an expiration date
if ( ! empty( $level->enddate ) ) {
$expiration_date = date( 'd/m/Y', $level->enddate );
}
// Create new ENDDATE field
$new_fields = array(
'ENDDATE' => $expiration_date,
// 'FNAME' => $user->first_name, // uncomment and edit if you need to send other fields to Mailchimp
);
// join existing fields with new fields
$fields = array_merge( $fields, $new_fields );
return $fields;
}
/*
(Optional) Tell PMPro MailChimp to always synchronize user profile updates. By default it only synchronizes if the user's email has changed.
Requires PMPro Mailchimp v2.0.3 or higher.
*/
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