Last active
January 6, 2023 03:46
-
-
Save NickGreen/736c96ce3f6394466d84657d2e9f18f5 to your computer and use it in GitHub Desktop.
Change email recipients
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( 'woocommerce_email_recipient_expired_subscription', 'wcs_change_recipient_for_expired_sub_notification', 10, 2 ); | |
function wcs_change_recipient_for_expired_sub_notification( $recipient, $order ) { | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
if ( 'wc-settings' === $page ) { | |
return $recipient; | |
} | |
$recipient = $order->billing_email; | |
return $recipient; | |
} |
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( 'woocommerce_email_recipient_customer_processing_renewal_order', 'wcs_disable_customer_order_email_if_free', 10, 2 ); | |
add_filter( 'woocommerce_email_recipient_customer_completed_renewal_order', 'wcs_disable_customer_order_email_if_free', 10, 2 ); | |
// If Total = 0 we change the email recipient to "" | |
function wcs_disable_customer_order_email_if_free( $recipient, $order ) { | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
if ( 'wc-settings' === $page ) { | |
return $recipient; | |
} | |
if( $order->get_total() === '0.00' ) $recipient = ''; | |
return $recipient; | |
} |
I just have one question about the code, what does this line of code does?
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
That checks if you're in wp-admin and looking at the wc-settings
page. If that's the case, then it doesn't change the recipient email. It will only change the recipient email in other contexts, such as during the sending of the email itself.
Thanks a lot for your code and guidance. I really appreciate it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for the code, it worked like a charm.
I just have one question about the code, what does this line of code does?
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';