我在我的Wordpress网站上使用woocommerce插件。我想知道如果客户购买了产品,如何将电子邮件通知发送到特定的地址电子邮件。

在Woocommerce中购买特定产品时,如何将电子邮件通知发送到特定地址?

最佳答案

当在订单项中找到特定的已定义产品ID时,以下代码会将自定义的已定义电子邮件收件人添加到“新电子邮件通知”中:

add_filter( 'woocommerce_email_recipient_new_order', 'conditional_recipient_new_email_notification', 15, 2 );
function conditional_recipient_new_email_notification( $recipient, $order ) {
    if( is_admin() ) return $recipient; // (Mandatory to avoid backend errors)

    ## --- YOUR SETTINGS (below) --- ##

    $targeted_id = 37; // HERE define your targeted product ID
    $addr_email  = '[email protected]'; // Here the additional recipient

    // Loop through orders items
    foreach ($order->get_items() as $item_id => $item ) {
        if( $item->get_variation_id() == $targeted_id || $item->get_product_id() == $targeted_id ){
            $recipient .= ', ' . $addr_email;
            break; // Found and added - We stop the loop
        }
    }

    return $recipient;
}

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

关于wordpress - 如果在Woocommerce中购买了特定产品,则将电子邮件通知发送到特定地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51577659/

10-13 01:29