Last active
October 7, 2024 14:38
-
-
Save ThemeGravity/7f9a44f9a50449362b6cf769eda5033a to your computer and use it in GitHub Desktop.
Disable Before Subscription Trial Ends reminder for canceled membership
This file contains hidden or 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 | |
add_filter('mepr-sub-trial-ends-reminder-disable', function($disable_email, $reminder, $usr, $prd, $event) { | |
global $wpdb; | |
// Membership ID with trial | |
$trial_membership_id = 2973; | |
$active_subs = $usr->active_product_subscriptions(); | |
// User is not active on any membership - so let's not send the reminder | |
if (empty($active_subs)) { | |
return $disable_email; | |
} | |
// 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($trial_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 = {$trial_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; | |
}, 11, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment