简体   繁体   English

自定义 PHP 剪辑器,用于向管理员发送电子邮件通知,以了解 WooCommerce 中的待处理订单状态,导致已处理订单的电子邮件重复

[英]Custom PHP snipper for email notification to the admin for pending order status in WooCommerce causing duplicated emails for processed orders

One of the payment methods we use on the site sets new orders to "Pending" mode which by default have no email notifications.我们在网站上使用的一种付款方式将新订单设置为“待处理”模式,默认情况下没有电子邮件通知。 I've found the following snippet and added it to my child's theme functions.php file.我找到了以下代码片段并将其添加到我孩子的主题 functions.php 文件中。

It does send a single email notifications for pending orders correctly, but it also causes double emails to be sent for other orders using other payment methods even though their status is "processing".它确实为挂单正确发送了一封电子邮件通知,但它也会导致使用其他付款方式的其他订单发送双封电子邮件,即使它们的状态为“正在处理”。 How would you suggest to fix it?你会建议如何修复它? Thank you for your time & help.感谢您的时间和帮助。

// New order notification for Pending Orders
add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
function pending_new_order_notification( $order_id ) {

    // Get an instance of the WC_Order object
    $order = wc_get_order( $order_id );

    // Only for "pending" order status
    if( ! $order->has_status( 'pending' ) ) return;

    // Send "New Email" notification (to admin)
    WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger( $order_id );
}

The problem is your use of the hook woocommerce_checkout_order_processed .问题是您使用了钩子woocommerce_checkout_order_processed Instead, try woocommerce_order_status_pending .相反,请尝试woocommerce_order_status_pending I believe the rest of your code should be fine.我相信您的其余代码应该没问题。 Basic use of this as well as some other useful hooks can be found here .可以在这里找到它的基本用法以及其他一些有用的钩子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向管理员发送电子邮件通知以了解 WooCommerce 中的待定订单状态 - Send an Email notification to the admin for pending order status in WooCommerce "为具有自定义状态的订单禁用 WooCommerce 订单电子邮件通知" - Disable WooCommerce order email notification for orders with custom status 在Woocommerce中将订单交易ID添加到管理员新订单电子邮件通知中 - Add orders transaction id to admin new order email notification in Woocommerce Woocommerce 向管理员发送“暂停”订单的新订单电子邮件通知 - Woocommerce new order email notification to admin for "On Hold" orders 停止 WooCommerce 管理员 email 通知免费订单 - Stop WooCommerce admin email notification for free orders WooCommerce 向管理员发送 email 通知以获取特定订单状态 - WooCommerce send email notification to admin for specific order status 自定义标题和主题 email 通知 WooCommerce 中的自定义订单状态 4 - Custom heading and subject email notification for custom order status in WooCommerce 4 向管理员和客户发送电子邮件通知待处理订单 - Email notification to the admin and customer for pending order 仅针对具有处理状态的已付款订单发送 WooCommerce 新订单 email 通知 - Send WooCommerce New Order email notification only for paid orders with processing status 在 Woocommerce 管理订单列表中显示具有“全部”自定义状态的订单 - Display orders with a custom status for “all” in Woocommerce admin orders list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM