禁用具有自定义状态的订单的 WooCommerce 订单电子邮件通知 [英] Disable WooCommerce order email notification for orders with custom status

查看:31
本文介绍了禁用具有自定义状态的订单的 WooCommerce 订单电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索并查看了 WooCommerce 文档禁用确认电子邮件"的解决方案当他们在 WooCoomerce 中下订单时发送给客户.

I have searched the web and checked the WooCommerce docs for a solution to disable the "confirmation email" that is sent to the customer when they place an order in WooCoomerce.

我也想禁用新订单"发送给管理员的邮件.

I also want to disable the "new order" mail that goes to the admin.

但仅当订单具有自定义状态mystatus"时,根据客户的订购情况,某些订单会获得该状态.

But only if the order has a custom status "mystatus", which some orders are getting based on what the customers are ordering.

尝试像这样添加它,但它不起作用:

Tried adding it like this, but it did not work:

remove_action('woocommerce_order_status_mystatus_notification', array($email_class->emails['WC_Email_New_Order'], 'trigger'));?>

有什么建议吗?

这是我更改特定订单的订单状态的方法:

This is how I change the order status for specific orders:

add_action( 'woocommerce_thankyou','woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;

$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();

if( ($order->get_status() == 'processing'  || $order->get_status() == 'pending' || $order->get_status() == 'on-hold' ) && dokan_is_user_seller( $user_id ) && is_user_logged_in()) {
    $order->update_status( 'mystatus' );
  }
}

推荐答案

实际上无需对 WooCommerce 设置进行任何更改.

No real need to make any changes to WooCommerce settings.

不会针对自定义订单状态发送电子邮件通知,除非您有效提供此信息.

No email-notifications will be sent for a custom order status, unless you effectively provide this.

但是,会发送默认的电子邮件通知,因为 woocommerce_thankyou 钩子是在发送电子邮件通知后执行的.

However, the default email-notifications are sent, because the woocommerce_thankyou hook is executed after the email-notifications have been sent.

因此使用woocommerce_thankyou对面的woocommerce_checkout_order_created钩子(即在发送电子邮件通知之前执行)来更改订单状态,并且不会发送电子邮件无论如何.

So use the woocommerce_checkout_order_created hook (that is executed, before the e-mail notifications are sent) opposite woocommerce_thankyou to change the order status, and no emails will be sent anyway.

function action_woocommerce_checkout_order_created( $order ) {
    // Get user ID
    $user_id = $order->get_user_id();
    
    // Compare
    if ( ( $order->get_status() == 'processing'  || $order->get_status() == 'pending' || $order->get_status() == 'on-hold' ) && dokan_is_user_seller( $user_id ) && is_user_logged_in() ) {
        // Update status
        $order->update_status( 'mystatus' );
    }
}
add_action( 'woocommerce_checkout_order_created', 'action_woocommerce_checkout_order_created', 10, 1 );


注意:如果您想在任何其他情况下禁用电子邮件,您可以使用 woocommerce_email_recipient_{$email_id} 过滤器复合挂钩并设置正确的电子邮件 ID,您可以选择禁用电子邮件通知.


Note: If you want to disable emails in any other case, you can use the woocommerce_email_recipient_{$email_id} filter composite hook and with the right email ID set, you have the option to disable email notifications.

例如:

// Admin - new order email notification
// Customer - on hold
// Customer - processing
// Customer - pending
function filter_woocommerce_email_recipient( $recipient, $order, $email ) { 
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) return $recipient;
    
    // Has order status
    if ( $order->has_status( 'your-order-status' ) ) {
        $recipient = '';
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'filter_woocommerce_email_recipient', 10, 3 );
add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'filter_woocommerce_email_recipient', 10, 3 );
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'filter_woocommerce_email_recipient', 10, 3 );
add_filter( 'woocommerce_email_recipient_customer_pending_order', 'filter_woocommerce_email_recipient', 10, 3 );

这篇关于禁用具有自定义状态的订单的 WooCommerce 订单电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆