【问题标题】:Send additional email in WooCommerce in a processing status order (functions.php)在处理状态订单中在 WooCommerce 中发送其他电子邮件 (functions.php)
【发布时间】:2021-04-12 09:09:57
【问题描述】:

结帐后我需要发送这两封电子邮件。

1.- Woocommerce 自动电子邮件(汇总订单、王子、总价等)。

2.- 包含附加信息的电子邮件。

我一直在寻找,但我无法从 WooCommerce 插件中完成,也无法使用 Shopmagic 等其他插件,所以......它必须与代码一起使用。

经过大量时间搜索,我认为可能是这样的。

(状态控制的顺序是processing而不是completed,因为我在Stripe和Stripe中使用test-mode进行测试,在测试模式下,订单被定义为“处理”状态,而不是completed

从现在开始,我的functions.php 文件中的内容是这样的:

$order = new WC_Order( $order_id );

function order_processing( $order_id ) {
    $order = new WC_Order( $order_id );
    $to_email = $order["billing_address"];
    $headers = 'From: Your Name <alexiglesiasvortex@gmail.com>' . "\r\n";
    wp_mail($to_email, 'subject', '<h1>This is a test for my new pending email.</h1><p>Agree, this is a test</p>', $headers );
}

add_action( 'woocommerce_payment_processing', 'order_processing' );

目前,这不起作用...我没有收到任何错误并且结帐正确结束,但没有新电子邮件到达我的收件箱。

我需要一些帮助,伙计们,有人可以帮助我吗?非常感谢,祝您周一愉快!

【问题讨论】:

  • 我建议您通过写入日志文件进行调试。另外,您可以访问电子邮件服务器的日志文件吗? (我的猜测是,邮件被邮件服务器拒绝了。)
  • 省略 wp_mail() 中的 $headers 并重试。它现在有效吗?检查这个:stackoverflow.com/questions/31322039/…

标签: php wordpress woocommerce phpmailer


【解决方案1】:

我在 WooCommerce 文档中找不到任何 woocommerce_payment_processing 挂钩。请改用woocommerce_order_status_changed

此外,您也错误地访问了帐单电子邮件。 $order 是一个对象,您无法像数组一样获取帐单电子邮件。您可以使用 WC_Order 类的get_billing_email 方法。

// send a custom email when the order status changes to "processing"
add_action( 'woocommerce_order_status_changed', 'send_custom_email_order_processing', 10, 4 );
function send_custom_email_order_processing( $order_id, $from_status, $to_status, $order ) {

    // only if the new order status is "processing"
    if ( $to_status == 'processing' ) {
        $to_email = $order->get_billing_email();
        $headers = 'From: Your Name <alexiglesiasvortex@gmail.com>' . "\r\n";
        wp_mail( $to_email, 'subject', '<h1>This is a test for my new pending email.</h1><p>Agree, this is a test</p>', $headers );
    }

}

代码已经过测试并且可以运行。将其添加到活动主题的 functions.php 中。

【讨论】:

    猜你喜欢
    • 2016-10-26
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    相关资源
    最近更新 更多