Support » Plugin: WooCommerce PDF Invoices & Packing Slips » exclude categories from pdf invoice

  • Resolved createscape

    (@createscape)


    Hi there,
    I found an old support question about excluding categories and tried using the filter you suggested to them. I still see the products being added to the pdf invoice. Here is the code I’m using:

    
    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_product_categories', 100, 4 );
    function wpo_wcpdf_exclude_product_categories( $condition, $order, $status, $template_type ) {
        // only apply check on invoices
        if ($template_type != 'invoice') {
            return $condition;
        }
    
        // define categories which shouldn't get an invoice here
        $no_invoice_cats = array(34);
    
        $items = $order->get_items();
        $order_cats = array();
        foreach ($items as $item_id => $item) {
            // get categories for item, requires product
            $product = $order->get_product_from_item( $item );
            if ($product) {
                $terms = get_the_terms( $product->id, 'product_cat' );
                if (empty($terms)) {
                    continue;
                }
                foreach ($terms as $key => $term) {
                    $order_cats[$term->term_id] = $term->name;
                }
            }
        }
    
        // get array of category matches
        $cat_matches = array_intersect($no_invoice_cats, $order_cats);
        if ( count($cat_matches) > 0 ) {
            // 1 or more matches, don't attach invoice
            return false;
        } else {
            return $condition;
        }
    }
    

    Can you tell me what I’m doing wrong? My category name is “No Tax Receipt” and the category id is 34.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter createscape

    (@createscape)

    I’m sorry, somehow I’ve landed on the wrong tax receipt plugin page again! Please disregard.

Viewing 1 replies (of 1 total)
  • The topic ‘exclude categories from pdf invoice’ is closed to new replies.