附加PDF woocommerce电子邮件
问题描述:
我想附加一个PDF从Woocommerce客户处理顺序,我曾尝试以下:附加PDF woocommerce电子邮件
add_filter('woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ($attachments, $status , $order) {
$allowed_statuses = array('customer_processing_order');
if(isset($status) && in_array ($status, $allowed_statuses)) {
$your_pdf_path = get_template_directory() . '/terms.pdf';
$attachments[] = $pdf_path;
}
return $attachments;
}
,我已经上传了一个PDF叫terms.pdf到我的孩子主题所以路径是 /wp-content/themes/child-theme/terms.pdf
,但不起作用。谁能帮忙?
答
您正在生成PDF路径并将其分配给一个名为$your_pdf_path
的变量,但是您将一个变量添加到名为$pdf_path
的数组中。您可以简化此操作,而无需使用像这样的临时变量:
$attachments[] = get_stylesheet_directory() . '/terms.pdf';
模板目录将始终指向父主题。 OP建议一个儿童主题,所以我相信[get_stylesheet_directory()](https://codex.wordpress.org/Function_Reference/get_stylesheet_directory)是有序的。 – helgatheviking