Last active
November 29, 2018 17:21
-
-
Save jrick1229/2d9311aa5dd4699fa2a959394ee6e2b6 to your computer and use it in GitHub Desktop.
Add customer to the cancelled subscription email as a 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 | |
function add_customer_to_cancelled_subscription_email( $recipient, $order ) { | |
// Bail on WC settings pages since the order object isn't yet set yet | |
// Not sure why this is even a thing, but shikata ga nai | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
if ( 'wc-settings' === $page ) { | |
return $recipient; | |
} | |
// just in case | |
if ( ! $order instanceof WC_Order ) { | |
return $recipient; | |
} | |
$items = $order->get_items(); | |
// check if a shipped product is in the order | |
foreach ( $items as $item ) { | |
$product = $order->get_product_from_item( $item ); | |
// add our extra recipient if there's a shipped product - commas needed! | |
// we can bail if we've found one, no need to add the recipient more than once | |
if ( $product && $product->needs_shipping() ) { | |
$recipient .= ', ' . $order->billing_email; | |
return $recipient; | |
} | |
} | |
return $recipient; | |
} | |
add_filter( 'woocommerce_email_recipient_cancelled_subscription', 'add_customer_to_cancelled_subscription_email', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment