Forked from bryceadams/gist:a8e01ad4e1901f849658
Last active
February 23, 2018 19:49
-
-
Save lmartins/9234b5983b62e66fc87d to your computer and use it in GitHub Desktop.
Quick little snippet that will let you add a static PDF file (or in fact, any kind of file) to the WooCommerce Order Emails.
Just add the following code to the ‘custom functions’ area of your functions.php file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 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[] = $pdf_path; | |
} | |
return $attachments; | |
} |
@renuprv: I think that $file needs to be an absolute path on the web server, not a url.
You have to change line 9 to:
$your_path = dirname(FILE) . '/terms.pdf';
(If terms.pdf is located at the same level as functions.php)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I have added the above code in my theme functions.php. But no attachment is added to the woocomerce email. My requirement is - I am using multisite(sub directory based). In checkout page, user will upload a file. I want to send that uploaded file to the admin on new order. I am using the below code -
function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object)
{
$attachments[] = $file; //$file contains the full path along with filename uploaded by user like - http://mysite/cityname/wp- content/uploads/user/fmyfile.pdf
return $attachments;
}
Can you please suggest if the above code is correct?
Thanks.