Is it possible to attach 2 files when WooCommerce is sending email?
-
Hi,
I found this code: (source: http://bryceadams.com/add-pdf-woocommerce-order-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( 'new_order', 'customer_invoice', 'customer_processing_order', 'customer_completed_order' ); if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) { $your_pdf_path = get_template_directory() . '/terms.pdf'; $attachments[] = $your_pdf_path; } return $attachments; }
but I cant get it working.
Is it possible to alter the code, so I can attach 2 files when the emails is send?
Thanks in advance.
Kind regards,
Frederik
-
Hi Mike,
Thanks for your fast reply.
So I have to use
return apply_filters( 'woocommerce_email_attachments', array(), $this->id, $this->object );
but I’m not sure how I can alter the code, so I can attach 2 files to the emails send.
Do you have a solution for that?
– Frederik
Bryce updated his code http://bryceadams.com/add-pdf-woocommerce-order-email/
I have now updated the code in my functions.php, but it still doesn’t attach anything to the emails.
The code I have now is:
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3); function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) { $your_pdf_path = get_template_directory() . '/terms.pdf'; $attachments[] = $your_pdf_path; return $attachments; }
I have tried with different directory paths for the file, but with no luck.
Do you know what path I should provide, if the file is located in:
/public/wp-content/uploads/files ?– Frederik
You need the full, absolute path to the file. get_template_directory is not suitable for this.
Great, now it’s working. I use
get_home_path()
instead ofget_template_directory()
The file is attached to all emails, is it possible to select for which email type, the file should be attached – if that make sense?
– Frederik
Check against the passed in $id – this is the email ID.
I was too fast – it only works partial.
I can get files attached to emails send when I change status on the order however there is no files attached to the emails customers receive right after placing an order. Is it possible to make this work?
– Frederik
The same code is ran for all emails.
Maybe it has something to do with the status “On hold”? Because as soon I change the status of the order the attachments will work..
If its the same email, should not make a difference. See this line – use of get_attachments https://github.com/woothemes/woocommerce/blob/master/includes/emails/class-wc-email-customer-processing-order.php#L65
It looks like this is for the Status “Processing order” and not “On hold”. I have been looking for the code for sending emails when the status is “On hold” which is the status of the order right after checkout, but I can’t find it. Maybe this function dosen’t include attachments?
Hi Mike .. i added below code in function.php to send a pdf attachment email
add_filter( ‘woocommerce_email_attachments’, ‘attach_terms_conditions_pdf_to_email’, 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
$your_pdf_path = get_template_directory() . ‘/terms.pdf’;
$attachments[] = $your_pdf_path;
return $attachments;
}and my file uploded path is
http://cartest.wpengine.com/dubai/wp-content/uploads/userpro/5/5694d2d62190d.pdf ..and this file is uploading trough the userpro.. i want too get the above uploaded file in the attachment..but i didn’t get the attachment…How can i get the attached file in Email ..pls help me out..
- The topic ‘Is it possible to attach 2 files when WooCommerce is sending email?’ is closed to new replies.