Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created November 18, 2022 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/a0ac39d0121ac916fc0e91792afe19bd to your computer and use it in GitHub Desktop.
Save ipokkel/a0ac39d0121ac916fc0e91792afe19bd to your computer and use it in GitHub Desktop.
Disable PMPro Invoice emails per level.
<?php
/**
* Disable the PMPro invoice email for specified 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_pmpro_disable_invoice_email_per_level( $recipient, $email ) {
// Set levels to disable emails for
$disable_invoice_levels = array( 1 ); // e.g. array( 1, 2, 3 ) or array( 1 )
if ( $email->template == 'invoice' ) { //use this to check for a certain template
$user = get_user_by( 'login', $email->data['user_login'] );
$level = pmpro_getMembershipLevelForUser( $user->ID );
if ( ! empty( $level ) && ! empty( $level->id ) && in_array( $level->id, $disable_invoice_levels, true ) ) {
$recipient = null;
}
}
return $recipient;
}
add_filter( 'pmpro_email_recipient', 'my_pmpro_disable_invoice_email_per_level', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment