Plugin Contributor
kluver
(@kluver)
Hi @joostbloemen,
With our Professional extension you can add the so called order notification email. This will let you send an email to specified email addresses (like a warehouse) when an order is placed. You can attach your PDF documents to this email.
With the following code snippet you will prevent the order notification email from sending when all products in the order are virtual or downloadable:
add_filter( 'woocommerce_email_get_option', 'wpo_wcpdf_dont_email_when_all_items_are_virtual_or_downloadable', 10, 5 );
function wpo_wcpdf_dont_email_when_all_items_are_virtual_or_downloadable ( $value, $email, $original_value, $key, $empty_value ) {
if ( $email->id == 'pdf_order_notification' && $key == 'recipient' && !empty( $email->object ) && $email->object instanceof WC_Order ) {
$items = $email->object->get_items();
foreach( $items as $item_id => $item ) {
if ( $product = $email->object->get_product_from_item( $item ) ) {
if ( $product->is_virtual() === false && $product->is_downloadable() === false ) {
return $value;
}
}
}
return false;
}
return $value;
}
This code snippet should be added to the functions.php of your child theme or with a plugin like Code Snippets. If you haven’t worked with code snippets or functions.php before please read this: How to use filters