• Resolved daveyk182

    (@daveyk182)


    I need help to be able to only send the invoice for only one product. I’m guessing that I use this filter – wpo_wcpdf_document_is_allowed

    But I couldn’t find any documentation for that function, I just saw it in another post. If you could help me write the function I would greatly appreciate it. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! The hook is quite simple in that it takes two arguments: 1) a boolean whether the document is allowed and 2) the document object (which contains the order in the order property: $document->order):

    Here’s an example:

    
    add_filter('wpo_wcpdf_document_is_allowed','wpo_wcpdf_invoice_specific_product',10,2);
    function wpo_wcpdf_invoice_specific_product( $is_allowed, $document ) {
    	if ( !empty($document->order) && $document->get_type() == 'invoice' ) {
    		$allowed_product = 42; // this is the product ID of the product you want to invoice (use parent ID for variable products)
    		foreach ( $document->order->get_items() as $item_id => $item ) {
    			if ( $item->get_product_id() != $allowed_product ) {
    				$is_allowed = false; // there's a product in the order that is not the allowed product
    			}
    		}
    	}
    	return $is_allowed;
    }
    
    Thread Starter daveyk182

    (@daveyk182)

    Awesome! Thanks for the help. Looks like it’s working.

    Thread Starter daveyk182

    (@daveyk182)

    Is there a quick way to change the filename that comes through to the email?

    Plugin Contributor Ewout

    (@pomegranate)

    Thread Starter daveyk182

    (@daveyk182)

    Perfect. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Only Send Invoice for Only One Product’ is closed to new replies.