WooCommerce 如何将自定义发票附加到电子邮件
WooCommerce how to attach custom invoice to Email
在一些帮助下,我设法创建了一个插件,用于在完成的订单电子邮件中附加发票。
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_completed_order' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
$attachments[] = $pdf_path;
}
return $attachments;
}
此代码用于检查“email_fatura”(翻译为“email_invoice”)的订单元,并获取此字段的值。此值采用路径根 /Faturas/GestaoDespesas/ORDER123.pdf
并将 pdf
附加到电子邮件。
但是,问题是当没有字段“email_fatura”时,它仍然会附加一个名为“GestaoDespesas”的文件,该文件来自 /Faturas/**GestaoDespesas**/
对于知道的人 PHP 我认为很容易解决这个问题。
提前感谢您的帮助。
我会先检查该字段是否为空,如果是则只是 return:
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_completed_order' );
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
if ( empty($pdf_name) ){
return;
}
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
$attachments[] = $pdf_path;
}
return $attachments;
}
在一些帮助下,我设法创建了一个插件,用于在完成的订单电子邮件中附加发票。
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_completed_order' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
$attachments[] = $pdf_path;
}
return $attachments;
}
此代码用于检查“email_fatura”(翻译为“email_invoice”)的订单元,并获取此字段的值。此值采用路径根 /Faturas/GestaoDespesas/ORDER123.pdf
并将 pdf
附加到电子邮件。
但是,问题是当没有字段“email_fatura”时,它仍然会附加一个名为“GestaoDespesas”的文件,该文件来自 /Faturas/**GestaoDespesas**/
对于知道的人 PHP 我认为很容易解决这个问题。
提前感谢您的帮助。
我会先检查该字段是否为空,如果是则只是 return:
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_completed_order' );
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
if ( empty($pdf_name) ){
return;
}
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$pdf_name = get_post_meta( get_the_id(), 'email_fatura', true );
$pdf_path = get_home_path() . '/Faturas/GestaoDespesas/' . $pdf_name;
$attachments[] = $pdf_path;
}
return $attachments;
}