I want to attach the invoice as PDF to the WooCommerce Mail. Works great with static PDFs (like terms and conditions), but I need the option to work with variable PDF-Files (like invoices).
I use this filter:
add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_email', 10, 3);
and this function:
function attach_pdf_to_email ( $attachments, $status , $object ) {
$pdf_path = ABSPATH . "wp-content/uploads/terms.pdf";
$attachments[] = $pdf_path;
return $attachments;
}
Works perfectly. Now I want to change $pdf_path to this:
$pdf_path = ABSPATH . "wp-content/uploads/terms" . $order_id . ".pdf";
But I am not able to get the $order_id.
I tried:
global $order;
// First try
$order_id = $order->id;
// Second try
$order_id = $order->get_id();
// Third and fourth try (like above)
global $post;
The problem is, that the filter sends neither the order, nor the order id. Is there any way or idea, how I can achieve that?
4
Answers
Try this code.
you can get order id from
$object
.try below code, i have tried your code and edited it to get order id
Try this code:
Tested Woo > 3.8.0
you have order object and from this object you can get order id i tried its working