我正在使用
woocommerce_email_attachments
钩子,但出于某种原因,我需要仅为新订单的管理副本添加一些 PDF 附件。
我知道我只能针对新订单触发此挂钩,没关系。
但我不知道如何才能只针对某些特定收件人执行此操作。 有没有办法在这个钩子中做到这一点?
这基本上就是我所需要的:
add_filter( 'woocommerce_email_attachments', 'edit_woocommerce_attachments', 10, 3 );
function edit_woocommerce_attachments($attachments, $email_id, $email_object){
if( $email_id === 'new_order'){
if($email == '[email protected]') $attachments[] = get_attached_file( 612 );
else return;
}
return $attachments;
}
您可以这样做,检查电子邮件是否是发给客户的?
add_filter('woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 4);
function attach_terms_conditions_pdf_to_email($attachments, $id, $object, $email)
{
if (!$email->is_customer_email()) {
$terms_path = get_template_directory() . '/assets/pdfs/terms.pdf';
$attachments[] = $terms_path;
}
return $attachments;
}