Skip to content

Instantly share code, notes, and snippets.

@noameppel
Last active June 8, 2021 05:38
Show Gist options
  • Select an option

  • Save noameppel/76a663593251c02fa53920eda03f97e6 to your computer and use it in GitHub Desktop.

Select an option

Save noameppel/76a663593251c02fa53920eda03f97e6 to your computer and use it in GitHub Desktop.
Hooks in to MemberPress $args array before sending new member info to MailChimp.
<?php
/**
* [cleanforest_mepr_add_my_tags]
* Hooks in to MemberPress $args array before sending new member info to MailChimp.
* Used to add custom MERGETAG information.
*/
function cleanforest_mepr_add_my_tags($args, $contact)
{
// MMERGE3 State
$state = get_user_meta($contact->ID, 'mepr-address-state', true);
$args['merge_fields']['MMERGE3'] = $state;
// MMERGE7 State
global $wpdb;
$theuserid = $contact->ID;
$results = $wpdb->get_results($wpdb->prepare("SELECT expires_at FROM wp_mepr_transactions WHERE user_id = %d AND status IN ('complete', 'confirmed', 'pending') ORDER BY id DESC LIMIT 1", $theuserid, ARRAY_A)); // Output 2017-09-16 23:59:59
if ($results) {
foreach ($results as $result) {
$trans_expiry = $result->expires_at;
}
}
if ($trans_expiry) {
$myDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $trans_expiry);
$mailchimp_expiry = $myDateTime->format('m/d/Y'); // Format for MailChimp
$args['merge_fields']['MMERGE7'] = $mailchimp_expiry;
}
return $args;
}
add_filter('mepr-mailchimptags-add-tag-args', 'cleanforest_mepr_add_my_tags', 11, 2);
@murrinmedia
Copy link

Is this filter still accruate?
mepr-mailchimptags-add-tag-args?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment