【问题标题】:Send New Order email to an additional email based on payment type in Woocommerce根据 Woocommerce 中的付款类型将新订单电子邮件发送到其他电子邮件
【发布时间】:2019-01-22 04:57:38
【问题描述】:

首先让我说我还没有代码,并且对此进行了研究但没有发现任何东西。如果有人能指出我正确的方向,那就太好了。

基本上,我希望最好使用代码 functions.php 来检查 WooCommerce 订单的付款方式并将标准的新订单电子邮件发送到特定的电子邮件地址。可以对这个地址进行硬编码以使其更简单。

我想要实现的是,每次使用 Stripe 作为付款方式下订单时,标准的新订单电子邮件都会发送到这个额外的电子邮件地址,同时也会发送到 WoocCommerce 设置中的指定地址。如果使用任何其他付款方式,除了发送正常的新订单电子邮件外,不会发生任何事情。

如果有人能指出我正确的方向,我将非常感激,但请记住,无论如何我都不是超级程序员。

【问题讨论】:

    标签: php wordpress woocommerce payment-gateway email-notifications


    【解决方案1】:

    试试下面的代码,它将为条带支付网关的“新订单”电子邮件添加一个额外的收件人:

    add_filter( 'woocommerce_email_recipient_new_order', 'new_order_additional_recipients', 20, 2 );
    function new_order_additional_recipients( $recipient, $order ) {
        if ( ! is_a( $order, 'WC_Order' ) ) 
            return $recipient;
    
        // Set Below your additional email adresses in the arrayy
        $emails = array('name1@domain.com');
        $emails = implode(',', $emails);
    
        // Adding recipients conditionally
        if ( 'stripe' == $order->get_payment_method() )
            $recipient .= ',' . $emails;
    
        return $recipient;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

    • 非常感谢!
    • 对此发表评论,因为我无法让它工作。它应该是“内爆”而不是“爆炸”吗?因为现在代码正试图将数组分解为我认为的数组?
    • @SpacePilot 是的,抱歉,内爆:) ...如果您喜欢/想要,您甚至可以投票赞成这个答案。无论如何,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多