向管理员发送电子邮件通知,以了解WooCommerce中的待处理订单状态 [英] Send an Email notification to the admin for pending order status in WooCommerce

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

问题描述

在WooCommerce中,当客户从购物车中结帐并提交订单时,如果未处理付款,则该订单将设置为待处理"付款.管理员未收到任何有关的电子邮件.

In WooCommerce, when a customer goes to checkout from cart and submit the order, if the payment is not processed, the order is set to "pending" payment. The Admin doesn't received any email about.

我想向Admin发送此类订单的电子邮件.我该怎么办?

I would like to send an email to Admin for this kind of orders. How can I do it?

推荐答案

更新2 (感谢CélineGarel将woocommerce_new_order更改为woocommerce_checkout_order_processed)

UPDATE 2 (Change from woocommerce_new_order to woocommerce_checkout_order_processed thanks to Céline Garel)

当新订单获得待处理状态时,将在所有可能的情况下触发此代码,并将自动触发新订单"电子邮件通知:

This code will be fired in all possible cases when a new order get a pending status and will trigger automatically a "New Order" email notification:

// New order notification only for "Pending" Order status
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 );
}

代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

此代码已经过测试,可在WooCommerce 2.6.x和3+版本中使用.

This code is tested and works in WooCommerce versions 2.6.x and 3+.

更具自定义性的代码版本(如果需要),这将使待处理订单更加可见:

A more customizable version of the code (if needed), that will make pending Orders more visible:

// New order notification only for "Pending" Order status
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;

    // Get an instance of the WC_Email_New_Order object
    $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order'];

    ## -- Customizing Heading, subject (and optionally add recipients)  -- ##
    // Change Subject
    $wc_email->settings['subject'] = __('{site_title} - New customer Pending order ({order_number}) - {order_date}');
    // Change Heading
    $wc_email->settings['heading'] = __('New customer Pending Order'); 
    // $wc_email->settings['recipient'] .= ',name@email.com'; // Add email recipients (coma separated)

    // Send "New Email" notification (to admin)
    $wc_email->trigger( $order_id );
}

代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

此代码已经过测试,可在WooCommerce 2.6.x和3+版本中使用.

This code is tested and works in WooCommerce versions 2.6.x and 3+.

在此版本中,您可以自定义电子邮件标题,主题,添加收件人...

In this version you can customize the email heading, subject, add recipients...

这篇关于向管理员发送电子邮件通知,以了解WooCommerce中的待处理订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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