Deactivate invoice for several products

[ad_1]

Hi @estebanip,

Here is not only a code snippet example, but the actual one that works for your case:

/**
 * WooCommerce PDF Invoices & Packing Slips
 * Deactivate invoice for specific products
 */
add_filter( 'wpo_wcpdf_document_is_allowed', function( $is_allowed, $document ) {	
	if ( ! empty( $order = $document->order ) && $document->get_type() == 'invoice' && ! $document->exists() ) {
		$disallowed_products = [ 123, 321 ]; // Add all your disallowed products IDs here separated by comma
		foreach ( $order->get_items() as $item_id => $item ) {
			if ( in_array( $item->get_product_id(), $disallowed_products ) ) {
				$is_allowed = false;
			}
		}
	}
	return $is_allowed;
}, 10, 2 );

If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

Just replace the product IDs within the $disallowed_products with the actual product IDs 😉

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer