-
-
Save lmartins/9234b5983b62e66fc87d to your computer and use it in GitHub Desktop.
<?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; | |
} |
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.
@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)
$pdf_path does not exist. Rename it to $your_pdf_path