Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active June 13, 2020 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save damiencarbery/d045aa304144320b85af49777deaca52 to your computer and use it in GitHub Desktop.
Save damiencarbery/d045aa304144320b85af49777deaca52 to your computer and use it in GitHub Desktop.
Add BCC to WooCommerce emails - Add an email address (or two) as BCC to all WooCommerce emails. https://www.damiencarbery.com/2020/03/add-bcc-to-woocommerce-emails/
<?php
/*
Plugin Name: Add BCC to WooCommerce emails (with YITH)
Plugin URI: https://www.damiencarbery.com/2020/03/add-bcc-to-woocommerce-emails/
Description: Add an email address as BCC to all WooCommerce emails. Updated for when YITH Request a Quote installed.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
// YITH Request a Quote calls the pre-WooCommerce 3.7.0 parameter version of the 'woocommerce_email_headers' filter (with 3 parameters).
add_action( 'woocommerce_email_header', 'dcwd_add_bcc_to_woocommerce_emails_header' );
function dcwd_add_bcc_to_woocommerce_emails_header( ) {
if ( class_exists( 'YITH_YWRAQ_Send_Email_Request_Quote' ) ) {
//error_log( 'Class YITH_YWRAQ_Send_Email_Request_Quote exists.' );
add_filter( 'woocommerce_email_headers', 'dcwd_woocommerce_email_headers_3', 10, 3 );
}
else {
//error_log( 'No class YITH_YWRAQ_Send_Email_Request_Quote active.' );
add_filter( 'woocommerce_email_headers', 'dcwd_woocommerce_email_headers', 10, 4 );
}
}
// Simple wrapper around the newer 4 parameter version of the filter call.
function dcwd_woocommerce_email_headers_3( $header, $email_id, $email_for_obj ) {
return dcwd_woocommerce_email_headers( $header, $email_id, $email_for_obj, null );
}
function dcwd_woocommerce_email_headers( $header, $email_id, $email_for_obj, $email_class ) {
// Bcc this email address to *all* WooCommerce emails.
$header .= 'Bcc: you@domain.com' . "\r\n";
// Add another address to the Order Completed emails only.
if ( 'customer_completed_order' == $email_id ) {
$header .= 'Bcc: me@domain.com' . "\r\n";
}
return $header;
}
<?php
/*
Plugin Name: Add BCC to WooCommerce emails
Plugin URI: https://www.damiencarbery.com/2020/03/add-bcc-to-woocommerce-emails/
Description: Add an email address as BCC to all WooCommerce emails.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
add_filter( 'woocommerce_email_headers', 'dcwd_woocommerce_email_headers', 10, 4 );
function dcwd_woocommerce_email_headers( $header, $email_id, $email_for_obj, $email_class ) {
// Bcc this email address to *all* WooCommerce emails.
$header .= 'Bcc: you@domain.com' . "\r\n";
// Add another address to the Order Completed emails only.
if ( 'customer_completed_order' == $email_id ) {
$header .= 'Bcc: me@domain.com' . "\r\n";
}
return $header;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment