因此,对于我商店中的每种产品,在购买该产品时,我都希望收到一封额外的通知电子邮件,其中包括主题中的订单ID,以及每个产品唯一的电子邮件地址。我在这里找到了一些解决方案,但是看起来我只能在网站上将其用于一种产品。
我已经尝试过此问题Email notification to a particular address if a specific product is purchased in Woocommerce的2个代码
但是问题是我不能为多个产品复制它。
感谢您的帮助。
答案 0 :(得分:0)
您必须更改代码,以便检查多个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_ids = array(37, 32, 30); // 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 ( in_array($item->get_variation_id(), $targeted_ids) || in_array($item->get_product_id(), $targeted_ids) ) {
$recipient .= ', ' . $addr_email;
break; // Found and added - We stop the loop
}
}
return $recipient;
}