Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created October 29, 2019 10:43
Show Gist options
  • Select an option

  • Save ipokkel/d8c22a82273363326e8c84ce89b9cc99 to your computer and use it in GitHub Desktop.

Select an option

Save ipokkel/d8c22a82273363326e8c84ce89b9cc99 to your computer and use it in GitHub Desktop.
Add the enddate to Mailchimp Merge fields if it exists otherwise return "N/A"
<?php
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,
);
// 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