Support » Plugin: PDF Invoices & Packing Slips for WooCommerce » how i can send PDF Invoices for specific product id

  • Resolved ele

    (@luishgc93)


    hello,
    your plugin is awesome, but i need send the PDF Invoices only for specific product id.

    how i can do? thanks 😀

    • This topic was modified 3 years ago by ele.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ele

    (@luishgc93)

    i try this code:

    <?php
    /*
    Plugin Name: WooCommerce PDF Invoices & Packing Slips Desactivar PDF
    Plugin URI: https://www.advancedcustomfields.com
    Description: Desactivamos el generador de Facturas en PDF para los productos que NO son de OAT
    Version: 1.0
    Author: Luishgc93
    Author URI: https://www.oatobservatorio.com
    */
    
    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( 1573, 2217 );
    
        // 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;
    }

    but on the order , on panel of control, the order is generated.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @luishgc93

    Please add the following code snippet to your theme functions.php file (don’t forget to add the product IDs):

    add_filter('wpo_wcpdf_document_is_allowed', 'disallow_document_on_certain_products', 10, 2);
    function disallow_document_on_certain_products( $allowed, $document )
    {
    	$products_ids = array(16, 23); // add here your product IDs
    
    	if ( !empty($order = $document->order) && $document->get_type() == 'invoice' ) {
    		foreach( $order->get_items() as $item_id => $item ) {
    			$product_id = $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'];
                if( in_array($product_id, $products_ids) ) {
                    $allowed = false;
                }
            }
    
    	}
    	return $allowed;
    }

    If you never worked with action/filters please read our documentation page: How to use filters

    Thread Starter ele

    (@luishgc93)

    its work ! thanksss

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how i can send PDF Invoices for specific product id’ is closed to new replies.