Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Created October 31, 2016 17:19
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jessepearson/fea13a281882b66d3a28d9b960312904 to your computer and use it in GitHub Desktop.
Save jessepearson/fea13a281882b66d3a28d9b960312904 to your computer and use it in GitHub Desktop.
Add a BCC to certain defined emails sent from WooCommerce
<?php // only copy this line if needed
/**
* Function adds a BCC header to emails that match our array
*
* @param string $headers The default headers being used
* @param string $object The email type/object that is being processed
*/
function add_bcc_to_certain_emails( $headers, $object ) {
// email types/objects to add bcc to
$add_bcc_to = array(
'customer_renewal_invoice', // Renewal invoice from WooCommerce Subscriptions
'customer_processing_order', // Customer Processing order from WooCommerce
);
// if our email object is in our array
if ( in_array( $object, $add_bcc_to ) ) {
// change our headers
$headers = array(
$headers,
'Bcc: Me <me@example.com>' ."\r\n",
);
}
return $headers;
}
add_filter( 'woocommerce_email_headers', 'add_bcc_to_certain_emails', 10, 2 );
@jessepearson
Copy link
Author

Has anything changed in the latest version of Woocommerce 4.20 with WordPress 5.4.2 The above code has stopped working. Please guide.

@KoolPal not that I am aware of. I just added it to a site and it worked for me.

@KoolPal
Copy link

KoolPal commented Jun 11, 2020

@jessepearson Thanks. I realized that one of the plugins I used had changed the email ID slugs.

Now I am seeing some PHP warnings and notices when emails are sent. Can you please guide me? (This is with the debug.log ENABLED)

[11-Jun-2020 11:22:32 UTC] PHP Warning:  strpos() expects parameter 1 to be string, array given in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 240
[11-Jun-2020 11:22:32 UTC] PHP Warning:  trim() expects parameter 1 to be string, array given in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 248
[11-Jun-2020 11:22:32 UTC] PHP Notice:  Undefined offset: 1 in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 248

Thanks a lot!

@jessepearson
Copy link
Author

@KoolPal that could be many, many things. If you're not seeing it once the snippet is disabled/removed, then you may need to reach out to a developer for help. You can also try the troubleshooting here: https://docs.woocommerce.com/document/woocommerce-self-service-guide/#section-4

@KoolPal
Copy link

KoolPal commented Jun 12, 2020

@KoolPal that could be many, many things. If you're not seeing it once the snippet is disabled/removed, then you may need to reach out to a developer for help. You can also try the troubleshooting here: https://docs.woocommerce.com/document/woocommerce-self-service-guide/#section-4

Thanks @jessepearson I will explore with the plugin author whose email is showing these.

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment