我想根据客户选择的产品变化属性添加不同的电子邮件收件人。我有以下代码,但目前无法正常工作。
function sv_conditional_email_recipient( $recipient, $order ) {
foreach ( $order->get_items() as $item_id => $item ) {
$variation = wc_get_product($item['variation_id']);
$variation_attributes = $variation->get_variation_attributes();
if($variation == "Branch" && $variation_attributes == "BT" ) $recipient .= 'bt@email.com';
elseif ($variation == "Branch" && $variation_attributes == "PW" ) $recipient .= 'pw@email.com';
elseif ($variation == "Branch" && $variation_attributes == "TP" ) $recipient .= 'tp@email.com';
return $recipient;
}
}
add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 15, 2 );
我很感激如果有人能帮助指出什么是问题,提前感谢你这么多!
1条答案
按热度按时间s5a0g9ez1#