We use dokan multivendor and we want that when customers reply to an order email they go to the vendor.
Below is some code we used, but it stops some emails sending, stops some ve does receiving stripe connect payment and stope announcement emails sending. Any help is greatly appreciate it!
* Change WooCommerce Order Emails `Reply-to`
*/
/**
* Change WooCommerce Order Emails `Reply-to`
*/
add_filter( 'woocommerce_email_headers', 'cbs_change_reply_to_email_address', 10, 3 );
function cbs_change_reply_to_email_address( $header, $email_id, $order) {
$order_status = $order->get_status();
if ($order_status == 'processing' || $order_status == 'completed') {
$WC_Product_Factory = new WC_Product_Factory();
$reply_to_name = [];
$reply_to_email = [];
foreach($order->get_items() as $key => $item) {
$product = $WC_Product_Factory->get_product($item->get_product_id());
$author = $product->post->post_author;
$vendor = get_user_by('id', $author);
$vendor_obj = dokan()->vendor->get($vendor);
if ($vendor_obj) {
$reply_to_name[] = $vendor_obj->data->data->display_name . ' ';
$reply_to_email[] = $vendor_obj->data->data->user_email . ' ';
}
if (!empty($reply_to_name) && !empty($reply_to_email)) {
// Get the WC_Email instance Object
$email = new WC_Email($email_id);
$header = "Content-Type: " . $email->get_content_type() . "\r\n";
$header .= 'Reply-to: ' . implode(', ', $reply_to_name) . ' <' . implode(', ', $reply_to_email) . ">\r\n";
}
return $header;
}
}
return $header;
}