John Davidson

php - Chabge reply-to email address to the vendors in dokan

0 comments
Message:


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


My Answer:
>status; // Get the order status

// Check if the email is an order email
if (strpos($email_id, 'customer_') !== false) {
// Get the vendor ID from the order
$vendor_id = get_post_meta($order->get_id(), '_vendor_id', true);

// Get the vendor email address
$vendor_email = get_user_meta($vendor_id, 'user_email', true);

// Change the reply-to email address to the vendor email address
$header .= "Reply-To: $vendor_email\r\n";
}

return $header;
}

This code snippet should change the reply-to email address in WooCommerce order emails to the vendor's email address. Make sure to replace '_vendor_id' with the correct meta key for the vendor ID in your Dokan Multivendor setup. Also, ensure that the vendor ID is correctly retrieved from the order and that the vendor email address is fetched correctly. This should help resolve the issue with some emails not sending and other functionality being affected.

Rate this post

3 of 5 based on 7673 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us