php - 向管理员发送电子邮件通知以了解 WooCommerce 中的待定订单状态

标签 php wordpress woocommerce orders email-notifications

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

我想向管理员发送此类订单的电子邮件。我该怎么做?

最佳答案

更新 2 (感谢 Céline Garel,从 woocommerce_new_order 更改为 woocommerce_checkout_order_processed)
/p>

当新订单进入待定状态时,在所有可能的情况下都会触发此代码,并会自动触发“新订单”电子邮件通知:

// 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 );
}

代码进入您的事件子主题(或主题)的 functions.php 文件或任何插件文件中。


一个更可定制的代码版本(如果需要),这将使挂起的订单更加可见:

// 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 );
}

代码进入您的事件子主题(或主题)的 functions.php 文件或任何插件文件中。

此版本允许自定义电子邮件标题、主题、添加收件人...

关于php - 向管理员发送电子邮件通知以了解 WooCommerce 中的待定订单状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45375143/

相关文章:

php - 将 Gravity Forms 中的字段连接到 WooCommerce 中的字段

php - 根据订单状态隐藏 WooCommerce 管理订单列表中的订单(表行)

php - 通过 wget/curl 进行长时间的 cron 作业?

javascript - 在 php 中完成流程后更改 JS/jQuery 中的按钮文本

php - Netbeans IDE 的自定义主题?

php - 从 WooCommerce 订单中获取优惠券数据

api - WooCommerce REST API 自定义字段

php - Mongodb展开嵌套文档

java - 使用 document.getElementsByClassName 更改不同类的样式

php - Doctrine 试图分配 4GB?