Support » Plugin: WooCommerce PDF Invoices & Packing Slips » 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 2 months, 2 weeks ago by ele.
Viewing 3 replies - 1 through 3 (of 3 total)
  • 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 Support 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

    ele

    (@luishgc93)

    its work ! thanksss

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.