Last active
November 22, 2021 02:19
-
-
Save NickGreen/a543c0fefaf4bf50eb180bde2aa6d77f to your computer and use it in GitHub Desktop.
Send to customer and 'CC' the admin on sub expired emails
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 | |
/** | |
* Plugin Name: Sub Expired Email Send to Customer | |
* Plugin URI: | |
* Description: | |
* Version: 1.0 | |
* Author: | |
* Author URI: | |
**/ | |
add_filter( 'woocommerce_email_headers', 'sub_expired_email_add_admin_cc', 9999, 3 ); | |
function sub_expired_email_add_admin_cc( $headers, $email_id, $order ) { | |
if ( 'expired_subscription' == $email_id ) { | |
$email = get_option( 'admin_email' ); | |
$headers .= "Cc: Admin <" . $email . ">" . "\r\n"; | |
} | |
return $headers; | |
} | |
function sub_expired_email_recipient( $recipient, $order ) { | |
// Bail on WC settings pages since the order object isn't yet set yet | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
if ( 'wc-settings' === $page ) { | |
return $recipient; | |
} | |
// just in case | |
if ( ! $order instanceof WC_Order ) { | |
return $recipient; | |
} | |
$email = $order->billing_email; | |
$recipient = $email; | |
return $recipient; | |
} | |
add_filter( 'woocommerce_email_recipient_expired_subscription', 'sub_expired_email_recipient', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment