Deactivate invoice for several products
-
Hi all,
I was following the steps shown in this topic, I want to exclude several products from invoice generation.
I used the following code (in code snippet plugin) to do that, but this code worked one time (idk why, I used it, then I disabled the plugin for 5 mins, then I activated it again).
add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_products', 100, 4 ); function wpo_wcpdf_exclude_products( $condition, $order, $status, $template_type ) { // only apply check on invoices if ($template_type != 'invoice') { return $condition; } // define product IDs which shouldn't get an invoice here $no_invoice_products = array( 101, 102 ); // loop through order items and cancel attachment if one of the products present $items = $order->get_items(); foreach ($items as $item_id => $item) { if (in_array($item->get_product_id(), $no_invoice_products)) { // matching product, don't attach invoice return false; } } // if we got here, there were no matching products return $condition; }
What should I do? I need a code that disables several product IDs from generating invoices
Thanks for the support!
EDIT: I was wondering if…
Perhaps it is better to act in the reverse way in my case: enable the generation of invoices only for specific products (because there are so many products to be excluded)EDIT2: The products are subcriptions that renew every month/year
EDIT3: I recreated the code snipper and now… he worked! … I keep this topic open asking what I wrote in “EDIT:”, if possible…
- The topic ‘Deactivate invoice for several products’ is closed to new replies.