Hi @mad2kx,
Try by adding this code snippet to your site in order to achieve what you want to:
/**
* Enable invoice just for specific product categories
*/
add_filter( 'wpo_wcpdf_document_is_allowed', function( $condition, $document ) {
if ( $document->type == 'invoice' ) {
if ( $document->exists() ) {
return $condition;
}
$condition = false;
if ( $order = $document->order ) {
//Set categories here (comma separated)
$not_allowed_cats = array( 'accessories', 'music' );
$order_cats = array();
//Get order categories
foreach ( $order->get_items() as $item_id => $item ) {
// get categories for item, requires product
if ( $product = $item->get_product() ) {
$id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
$terms = get_the_terms( $id, 'product_cat' );
if ( empty( $terms ) ) {
continue;
} else {
foreach ( $terms as $key => $term ) {
$order_cats[$term->term_id] = $term->slug;
}
}
}
}
// get array of category matches
$cat_matches = array_intersect( $not_allowed_cats, $order_cats );
if ( count( $cat_matches ) > 0 ) {
return true; // if there is 1 or more matches: allow invoice
}
}
}
return $condition;
}, 10, 2 );
Let me know if it worked! ??