Hello @dccreatives
Invoices are generated for orders not products, but should be possible to disallow the invoice generation if a specific product is ordered, but this works only at a order level.
Please add the code snippet below to your theme functions.php file:
add_filter('wpo_wcpdf_document_is_allowed', function( $allowed, $document )
{
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'];
// disallow product by ID
if( $product_id == 34 ) { // product ID
$allowed = false;
}
}
}
return $allowed;
}, 10, 2 );
If you never worked with actions/filters please read this documentation page: How to use filters
Hi, I have used the following code to avoid attaching invoices if the company name data is missing, but what I really want, is that the invoice is not generated if the field comes empty. Any ideas?
add_filter( ‘wpo_wcpdf_custom_attachment_condition’, ‘wpo_wcpdf_invoice_attachment_condition’, 100, 4 );
function wpo_wcpdf_invoice_attachment_condition( $condition, $order, $status, $template_type ) {
// only apply condition to invoices
if ($template_type == ‘invoice’) {
$billing_company = $order->get_billing_company();
// do not attach invoice if billing company is not filled in
if (empty($billing_company)) {
$condition = false;
}
}
return $condition;
}
Plugin Contributor
Ewout
(@pomegranate)