Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save garretthyder/78e1008c5a857bd8fb6b to your computer and use it in GitHub Desktop.
Save garretthyder/78e1008c5a857bd8fb6b to your computer and use it in GitHub Desktop.
Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments
<?php
// Add Downloadable Products to Woocommerce Completed Order & Invoice Emails as Attachments
function woocommerce_emails_attach_downloadables($attachments, $status, $order) {
if ( ! is_object( $order ) || ! isset( $status ) ) {
return $attachments;
}
if ( empty( $order ) ) {
return $attachments;
}
if ( ! $order->has_downloadable_item() ) {
return $attachments;
}
$allowed_statuses = array( 'customer_invoice', 'customer_completed_order' );
if ( isset( $status ) && in_array( $status, $allowed_statuses ) ) {
foreach ( $order->get_items() as $item_id => $item ) {
foreach ( $order->get_item_downloads( $item ) as $download ) {
$attachments[] = str_replace( content_url(), WP_CONTENT_DIR, $download['file'] );
}
}
}
return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'woocommerce_emails_attach_downloadables', 10, 3);
@garretthyder
Copy link
Author

Not work now

O cool I didn't know anyone was using it let alone it being the 'official' snippet on the website;
https://docs.woocommerce.com/document/email-faq/#section-14

From the looks of this thread you're not alone;
https://stackoverflow.com/a/53253862

Seems that WooCommerce updated the woocommerce_email_attachments filter to change the second param from $status to $email_id.

Would you mind taking a look at that stack thread & snippet @W15ER69 and letting me know if it works, if so I'd be happy to update the snippet here as it's embedded on the plugin FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment