Hi there,
we are attaching the PDFs through official WooCommerce Filters (e.g. woocommerce_email_attachments). You might want to check whether our filter gets applied by inserting some test outputs in WC_GZDP_Legal_Page_Helper::attach_pdfs.
Maybe it would be better to not initiate a new email object but to use the existing ones, e.g.:
$mails = WC()->mailer()->emails;
$email_o = $mails['WC_Email_Customer_Completed_Order'];
Cheers
Unfortunately, using the existing object did not work.
Hi,
then please investigate that further by following my approach from above. You might need to check, whether our filter gets applied or not. I do not see any issue with the code – normally it should be applied successfully even when manually triggering the email. Did you try to deactivate other plugins one after another?
Cheers
Hi!
I tried to attach an other file in WC_GZDP_Legal_Page_Helper::attach_pdfs with an absolute path – and the file got attached. So it is a path problem, or the variable $attachments is empty at this point.
I can’t investigate this further for now. I hope you fix this, it would be great.
This is how I am doing it now:
add_filter( 'woocommerce_email_attachments', 'attach_disclaimer_pdf_to_email', 10, 3);
function attach_disclaimer_pdf_to_email ( $attachments , $id, $object ) {
if($id = 'customer_completed_order') {
$serverRoot = $_SERVER['DOCUMENT_ROOT'];
$attachments[] = $serverRoot. '/wp-content/uploads/2019/10/pdf.pdf';
$attachments[] = $serverRoot. '/wp-content/uploads/2019/10/myfile.pdf';
}
return $attachments;
}
add_action( 'woocommerce_payment_complete', 'lw_payment_complete' );
function lw_payment_complete( $order_id ){
$mails = WC()->mailer()->emails;
$email_o = $mails['WC_Email_Customer_Completed_Order'];
$email_o->trigger($order_id);
}
Hi there,
I’ve just tested the script by myself. I’ve manually triggered the order complete mail including attachments – just like you did. I can’t find any problems with the attachments – my chosen attachments are attached as configured.
You might need to debug that a little further, e.g. check the $attachments variable within WC_GZDP_Legal_Page_Helper::attach_pdfs (var_dump( $attachments )).
Cheers
I just found out, that no changes Ido to the Order Confirmation Mail in the WC settings are applied to the mail I’m sending within the ‘woocommerce_payment_complete’ action… neither Subject, nor Confirmation Text, Attachments etc… this seems to be a WC bug.
I also tried the same thing in another WP installation, same problem.
Hi there,
as I said, I’ve tested that successfully. You should try disabling other plugins and extensions before considering that as a bug..
Cheers
-
This reply was modified 6 years ago by
vendidero.