Created
January 4, 2019 00:03
-
-
Save cartpauj/30f735222f48566fe8bf8c9bc14c21e4 to your computer and use it in GitHub Desktop.
Disable signup reminder in MemberPress if user has cancelled monthly membership, or has upgraded to annual membership already
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 | |
// THIS CODE CAN BE PASTED INTO A PLUGIN LIKE Code Snippets, My Custom Functions, or placed in a Child Theme's functions.php file | |
// Begin copying from line #4 below | |
function disable_mepr_reminder_if_cancelled_or_upgraded($disable_email, $reminder, $usr, $prd) { | |
global $wpdb; | |
//BEGIN EDITING | |
$annual_membership_id = 2974; | |
$monthly_membership_id = 2973; | |
//STOP EDITING | |
$active_subs = $usr->active_product_subscriptions(); | |
// User is not active on any membership - so let's not send the reminder | |
if(empty($active_subs)) { $disable_email = true; } | |
// User has already upgraded to Annual - so let's not send the reminder | |
if(in_array($annual_membership_id, $active_subs, false)) { $disable_email = true; } | |
// The user may have canceled recently, but is still active... | |
// because their transaction to the Monthly membership has not expired yet... | |
// So we need to make sure the user's Subscription is not canceled before sending | |
if(in_array($monthly_membership_id, $active_subs, false)) { | |
$num_active = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}mepr_subscriptions WHERE user_id = {$usr->ID} AND product_id = {$monthly_membership_id} AND status = 'active'"); | |
// User has no enabled/active monthly subscriptions so disable the reminder because they've likely canceled recently | |
if(empty($num_active)) { | |
$disable_email = true; | |
} else { | |
$disable_email = false; | |
} | |
} else { | |
$disable_email = true; //We shouldn't ever get here, but just in case - don't send the reminder | |
} | |
return $disable_email; | |
} | |
add_filter('mepr-member-signup-reminder-disable', 'disable_mepr_reminder_if_cancelled_or_upgraded', 11, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment