5

I'm trying to add BCC to every mail that is sent by woocommerce / wp. I tried using different solution found on the web and at Stackoverflow and added the snippets to the functions.php of the theme I'm using:

add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_admin_new_order', 10, 3 );
function add_bcc_to_wc_admin_new_order( $headers = '', $id = '', $wc_email = array() ) {
    if ( $id == 'new_order' ) {
        $headers .= "Bcc: my@mail.net\r\n";
    }
return $headers;
}

and

add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2);

function add_bcc_all_emails($headers, $object) {

    $headers = array();
    $headers[] = 'Bcc: my@mail.net';
    $headers[] = 'Content-Type: text/html';

    return $headers;
}

and

add_filter('wp_mail','custom_mails', 10,1);

function custom_mails($args){
    $bcc_email = sanitize_email('my@mail.net');

    if (is_array($args['headers'])){
        $args['headers'][] = 'Bcc: '.$bcc_email ;
    }
    else{
        $args['headers'] .= 'Bcc: '.$bcc_email."\r\n";
    }

    return $args;
}

I'm using "The Events Calendar" so I also tried this:

add_action( 'event_tickets_rsvp_tickets_generated', 'tribe_tickets_cc_organizer', 10, 3 );

function tribe_tickets_cc_organizer( $order_id = null, $post_id = null, $attendee_order_status = null ) {
    $to = tribe_get_organizer_email( $post_id, false );
    // bail if there's no valid email for the organizer
    if ( ! is_email( $to ) ) return;
        $event_name        = get_the_title( $post_id );
        $site_name         = get_bloginfo( 'name' );
        $attendee_list_url = admin_url( 'edit.php?post_type=tribe_events&page=tickets-attendees&event_id=' . $post_id ); 
        $content     = '<a href="' . esc_url( $attendee_list_url ) . '" style="color: #000; font-family: sans-serif;">Check the event attendee list</a>';
        $headers     = array( 'Content-type: text/html' );
        $subject     = sprintf( __( 'Your event %1$s has new attendee(s) - %2$s', 'tribe-extension' ), $event_name, $site_name );
        wp_mail( $to, $subject, $content, $headers);
    }

add_action( 'event_ticket_woo_attendee_created', 'tribe_woo_compat_cc', 10, 4 );

function tribe_woo_compat_cc ( $attendee_id, $event_id, $order, $product_id ) {
    tribe_tickets_cc_organizer( null, $event_id );
}

All of theme don't work as intended. They ignore the BCC and send out all emails again, so the admin and the user receive the mails double. But the added bcc mail doesn't receive one mail. I can't figure out, why this is isn't working. Anybody an idea?

Thanks in advance.

Jesse Nickles
  • 1,435
  • 1
  • 17
  • 25
DBR
  • 146
  • 1
  • 10

3 Answers3

5

Maybe you can have a try with:

function add_bcc_all_emails( $headers, $object ) {

    $headers = array( 
         $headers,
         'Bcc: Me <my@mail.net>' ."\r\n",
    );

    return $headers;
}
add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2 );
jjj
  • 965
  • 8
  • 23
  • Thanks, that one worked for me! To be honest, I believe the issue has been about 30cm (~11inch) in front of the computer. So I propose one of my already postet snippets should work for someone else to. – DBR Oct 23 '18 at 07:24
3

For a no code solution, try using the Post SMTP plugin to handle your email instead. Under Settings / Message there is an option to BCC on all emails coming out of WP including from WooCommerce.

Adam
  • 2,762
  • 1
  • 30
  • 32
0

To send BCC to all WooCommerce emails:

  • Remove previously added code snippets from your current theme's functions.php file
  • Add following snippet in your current theme's functions.php file

add_filter( 'woocommerce_email_headers', 'lh_wc_add_bcc_email', 10, 2 );

function lh_wc_add_bcc_email( $headers, $email ) {

    $headers .= 'BCC: Your name <you@email.com>' . "\r\n"; //replace 'Your name' with your name and 'you@email.com' with your email address

    return $headers;
}

Or you can use this plugin: CC & BCC for Woocommerce Order Emails

Kashif Rafique
  • 1,273
  • 1
  • 12
  • 25
  • Thanks for the snippet, but that didn't work for me at all. Just the usual mails where received. – DBR Oct 23 '18 at 07:22