0

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;
}

1 Answers1

0

If you want to change the reply-to email address of the customer order email, you can try this code:

#-- Change Reply-to Email Address from Admin to Vendor --#
function change_reply_to_email_address( $header, $email_id, $order ) {

    if( $email_id =='customer_processing_order' ){       

        $vendor_id = dokan_get_seller_id_by_order( $order->get_id() );
        $vendor    = dokan()->vendor->get( $vendor_id );

        // HERE below set the name and the email address
        $reply_to_name  = $vendor->get_shop_name();
        $reply_to_email = $vendor->get_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: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";

    }
    return $header;
}

add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 3 );
Elikill58
  • 4,050
  • 24
  • 23
  • 45
  • Hi Tanjir, thanks so much for the rely, I tried this but unfortunately it has now worked. When I reply to order emails they are still going to admin. Thanks – Craig Andrew Jan 12 '22 at 10:44