attach PDF woocommerce email

2019-06-12 03:13发布

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?

1条回答
不美不萌又怎样
2楼-- · 2019-06-12 04:05

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:

$attachments[] = get_stylesheet_directory() . '/terms.pdf';
查看更多
登录 后发表回答