Wordpress 如何在过滤器';woocommerce电子邮件附件&x27;
我想将发票以PDF格式附在WooCommerce邮件中。使用静态PDF(如条款和条件)非常有效,但我需要使用可变PDF文件(如发票)的选项 我使用这个过滤器:Wordpress 如何在过滤器';woocommerce电子邮件附件&x27;,wordpress,woocommerce,Wordpress,Woocommerce,我想将发票以PDF格式附在WooCommerce邮件中。使用静态PDF(如条款和条件)非常有效,但我需要使用可变PDF文件(如发票)的选项 我使用这个过滤器: add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3); 这个功能是: function attach_pdf_to_email ( $attachments, $status , $object ) { $pdf_path = ABSPAT
add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
这个功能是:
function attach_pdf_to_email ( $attachments, $status , $object ) {
$pdf_path = ABSPATH . "wp-content/uploads/terms.pdf";
$attachments[] = $pdf_path;
return $attachments;
}
工作完美。现在我想将$pdf\u路径更改为:
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
但我无法获得$order\u id
我试过:
global $order;
// First try
$order_id = $order->id;
// Second try
$order_id = $order->get_id();
// Third and fourth try (like above)
global $post;
问题是,过滤器既不发送订单,也不发送订单id。是否有任何方法或想法,我如何实现这一点?试试这段代码
add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
function attach_agb_to_email ( $attachments, $status , $order ) {
if ( empty( $order ) ) {
return $attachments;
}
$order_id = $order->id;
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
$attachments[] = $pdf_path;
return $attachments;
}
试试这个代码
add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
function attach_agb_to_email ( $attachments, $status , $order ) {
if ( empty( $order ) ) {
return $attachments;
}
$order_id = $order->id;
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
$attachments[] = $pdf_path;
return $attachments;
}
您可以从
$object
获取订单id。
尝试下面的代码,我已经尝试了你的代码,并编辑它,以获得订单id
function attach_pdf_to_email($attachments, $status, $object) {
$order_id = method_exists($object, 'get_id') ? $object->get_id() : $object->id;
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
// $pdf_path = ABSPATH . "wp-content/uploads/terms.pdf";
$attachments[] = $pdf_path;
return $attachments;
}
add_filter('woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
您可以从
$object
获取订单id。
尝试下面的代码,我已经尝试了你的代码,并编辑它,以获得订单id
function attach_pdf_to_email($attachments, $status, $object) {
$order_id = method_exists($object, 'get_id') ? $object->get_id() : $object->id;
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
// $pdf_path = ABSPATH . "wp-content/uploads/terms.pdf";
$attachments[] = $pdf_path;
return $attachments;
}
add_filter('woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
请尝试以下代码:
add_filter( 'woocommerce_email_attachments', 'wh_attach_document_into_email', 10, 3 );
function wh_attach_document_into_email ( $attachments, $email_id, $object ){
$order_id = $object->order->get_order_number();
//`enter code here`
return $attachments;
}
添加过滤器('woocommerce\u email\u attachments'、'wh\u attachment\u document\u into\u email',10,3);
将文档附加到电子邮件中的函数($attachments,$email,$id,$object){
$order\u id=$object->order->get\u order\u number();
//`在这里输入代码`
返回$attachments;
}
已测试的Woo>3.8.0请尝试以下代码:
add_filter( 'woocommerce_email_attachments', 'wh_attach_document_into_email', 10, 3 );
function wh_attach_document_into_email ( $attachments, $email_id, $object ){
$order_id = $object->order->get_order_number();
//`enter code here`
return $attachments;
}
添加过滤器('woocommerce\u email\u attachments'、'wh\u attachment\u document\u into\u email',10,3);
将文档附加到电子邮件中的函数($attachments,$email,$id,$object){
$order\u id=$object->order->get\u order\u number();
//`在这里输入代码`
返回$attachments;
}
Tested Woo>3.8.0打印此
$object
对象,然后您将获得订单id。我无法打印$object,因为筛选器仅将文件添加到WooCommerce邮件。打印此$object
对象,然后您将获得订单id。我无法打印$object,因为过滤器只是将文件添加到WooCommerce邮件中。您是否可以尝试打印它并检查您是否获得订单id?抱歉。我是个白痴。我犯了个错误,你的代码运行得很好。非常感谢。你能试着打印它并检查你是否得到订单id吗?对不起。我是个白痴。我犯了个错误,你的代码运行得很好。非常感谢。很抱歉我是个白痴。我犯了一个错误,你的代码也运行得很好。非常感谢。很抱歉我是个白痴。我犯了一个错误,你的代码也运行得很好。非常感谢。