How to attach a file (pdf) to the e-mail?

To make an online store legally clean, the order email should also contain the terms and conditions and the revocation. These texts can be placed in the footer of the email or visually cleaner as an attached pdf file. The following script in the functions.php integrates a corresponding file:

add_filter( 'woocommerce_email_attachments', 'wphelp_email_files_woo', 10, 4 );
function wphelp_email_files_woo( $attachments, $email_id, $order, $email ) {
    $email_ids = array( 'new_order', 'customer_processing_order' );
    if ( in_array ( $email_id, $email_ids ) ) {
        $upload_dir = wp_upload_dir();
        $attachments[] = $upload_dir['basedir'] . "/datei.pdf";
    }
    return $attachments;
}

Alternative to e.g. attach a file to all WooCommerce mails:

add_filter( 'woocommerce_email_attachments', 'attach_file_to_order_emails', 10, 3);
function attach_file_to_order_emails( $attachments , $mail_id, $order ) {

  if( ! is_a( $order, 'WC_Order' ) || ! isset( $mail_id) ) {
    return $attachments;
  }
  $attachments[] = get_stylesheet_directory() . '/agb-widerruf.pdf';
 
  return $attachments;
}

 

Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.