Search code examples
phpwordpresswoocommerceemail-notificationswoocommerce-subscriptions

Add BCC recipient to Completed Renewal Order notification in WooCommerce Subscriptions


I am trying to add a BCC recipient to a specific type of mail sent by WooCommerce. This concerns the customers that receive a renewal mail. The type of the mail is 'Completed Renewal Order'.

I am aware of this post: How to add BCC recipient to all emails sent by WooCommerce? which discusses adding a BCC to every mail sent by WooCommerce.

The solution for that problem was found as:

function add_bcc_all_emails( $headers, $object ) {

    $headers = array( 
         $headers,
         'Bcc: Me <[email protected]>' ."\r\n",
    );

    return $headers;
}
add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2 );

I would like to edit this code, so we can add a BCC to the 'Completed Renewal Orders' only.


Solution

  • Use the following revisited code, to target Completed Renewal Order email notification, while adding a Bcc recipient:

    add_filter( 'woocommerce_email_headers', 'add_bcc_to_completed_renewal_order_notification', 10, 2 );
    function add_bcc_to_completed_renewal_order_notification( $headers, $email_id ) {
        if( $email_id === 'customer_completed_renewal_order' ) {
            $full_name = 'Mr Someone';
            $email     = '[email protected]';
    
            $headers  .= sprintf("Bcc: %s\r\n",  utf8_decode($full_name.' <'.$email.'>') );
        }
        return $headers;
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    Related: Target a specific email notification with the email id in WooCommerce