Adding Attachments To WooCommerce Emails

Aug 18, 2019

Adding Attachments To WooCommerce Emails


This post was originally created on our sister site WP Cover.
View Original Article
August 18, 2019

WooCommerce is a great e-commerce platform that comes with flexibility. One request we recently had from a client was adding a PDF document to one of the automated WooCommerce emails that gets sent out. I went hunting for the correct filter and happy to share it today. Here is the code that would go in your functions.php file, I’ll explain each part of it below:
 

add_filter( 'woocommerce_email_attachments', 'wpcover_woocommerce_attachments', 10, 3 );
function wpcover_woocommerce_attachments($attachments, $email_id, $email_object){
	if( $email_id === 'customer_processing_order' || $email_id === 'customer_on_hold_order'){
		$attachments[] = get_attached_file( 2527 );
	}
	return $attachments;
}

 
Before you implement the above code, you’ll need to upload your attachment to the WordPress media library. Once uploaded, you would grab the attachment ID and swap it for the number 2527 as seen in the example above on line 4.

You may also want to adjust line 3 of the example function that determines which emails the PDF is attached to. In this case, we’re attaching it to the order processing and order on hold emails. Here is a list of other WooCommerce emails you may want to attach to:

customer_processing_order
cancelled_order
customer_completed_order
customer_invoice
customer_new_account
customer_note
customer_on_hold_order
customer_refunded_order
customer_reset_password
failed_order
new_order

I hope the above helps somebody else who is looking to attach PDFs or other document types to the automated emails WooCommerce sends out.

The post Adding Attachments To WooCommerce Emails appeared first on WP Cover.

Additional News

Perfect!

Let's get started. Fill out the form below to email us or request a call back.


FREE: 10 Step Guide To Choosing A Web Design Company

FREE: 10 Step Guide To Choosing A Web Design Company

Download your free e-book. Learn the questions you should be asking prior to partnering with a web design company. Enter your email address and we'll send it to you right away!

We've sent the e-book to your email address!