Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NickGreen/736c96ce3f6394466d84657d2e9f18f5 to your computer and use it in GitHub Desktop.
Save NickGreen/736c96ce3f6394466d84657d2e9f18f5 to your computer and use it in GitHub Desktop.
Change email recipients
<?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;
}
<?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;
}
Copy link

ghost commented Dec 28, 2022

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'] : '';

@NickGreen
Copy link
Author

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.

Copy link

ghost commented Jan 6, 2023

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