Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/9fb16e6a22958990636bf7a4c8469596 to your computer and use it in GitHub Desktop.
Save ipokkel/9fb16e6a22958990636bf7a4c8469596 to your computer and use it in GitHub Desktop.
Don't send recurring payment email reminder to specified levels.
<?php
/**
* Do not sent recurring payment reminder email to specified levels.
*
* This may be useful to stop sending reminder emails for short
* billing term recurring payment membership levels.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorm_dont_send_reminder_to_levels( $send_mail, $user, $lastorder ) {
// Set level IDs that should not receive a recurring payment reminder email here
$no_reminder_levels = array( 3, 5 );
// Get membership level for user
if ( ! empty( $lastorder->membership_id ) ) {
$membership_level = intval( $lastorder->membership_id );
} else {
$membership_level = pmpro_getMembershipLevelForUser( $user->ID );
if ( ! empty( $membership_level ) ) {
$membership_level = intval( $membership_level->id );
}
}
// Don't send a reminder if the user has a level that shouldn't receive a recurring payment reminder.
if ( ! empty( $membership_level ) && in_array( $membership_level, $no_reminder_levels ) ) {
return false;
}
return $send_mail;
}
add_filter( 'pmprorm_send_reminder_to_user', 'my_pmprorm_dont_send_reminder_to_levels', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment