如何从客户预订取消邮件中移除供应商

huangapple go评论89阅读模式
英文:

How to remove vendor from Customer booking cancelled email

问题

我正在使用WooCommerce Bookings。我已经自定义了customer-bookings-cancelled模板,当客户取消预订时它可以正常工作,但它会向供应商和客户发送电子邮件通知。我需要从通知中删除供应商,但找不到任何如何操作的说明。是否有任何类或钩子可以用来从通知中去除供应商。

  1. // Hook into the 'woocommerce_email_recipient_customer_booking_cancelled' filter
  2. add_filter('woocommerce_email_recipient_customer_booking_cancelled', 'custom_exclude_vendor_from_customer_email', 10, 2);
  3. function custom_exclude_vendor_from_customer_email($recipient, $booking) {
  4. // 获取客户电子邮件
  5. $customer_email = $booking->get_customer_email();
  6. // 获取供应商电子邮件(们) - 用您的供应商的适当用户角色替换'role'
  7. $vendor_emails = array();
  8. $vendors = get_users(array('role' => 'vendor'));
  9. foreach ($vendors as $vendor) {
  10. $vendor_emails[] = $vendor->user_email;
  11. }
  12. // 从收件人列表中删除供应商电子邮件
  13. $recipient_emails = array_diff(array($customer_email), $vendor_emails);
  14. // 返回经过过滤的收件人列表(仅包括客户电子邮件)
  15. return $recipient_emails;
  16. }

任何方向将不胜感激。

英文:

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.

  1. // Hook into the 'woocommerce_email_recipient_customer_booking_cancelled' filter
  2. add_filter( 'woocommerce_email_recipient_customer_booking_cancelled', 'custom_exclude_vendor_from_customer_email', 10, 2 );
  3. function custom_exclude_vendor_from_customer_email( $recipient, $booking ) {
  4. // Get the customer email
  5. $customer_email = $booking->get_customer_email();
  6. // Get the vendor email(s) - Replace 'vendor' with the appropriate user role for your vendors
  7. $vendor_emails = array();
  8. $vendors = get_users( array( 'role' => 'vendor' ) );
  9. foreach ( $vendors as $vendor ) {
  10. $vendor_emails[] = $vendor->user_email;
  11. }
  12. // Remove vendor emails from the recipient list
  13. $recipient_emails = array_diff( array( $customer_email ), $vendor_emails );
  14. // Return the filtered recipient list (customer email only)
  15. return $recipient_emails;
  16. }

Any direction here would be greatly appreciated.

答案1

得分: 0

  1. /**
  2. * 从取消邮件通知头部中移除供应商信息。
  3. */
  4. function remove_vendor_from_cancellation_email_headers( $headers, $booking_id, $booking ) {
  5. // 从“收件人”头部中移除供应商邮件。
  6. $to = isset( $headers['To'] ) ? $headers['To'] : '';
  7. if ( $to ) {
  8. $to = explode( ',', $to );
  9. $to = array_diff( $to, array( 'vendor' ) ); // 用实际的供应商邮件地址替换 'vendor'
  10. $headers['To'] = implode( ',', $to );
  11. }
  12. // 返回更新后的头部信息。
  13. return $headers;
  14. }
  15. add_filter( 'woocommerce_email_headers', 'remove_vendor_from_cancellation_email_headers', 10, 3 );
英文:

You can use the other method ;

  1. /**
  2. * Remove vendor from cancellation email notification headers.
  3. */
  4. function remove_vendor_from_cancellation_email_headers( $headers, $booking_id, $booking ) {
  5. // Remove the vendor email from the "To" headers.
  6. $to = isset( $headers['To'] ) ? $headers['To'] : '';
  7. if ( $to ) {
  8. $to = explode( ',', $to );
  9. $to = array_diff( $to, array( 'vendor' ) ); // Replace 'vendor' with the actual vendor email
  10. $headers['To'] = implode( ',', $to );
  11. }
  12. // Return the updated headers.
  13. return $headers;
  14. }
  15. add_filter( 'woocommerce_email_headers', 'remove_vendor_from_cancellation_email_headers', 10, 3 );

答案2

得分: 0

在我们的模型上,我们确定供应商配置文件始终是第二个接收者,因此最好使用简单的数组选项:

  1. function remove_vendor_from_cancellation_email( $recipients ) {
  2. $recipientsArr = explode(',', $recipients);
  3. $recipient = $recipientsArr[0];
  4. return $recipient;
  5. }
  6. 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:

  1. function remove_vendor_from_cancellation_email( $recipients ) {
  2. $recipientsArr = explode(',', $recipients);
  3. $recipient = $recipientsArr[0];
  4. return $recipient;
  5. }
  6. add_filter( 'woocommerce_email_recipient_booking_cancelled', 'remove_vendor_from_cancellation_email');

huangapple
  • 本文由 发表于 2023年7月20日 16:53:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定