【问题标题】:Add an attachment to admin email-notification once order is placed in Woocommerce在 Woocommerce 中下订单后,将附件添加到管理员电子邮件通知
【发布时间】:2018-05-26 08:10:27
【问题描述】:

下新订单后,我正在尝试将 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;
}

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

这可能吗?

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce email-notifications


    【解决方案1】:

    $idWC_Email ID,您可以使用它来定位特定的电子邮件通知,例如在成功下订单后发送给管理员的“新订单”,这样:

    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 文件或任何插件文件中。

    测试和工作

    【讨论】:

    • 太棒了!按预期工作。非常感谢!
    • 如果您在子主题中使用它,请使用get_stylesheet_directory() 获取您的子主题目录的路径
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多