【发布时间】:2019-04-14 15:09:35
【问题描述】:
为我建立 WP 网站的人现在被这个问题困扰了一段时间。他需要将一些自定义 PDF 文件附加到订单确认邮件中。他使用woocommerce_emails_attach_downloadables 函数来做到这一点。出于某种原因,在 $order 参数为空的情况下调用了该函数。
这是他使用的代码:
add_filter( 'woocommerce_email_attachments', 'attach_order_notice', 10, 3 );
function attach_order_notice ( $attachments, $email_id, $order )
{
//
// Only for "New Order" email notification (for admin)
if( $email_id == 'customer_on_hold_order' ){
$pdf_options = array(
// "source_type" => 'html',
// "source" => '<html>hello</html>',
"source_type" => 'url',
"source" => 'http://tt.dev.co.il/checkout/order-received/757/?key=wc_order_5bce0e5ba39b8',
"action" => 'save',
"save_directory" => get_template_directory() .'/pdfs',
"file_name" => 'print-pdf'. json_encode($order) .'.pdf');
// phptopdf($pdf_options);
$attachments[] = get_template_directory() . '/pdfs/print-pdf.pdf';
}
return $attachments;
}
所以我的问题是:
那些是什么情况?
什么会导致 $order 被传递为空?
【问题讨论】:
标签: php wordpress object woocommerce hook-woocommerce