skip to Main Content

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]>' ."rn",
    );

    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.

2

Answers


  1. You can create a condition to send email only in a specific condition, so change your code to:

    function add_bcc_all_emails( $headers, $object ) {
       if ($object == 'completed_renewal_orders') {  // replace with correct slug for Completed Renewal Orders
           $headers = array( 
              $headers,
              'Bcc: Me <[email protected]>' ."rn",
          );
        }
        return $headers;
    }
    add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2 );
    
    Login or Signup to reply.
  2. 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: %srn",  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search