Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Created March 24, 2021 14:16
Show Gist options
  • Select an option

  • Save JarrydLong/7ec847602d97e4ffe67a75d264b6aa59 to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/7ec847602d97e4ffe67a75d264b6aa59 to your computer and use it in GitHub Desktop.
<?php
/*
* Creates a custom merge field in MailChimp.
*/
function my_pmpro_mailchimp_merge_fields( $merge_fields ) {
$merge_fields[] = array(
'name' => 'GOAL',
'type' => 'text'
);
return $merge_fields;
}
add_filter( 'pmpro_mailchimp_merge_fields', 'my_pmpro_mailchimp_merge_fields' );
/*
* Populates the custom merge field in MailChimp
*/
function my_pmpro_mailchimp_listsubscribe_fields($fields, $user) {
$user_id = $user->ID;
$new_fields = array(
"GOAL" => get_user_meta( $user_id, 'goal', true ),
);
$fields = array_merge($fields, $new_fields);
return $fields;
}
add_action('pmpro_mailchimp_listsubscribe_fields', 'my_pmpro_mailchimp_listsubscribe_fields', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment