【问题标题】:Woocommerce new order additional email recipient added in order metaWoocommerce 新订单在订单元中添加了额外的电子邮件收件人
【发布时间】:2021-10-27 06:36:59
【问题描述】:

我正在尝试在客户订单确认电子邮件中添加其他收件人。

我已成功将额外收件人电子邮件地址的元值添加到订单中,并已连接到一些电子邮件,但是,我发现很难找到确认电子邮件的挂钩。

我的代码:

add_filter('woocommerce_email_recipient_customer_processing_order', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_completed_order', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_invoice', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_invoice_paid', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_note', 'ddl_additional_email_checkout', 10, 2);
function ddl_additional_email_checkout($emails, $object){
    
    $additional_email = get_post_meta($object->id, 'additional_recipient', true);
    
    if( $additional_email ){
        $emails .= ',' . $additional_email;
    }

    return $emails;

}

理想情况下,我会加入 woocommerce_email_recipient_customer_new_order 之类的东西,但这似乎不是一个选择。

非常感谢。

【问题讨论】:

  • 您可以根据 $email_id 设置过滤器挂钩:woocommerce_email_recipient_{$email_id},用于正确/可能的$email_id 视图stackoverflow.com/a/61459068/11987538stackoverflow.com/a/47742782/11987538。所以看起来您正在寻找new_order另见来自this answer的第二部分
  • $order->get_id()
  • 完美,第一条评论中的第一个链接让我走上了正轨。非常感谢 @7uc1f3r 和 Howard E 的帮助。

标签: wordpress woocommerce hook-woocommerce


【解决方案1】:

链接到https://stackoverflow.com/a/61459068/11987538 的第一条评论为我解决了这个问题,本质上它只是找到了正确的$email_id

这段代码也很有帮助,因为它会在电子邮件中显示 ID。

add_action( 'woocommerce_email_order_details', 'add_custom_text_to_new_order_email', 10, 4 );
function add_custom_text_to_new_order_email( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for "New Order"  email notifications (to be replaced by yours)
    if( ! ( 'new_order' == $email->id ) ) return;

    // Display a custom text (for example)
    echo '<p>'.__('My custom text').'</p>';
}

来自Targeting specific email with the email id in Woocommerce

【讨论】:

    猜你喜欢
    • 2017-05-02
    • 2022-01-19
    • 2019-12-27
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2019-02-23
    相关资源
    最近更新 更多