Home / Disable / MemberPress: Disable Emails for Specific Memberships
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Disable Emails for Specific Memberships

The code snippet will disable emails from being sent based on the text matching a membership title present in the body of an email. The membership title can be added to the email body manually, or automatically by adding the {$product_name} parameter to the email body.

In the example, the title of the membership used is "Free Membership". Thus, the code will disable any mail containing the Free Membership text somewhere in the email content (body). This works for both admin and user emails.

The code needs to be modified to match the title of the actual membership title. Here, the dummy Free Membership title should be changed to the title of the actual membership, on the following line:

if( strpos( $message, 'Free Membership' ) !== false ) {

Code Preview
php
<?php
function mepr_disable_membership_emails( $recipients, $subject, $message, $headers ) {
  if( strpos( $message, 'Free Membership' ) !== false ) {
    return null;
  }
  return $recipients;
}
add_filter( 'mepr-wp-mail-recipients', 'mepr_disable_membership_emails', 10, 4 );

Comments

Add a Comment