Created
November 18, 2022 14:46
-
-
Save ipokkel/a0ac39d0121ac916fc0e91792afe19bd to your computer and use it in GitHub Desktop.
Disable PMPro Invoice emails per level.
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 | |
/** | |
* 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