[英]Attach pdf to only specific email notification in Woocommerce
安裝PDF 只 woocomerce新訂單電子郵件
我正在使用此代碼,但是woocommerce中的每封電子郵件都附帶了PDF
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 ) {
$your_pdf_path = get_template_directory() . '/terms123.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
更新2
Woocommerce中沒有針對客戶的“新訂單”通知 ...根據啟用的付款方式,要定位的通知可以是“客戶保留訂單”或/和“客戶處理訂單” (請參閱最后一節)
以下將為“客戶保留訂單”電子郵件通知啟用PDF附件:
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;
}
// Only for "Customer On Hold" email notification (for customer)
if( $email_id === 'customer_on_hold_order' ){
$your_pdf_path = get_template_directory() . '/terms123.pdf';
$attachments[] = $your_pdf_path;
}
return $attachments;
}
代碼進入您的活動子主題(活動主題)的function.php文件中。 經過測試和工作。
根據安裝中啟用的付款網關,您可以:
1) 您可以使用“正在處理”電子郵件代替此行:
if( $email_id === 'customer_on_hold_order' ){
這樣:
if( $email_id === 'customer_processing_order' ){
2) 您可以同時使用“保留”和“正在處理”客戶的電子郵件,替換此行:
if( $email_id === 'customer_on_hold_order' ){
這樣:
if( in_array( $email_id, array( 'customer_on_hold_order', 'customer_processing_order' ) ){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.