0

I want to send a copy of the completed order, failed order and canceled order to a specific E-Mail address. This E-Mail address is stored in a custom field I created with the Advanced Custom Fields plugin.

The field name is "e-mail_adresse". As I am using a multisite network I cant enter the E-Mail Address manually and have to pull it from this field. Is this possible?

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Chris
  • 17
  • 3

1 Answers1

0
add_filter( 'woocommerce_email_headers', 'custom_cc_email_headers', 10, 3 );

function custom_cc_email_headers( $header, $email_id, $order ) {

    //Only for "Completed,cancelled, failed Order" email notification
    if ( 'customer_completed_order' !== $email_id || 'cancelled_order' !== $email_id || 'failed_order' !== $email_id )
        return $header;

    //Get the CC email
    $custom_user_email = get_user_meta( $order->get_user_id(), 'e-mail_adresse', true );

    if ( !empty( $custom_email ) )
        return $header; // Exit (if empty value)


//Get customer full name
    $user_name   = $order->get_billing_first_name() . ' ';
    $user_name   .= $order->get_billing_last_name();

    $formatted_email = utf8_decode( $user_name . ' <' . $custom_user_email . '>' );

    //Add Cc to headers
    $header .= 'Cc: ' . $formatted_email . '\r\n';

    return $header;
}

Try this code

mujuonly
  • 11,370
  • 5
  • 45
  • 75