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);