Exclude product category from invoice
-
Hello, I found this thread, where it is described to exclude product categories from beeing included in an invoice.
https://www.ads-software.com/support/topic/exclude-specific-product-categories-from-invoices/
Unfortunately this code does not work anymore? I created a category noinvoice, but when the order state is changed to processing / completed, an invoice number for this order is generated and the invoice is attached to the woocommerce order email, which should also be prevented
add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_not_allow_invoice_for_certain_categories', 10, 2 ); function wpo_wcpdf_not_allow_invoice_for_certain_categories ( $condition, $document ) { if ( $document->type == 'noinvoice' ) { //Set categories here (comma separated) $not_allowed_cats = array( 'noinvoice' ); $order_cats = array(); if ( $order = $document->order ) { //Get order categories foreach ( $order->get_items() as $item_id => $item ) { // get categories for item, requires product if ( $product = $item->get_product() ) { $id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id(); $terms = get_the_terms( $id, 'product_cat' ); if ( empty( $terms ) ) { continue; } else { foreach ( $terms as $key => $term ) { $order_cats[$term->term_id] = $term->slug; } } } } } // get array of category matches $cat_matches = array_intersect( $not_allowed_cats, $order_cats ); if ( count( $cat_matches ) > 0 ) { return false; // 1 or more matches: do not allow invoice } } return $condition; }
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Exclude product category from invoice’ is closed to new replies.