首页 文章

在Woocommerce中下订单后,为管理员电子邮件通知添加附件

提问于
浏览
1

我正在尝试在下订单后向商店管理员发送pdf文件 . 'woocommerce_email_attachments'钩子的问题是电子邮件被发送给客户和管理员 .

`add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3);`

`function attach_order_notice ($attachments, $id, $object) 
{
    $pdf_path = get_template_directory() . '/notice.pdf';
    $attachments[] = $pdf_path;
    return $attachments;
}`

目前,客户和管理员都收到新的订单电子邮件(包括附件),我希望客户和管理员都收到新的订单电子邮件,但只向管理员发送附件 .

这甚至可能吗?

1 回答

  • 1

    $idWC_Email ,可用于定位特定电子邮件通知,例如"New order",在成功下达订单后发送给管理员,这样:

    add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
    function attach_order_notice ( $attachments, $email_id, $order ) 
    {
        // Only for "New Order" email notification (for admin)
        if( $email_id == 'new_order' ){
            $attachments[] = get_template_directory() . '/notice.pdf';
        }
        return $attachments;
    }
    

    代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .

    经过测试和工作

相关问题