Skip to content

Instantly share code, notes, and snippets.

@pjrvs
Last active December 9, 2022 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjrvs/30bf6a4cc2f124b19613f8b3c3518ff6 to your computer and use it in GitHub Desktop.
Save pjrvs/30bf6a4cc2f124b19613f8b3c3518ff6 to your computer and use it in GitHub Desktop.
here's the code to populate a mailchimp field with a wordpress variable:
add_filter( 'mailchimp_sync_subscriber_data', function( MC4WP_MailChimp_Subscriber $subscriber, $user ) {
$subscriber->merge_fields['MERGE6'] = AFF_ID_GOES_HERE;
return $subscriber;
}, 10, 2 );
here's the code to get the aff id:
if ( $affiliate = affiliate_wp()->affiliates->get_by( 'user_id', $user->ID ) ) {
// do stuff
}
how do i combine the two so i can push the affiliate ID to MERG6, only if it's not null (i.e. the user isn't an affiliate?
i'm trying to push the affiliate ID to mailchimp, thus letting me automate based on a changed/added merge field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment