Add a pdf attachment to WooCommerce completed order email notification
There are some errors in your code: The $email_object
function argument is the wrong variable name and should be instead $order
to match with your first if statement.
Now for the attachement path linked to the theme, you will use:
get_stylesheet_directory()
for a child themeget_template_directory()
for a parent theme (Website without a child theme)
The email Id customer_completed_order
is correct to target Customer "completed" email notification.
As you are not using the $order
variable argument in your code, ! is_a( $order, 'WC_Order' )
is not needed, so the working code will be:
add_filter( 'woocommerce_email_attachments', 'attach_pdf_file_to_customer_completed_email', 10, 3);function attach_pdf_file_to_customer_completed_email( $attachments, $email_id, $order ) { if( isset( $email_id ) && $email_id === 'customer_completed_order' ){ $attachments[] = get_stylesheet_directory() . '/Q-0319B.pdf'; // Child theme } return $attachments;}
Code goes in functions.php file of your active child theme (or active theme). Tested and work.
For a parent theme replace:
$attachments[] = get_stylesheet_directory() . '/Q-0319B.pdf'; // Child theme
by the following line:
$attachments[] = get_template_directory() . '/Q-0319B.pdf'; // Parent theme