Hi @ckriegel
You can disable invoice creation for all orders that have products with the ‘donations’ category in them via the following code snippet:
add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_not_allow_invoice_for_certain_categories', 10, 2 );
function wpo_wcpdf_not_allow_invoice_for_certain_categories ( $condition, $document ) {
if ( $document->type == 'invoice' ) {
//Set categories here (comma separated)
$not_allowed_cats = array( 'donations' );
$order_cats = array();
if ( $order = $document->order ) {
//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 false; // 1 or more matches: do not allow invoice
}
}
return $condition;
}
This code snippet should be added to the functions.php of your child theme or via a plugin like Code Snippets. If you haven’t worked with code snippets or functions.php before please read the following guide: How to use filters
-
This reply was modified 3 years, 7 months ago by kluver.