在另一个线程上找到此代码,但无法使其工作。PDF 上传到 wp-content/child-theme/。
目标是将 pdf 附加到 woocommerce 将发送的已完成订单电子邮件中。
不确定是否customer_completed_order正确?
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3 );
function attach_terms_conditions_pdf_to_email ( $attachments , $email_id, $email_object ) {
// Avoiding errors and problems
if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) ) {
return $attachments;
}
if( $email_id === 'customer_completed_order' ){
$your_pdf_path = get_stylesheet_directory() . '/Q-0319B.pdf';
$attachments[] = $your_pdf_path;
}
return $attachments;
}
Run Code Online (Sandbox Code Playgroud)