Created
October 9, 2019 13:42
-
-
Save madeincosmos/077a3913289e7213fb665689126ace30 to your computer and use it in GitHub Desktop.
Add email attachment for certain product only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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