I would like to attach a PDF to the customer-processing-order from Woocommerce, I have tried the following:
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('customer_processing_order');
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$your_pdf_path = get_template_directory() . '/terms.pdf';
$attachments[] = $pdf_path;
}
return $attachments;
}
and I have uploaded a PDF called terms.pdf into my child theme so path is
/wp-content/themes/child-theme/terms.pdf
, but is not working. Can anyone help?
You are generating the path to your PDF and assigning it to a variable named
$your_pdf_path
but then you add a variable to the$attachments
array called$pdf_path
. You can simplify this without using a temporary variable like so: