英文:
How to remove vendor from Customer booking cancelled email
问题
我正在使用WooCommerce Bookings。我已经自定义了customer-bookings-cancelled模板,当客户取消预订时它可以正常工作,但它会向供应商和客户发送电子邮件通知。我需要从通知中删除供应商,但找不到任何如何操作的说明。是否有任何类或钩子可以用来从通知中去除供应商。
// Hook into the 'woocommerce_email_recipient_customer_booking_cancelled' filter
add_filter('woocommerce_email_recipient_customer_booking_cancelled', 'custom_exclude_vendor_from_customer_email', 10, 2);
function custom_exclude_vendor_from_customer_email($recipient, $booking) {
// 获取客户电子邮件
$customer_email = $booking->get_customer_email();
// 获取供应商电子邮件(们) - 用您的供应商的适当用户角色替换'role'
$vendor_emails = array();
$vendors = get_users(array('role' => 'vendor'));
foreach ($vendors as $vendor) {
$vendor_emails[] = $vendor->user_email;
}
// 从收件人列表中删除供应商电子邮件
$recipient_emails = array_diff(array($customer_email), $vendor_emails);
// 返回经过过滤的收件人列表(仅包括客户电子邮件)
return $recipient_emails;
}
任何方向将不胜感激。
英文:
I am using WooCommerce Bookings. I've customized the customer-bookings-cancelled template and it works when a customer cancels a booking, but it is sending an email notification to both vendor and customer. I need to remove the vendor from this notification but cannot find any instruction on how to do this. Are there any classes or hooks I can use to strip the vendor from the notification.
// Hook into the 'woocommerce_email_recipient_customer_booking_cancelled' filter
add_filter( 'woocommerce_email_recipient_customer_booking_cancelled', 'custom_exclude_vendor_from_customer_email', 10, 2 );
function custom_exclude_vendor_from_customer_email( $recipient, $booking ) {
// Get the customer email
$customer_email = $booking->get_customer_email();
// Get the vendor email(s) - Replace 'vendor' with the appropriate user role for your vendors
$vendor_emails = array();
$vendors = get_users( array( 'role' => 'vendor' ) );
foreach ( $vendors as $vendor ) {
$vendor_emails[] = $vendor->user_email;
}
// Remove vendor emails from the recipient list
$recipient_emails = array_diff( array( $customer_email ), $vendor_emails );
// Return the filtered recipient list (customer email only)
return $recipient_emails;
}
Any direction here would be greatly appreciated.
答案1
得分: 0
/**
* 从取消邮件通知头部中移除供应商信息。
*/
function remove_vendor_from_cancellation_email_headers( $headers, $booking_id, $booking ) {
// 从“收件人”头部中移除供应商邮件。
$to = isset( $headers['To'] ) ? $headers['To'] : '';
if ( $to ) {
$to = explode( ',', $to );
$to = array_diff( $to, array( 'vendor' ) ); // 用实际的供应商邮件地址替换 'vendor'
$headers['To'] = implode( ',', $to );
}
// 返回更新后的头部信息。
return $headers;
}
add_filter( 'woocommerce_email_headers', 'remove_vendor_from_cancellation_email_headers', 10, 3 );
英文:
You can use the other method ;
/**
* Remove vendor from cancellation email notification headers.
*/
function remove_vendor_from_cancellation_email_headers( $headers, $booking_id, $booking ) {
// Remove the vendor email from the "To" headers.
$to = isset( $headers['To'] ) ? $headers['To'] : '';
if ( $to ) {
$to = explode( ',', $to );
$to = array_diff( $to, array( 'vendor' ) ); // Replace 'vendor' with the actual vendor email
$headers['To'] = implode( ',', $to );
}
// Return the updated headers.
return $headers;
}
add_filter( 'woocommerce_email_headers', 'remove_vendor_from_cancellation_email_headers', 10, 3 );
答案2
得分: 0
在我们的模型上,我们确定供应商配置文件始终是第二个接收者,因此最好使用简单的数组选项:
function remove_vendor_from_cancellation_email( $recipients ) {
$recipientsArr = explode(',', $recipients);
$recipient = $recipientsArr[0];
return $recipient;
}
add_filter( 'woocommerce_email_recipient_booking_cancelled', 'remove_vendor_from_cancellation_email');
注意:这是给定的代码的翻译部分。
英文:
On our model, we determined that the vendor profile would always be the second recipient and therefore a simple array option worked the best:
function remove_vendor_from_cancellation_email( $recipients ) {
$recipientsArr = explode(',', $recipients);
$recipient = $recipientsArr[0];
return $recipient;
}
add_filter( 'woocommerce_email_recipient_booking_cancelled', 'remove_vendor_from_cancellation_email');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论