Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save madeincosmos/077a3913289e7213fb665689126ace30 to your computer and use it in GitHub Desktop.
Save madeincosmos/077a3913289e7213fb665689126ace30 to your computer and use it in GitHub Desktop.
Add email attachment for certain product only
add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 10, 3 );
function add_woocommerce_attachments_for_certain_product ( $attachments, $email_id, $email_order ){
$product_id = 217762;
$attachment_id = 217944;
if( $email_id === 'customer_processing_order' ){
$order = wc_get_order( $email_order );
$items = $order->get_items();
foreach ( $items as $item ) {
if ( $product_id === $item->get_product_id() ) {
$attachments[] = get_attached_file( $attachment_id );
}
}
}
return $attachments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment