1

在woocommerce我使用下面的代码添加PDF文件作为电子邮件附件:电子邮件附件添加到WooCommerce通知时订单状态是处于保持

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

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

怎么可能知道我的订单的状态和发送电子邮件附件只为这种情况下?

回答

0

更新

您需要使用$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文件主题(或主题)或任何插件文件。

经测试和工程

+0

嗯,您的配置我无法订购我的产品。当我点击“订单”按钮时,我看到只有红色的矩形,里面没有东西。我精确地使用了你的代码并将它复制到了function.php中。如果我使用我发送的代码,它正在工作,但不是我想要的。 –

+0

@RichardJacko对不起,我犯了一个小错误...我已经更新了代码。尝试一下,现在它应该按预期工作。 – LoicTheAztec

+0

它现在工作正常:)真的非常感谢您的帮助。你的代码是完美的! –

相关问题