Add PDF to order confirmation in certain language
-
Hello,
I have read most of the relevant posts on this support forum but could not find the solution to our issue.Besides our invoice from the PDF packing slip and PDF plugin, we are attaching an additional PDF to our order confirmations from WooCommerce as it is our legal obligation to send a cancellation form to consumers. We have a multinlingual website and hence also two language versions of this cancellation form PDF.
The issue
We are trying to send customers the language version of the cancellation form in the language in which they have ordered their product(s). We noticed that the automatic PDF invoice is in English for customers who order via the English language version of our website and in Dutch for customers who ordered via the Dutch language version of our website.We have tried the following code:
add_filter( 'woocommerce_email_attachments', 'attach_pdf_to_emails', 10, 4 ); function attach_pdf_to_emails( $attachments, $email_id, $order, $email ) { if ( defined( 'ICL_LANGUAGE_CODE' ) && 'nl' == ICL_LANGUAGE_CODE ) { $email_ids = array( 'customer_completed_order'); if ( in_array ( $email_id, $email_ids ) ) { $upload_dir = wp_upload_dir(); $attachments[] = $upload_dir['basedir'] . "/2021/05/Herroepingsformulier.pdf"; } return $attachments; } Else { $email_ids = array( 'customer_completed_order'); if ( in_array ( $email_id, $email_ids ) ) { $upload_dir = wp_upload_dir(); $attachments[] = $upload_dir['basedir'] . "/2021/05/Cancellation-form.pdf"; } return $attachments; } }
What could be the reason (but not sure)
The filter that we use searched for the language version of the webpage that is being used. However, after a customer orders we have to set the order from ‘being processed’ to ‘completed’ in our backend. I can imagine that if the backend is set in Dutch and the order is set to completed it is that language that the filter uses (and hence sends the cancellation form in Dutch) instead of the original language in which the customer ordered (English)?Our thoughts on a solution, but not sure hence why we are asking:
I have read that people use filters on the product IDs instead of language code to attach PDFs to certain products. However, if we are e.g. selling 5.000 products in both languages this is not practical. So we are looking for a solution where I do not have to add all product IDs manually and do not need to update the code everytime we have a new product added to our assortment.Many thanks in advance!!
- The topic ‘Add PDF to order confirmation in certain language’ is closed to new replies.