【问题标题】:Add an email attachment to WooCommerce notifications when order status is on-hold当订单状态为保留时,向 WooCommerce 通知添加电子邮件附件
【发布时间】:2017-08-07 16:06:16
【问题描述】:

在 woocommerce 中,我使用以下代码将 PDF 文件添加为电子邮件附件:

add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);

function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
    $your_pdf_path1 = get_stylesheet_directory() . '/pdf/ano1.pdf';
    $your_pdf_path2 = get_stylesheet_directory() . '/pdf/ano2.pdf';
    $attachments[] = $your_pdf_path1;
    $attachments[] = $your_pdf_path2;
    return $attachments;
}

我的问题是附件总是发送给客户的所有电子邮件。我只想在订单状态为“保留”的情况下发送电子邮件附件。

如何才能知道我的订单状态并仅针对这种情况发送电子邮件附件?

【问题讨论】:

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


    【解决方案1】:

    更新

    您需要在函数中使用 $id 参数和“customer_on_hold_order”作为电子邮件 ID 作为条件……

    add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
    
    function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
    
    // Continue if it's customer_on_hold email notiication
    if ( $id != 'customer_on_hold_order' ) return $attachments;
    
        $your_pdf_path1 = get_stylesheet_directory() . '/pdf/ano1.pdf';
        $your_pdf_path2 = get_stylesheet_directory() . '/pdf/ano2.pdf';
        $attachments[] = $your_pdf_path1;
        $attachments[] = $your_pdf_path2;
        return $attachments;
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

    经过测试并且可以工作

    【讨论】:

    • 嗯,您的配置我无法订购我的产品。当我点击“订购”按钮时,我只看到红色矩形,里面什么都没有。我完全使用了您的代码并将其复制到 function.php。如果我使用我发送的代码,它可以工作,但不是我想要的。
    • @RichardJacko 对不起,我犯了一个小错误……我已经更新了代码。试一试,现在应该可以正常工作了。
    • 它现在工作正常 :) 非常感谢您的帮助。你的代码很完美!!!
    • 今天发现添加附件只是为了通过银行付款,但是如果用户选择货到付款,附件是不会添加的。请问您能帮忙添加代码吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 2021-02-12
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多