Send invoice only for a specific product
-
Hi,
I am using your plugin to create a gift card template for one specific product on the shop of a client.
I only need the PDF to be send if this particular product is added to cart and checked out. I only allow one item at a time in the cart to prevent any mix up.I tried all the snippets I could find in this forum, tried to tweak them to what I need, but none of them work.
Here is the last thing I tried (the product ID is 185747, and it is a variable product) , which still send the PDF to every product.
All my other attempt doesn’t send the PDF at all.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(185747); 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; endif; endforeach; endif; return $allowed; }
What am I doing wrong ?
I would be very grateful if you could help me with this issue !
Thank you
- The topic ‘Send invoice only for a specific product’ is closed to new replies.