我想在Woocommerce的客户处理订单上添加PDF,我尝试了以下内容:
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;
}
我已将一个名为terms.pdf的PDF上传到我的子主题中,因此路径为 /wp-content/themes/child-theme/terms.pdf
,但无效 . 有人可以帮忙吗?
1 回答
您正在生成PDF的路径并将其分配给名为
$your_pdf_path
的变量,但随后将变量添加到名为$pdf_path
的$attachments
数组中 . 您可以在不使用临时变量的情况下简化此操作: