如果在Woocommerce中购买了特定产品,则通过电子邮件将通知发送到特定地址 [英] Email notification to a particular address if a specific product is purchased in Woocommerce

查看:114
本文介绍了如果在Woocommerce中购买了特定产品,则通过电子邮件将通知发送到特定地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the woocommerce plugin in my Wordpress website. I am wondering how can I send an email notification to a specific address email if product A is purchased by customer.

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

How to send an email notification to a specific address when a specific product is purchased in Woocommerce?

推荐答案

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

The code below will add a custom defined email recipient to New Email Notification When a specific defined product Id is found in order items:

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  = 'name@domain.com'; // 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文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于如果在Woocommerce中购买了特定产品,则通过电子邮件将通知发送到特定地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆