Forked from dparker1005/mailchimp_oldmember.php
Last active
February 27, 2023 22:10
-
-
Save JarrydLong/37c7d264562d4f742ec628d5a03ec977 to your computer and use it in GitHub Desktop.
Creates an OLDMEMBER merge field in MailChimp.
This file contains 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 | |
/* | |
* Creates an OLDMEMBER merge field in MailChimp. | |
*/ | |
function my_pmpro_mailchimp_merge_field_oldmember( $merge_fields ) { | |
$merge_fields[] = array( | |
'name' => 'OLDMEMBER', | |
'type' => 'text' | |
); | |
return $merge_fields; | |
} | |
add_filter( 'pmpro_mailchimp_merge_fields', 'my_pmpro_mailchimp_merge_field_oldmember' ); | |
/* | |
* Populates the OLDUSER merge field in MailChimp | |
*/ | |
function my_pmpro_mailchimp_listsubscribe_field_oldmember($fields, $user) { | |
global $wpdb; | |
$has_membership = pmpro_hasMembershipLevel( null, $user->ID ); | |
$new_fields = array( | |
"OLDMEMBER" => !$has_membership ? 'yes' : 'no', | |
); | |
$fields = array_merge($fields, $new_fields); | |
return $fields; | |
} | |
add_action('pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_field_oldmember', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment