根据 Woocommerce 中的付款类型将新订单电子邮件发送到其他电子邮件

Send New Order email to an additional email based on payment type in Woocommerce

先声明一下,我还没有代码,研究过这个也没有找到任何东西。如果有人能指出我正确的方向,那就太好了。

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

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

如果有人能给我指出正确的方向,我将不胜感激,但请记住,我无论如何都不是超级编码员。

尝试使用以下代码将额外的收件人添加到 "New Order" 条带支付网关的电子邮件:

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 文件。已测试并有效。