I am trying to customize the code that I found to cc on all email sent by wp-mail.
Here is my Code (found here):
// CC emails
add_filter('wp_mail','custom_mails', 10,1);
function custom_mails($args)
{
// Get the custom email from user meta data (with the correct User ID)
$cc_email = get_user_meta( $order->get_user_id(), 'doc_email', true );
if (is_array($args['headers']))
{
$args['headers'][] = 'cc: '.$cc_email;
}
else
{
$args['headers'] .= 'cc: '.$cc_email."\r\n";
}
return $args;
}
I have previously implemented the below code where it specifies a custom email address from the user metadata.
$custom_user_email = get_user_meta( $order->get_user_id(), 'order_cc_email', true );
From "Add custom user email to CC for specific Woocommerce email notification" answer code, I understand that the hook being used is the "woocommerce_email_headers
" in the example above, so the part of the line get_user_meta( $order->get_user_id()
, is relying on the order ID to then retrieve the User ID and then the metadata.
The question of how would I go about retrieving this field without using the $order
var?
Is the approach here to use get_current_user_id()
? So can then get that piece of metadata and past it to the $cc_email
variable?