在WooCommerce中,我为电子邮件地址创建了一个自定义字段。现在,如果该字段中有值,我需要WooCommerce仅将完成的订单电子邮件发送到该自定义字段adres。
我想出了如何将完成的订单电子邮件发送为自定义电子邮件地址的密件抄送,但现在我正尝试将电子邮件发送到不包含标准电子邮件地址的自定义字段电子邮件地址。
自定义字段电子邮件作为密件抄送(工作代码):
// *将发票发送到已完成订单的应付帐款* //
add_filter( 'woocommerce_email_headers',
'wcmos_email_cc_alternative', 10, 3);
function wcmos_email_cc_alternative( $recipient, $email_id, $order )
{
if ($email_id == 'customer_completed_order') {
$alternative_email = $order->get_meta( 'purchase_order_email',
true );
if ( $alternative_email ) {
$recipient = '$alternative_email';
}
}
return $recipient;
}
自定义字段电子邮件作为主要收件人(失败代码):
add_filter( 'woocommerce_email_recipient_customer_completed_order',
'wcmos_email_cc_alternative', 10, 3);
function wcmos_email_cc_alternative( $recipient, $email_id, $item_id
) {
if ($email_id == 'customer_completed_order') {
$alternative_email = $order->get_meta( 'purchase_order_email',
true );
$po_email = wc_get_order_item_meta( $item_id,
'purchase_order_email - '.$enroll_num, true );
if ( $alternative_email ) {
$recipient = ', $po_email';
}
}
return $recipient;
}
答案 0 :(得分:3)
woocommerce_email_recipient_customer_completed_order过滤器采用两个参数:$ recipients和$ order
似乎是您想要的:
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'wcmos_email_cc_alternative', 10, 2);
function wcmos_email_cc_alternative( $recipient, $order) {
$alternative_email = $order->get_meta('purchase_order_email',true);
if ($alternative_email != '') {
$recipient = $alternative_email;
}
return $recipient;
}