在订单状态暂停时,向WooCommerce通知添加电子邮件附件

时间:2017-08-07 16:06:16

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

在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;
}

我的问题是附件总是向所有客户发送电子邮件。我想仅在订单状态为“暂停”的情况下发送电子邮件附件。

如何知道我的订单状态并仅针对此案例发送电子邮件附件?

1 个答案:

答案 0 :(得分: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文件中,或者放在任何插件文件中。

经过测试和工作