0

I added a confirmation form to complete the order on Woocommerce. one of the fields is the supervisor email of the user. I was looking around how to get this meta data and insert in into the header as CC. I look here and here but I for sure did a mistake.

function techie_custom_wooemail_headers( $headers, $id, $object) {
    // The order ID | Compatibility with WC version +3
    $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
    $email = get_post_meta( $order_id, '_contact_name', true );
    $headers .= 'Cc: ' . $email . "\r\n";

    return $headers;
}
add_filter( 'woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 3);

1 Answers1

0

I found a way:

function techie_custom_wooemail_headers( $headers, $id, $order) {
    $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
    $email = get_field("delivery_email", $order->id);
    $headers .= 'Cc: ' . $email . " ";

    return $headers;
}

add_filter( 'woocommerce_email_headers', 'techie_custom_wooemail_headers', 10, 3);