Support » Plugin: Invoices for WooCommerce » Exclude category

  • Hi there,
    Is there a way I can exclude products from a certain category from displaying on the PDF invoice? We use this plugin for generating tax receipts. My client wants to add a new product which isn’t tax deductible.
    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter createscape

    (@createscape)

    I’ve found your “bewpi_skip_invoice_generation” function and have made it work for excluding product ids….

    function bewpi_skip_invoice_generation( $skip, $status, $order ) {
    
      $products = $order->get_items();
      $excludeids = array( 2815 );
    
      foreach ( $products as $product ) {
    
      if ( !in_array( $product->get_id(), $excludeids ) ) {
      return true;
      }
      }
    
    }
    add_filter( 'bewpi_skip_invoice_generation', 'bewpi_skip_invoice_generation', 10, 3 );
    

    …however I need the invoice to send if they purchase another product in the same order which is tax deductible along with the one that isn’t, but to exclude the one product from the invoice table.

    Thread Starter createscape

    (@createscape)

    I found something that sort of works…

    //Exclude Category from PDF Invoices
    function bewpi_skip_invoice_generation( $skip, $status, $order ) {
     $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 true;
        }
    
    }
    add_filter( 'bewpi_skip_invoice_generation', 'bewpi_skip_invoice_generation', 10, 3 );

    But it would still be problematic if someone ordered one item that was in the excluded category, and one that wasn’t. With the code above it doesn’t generate any invoice.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude category’ is closed to new replies.