Home Forums WoodMart support forum Size filter showing products which are out of stock

Size filter showing products which are out of stock

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #121481

    tsyganov
    Participant

    For a product variation I’ve selected “Manage stock” and quantity to zero. On the product page it shows correctly that the size is out of stock. But in the category page when I use the “size” filter to find available products – it’s still showing in the catalogue. How to solve this?

    #121482

    tsyganov
    Participant

    2. Another issue with the filter.

    I’ve disabled a product size variation. On the product page the the size doesn’t show in the sizes dropdown, but when I select the size in the filter on categories page – the product with this not active size still appears. How to solve this?

    #121487

    newsprince
    Participant

    @tsyganov

    This is a woocomerce problem as you can see here.

    https://github.com/woocommerce/woocommerce/issues/20800

    The good news is i have a solution for this.

    https://xtemos.com/forums/topic/filter-attributes-dont-show-out-of-stock-variations/

    Read my comment on how to implement this code in your shop and after that when you filter a product that is out of stock this product gets hidden.

    Also look here.

    https://github.com/Moultrex/Woocommerce-out-of-stock-variations-loop/blob/master/wc-out-of-stock-variation.php

    #121514

    tsyganov
    Participant

    I’ve added your code. But now when I filter the products by “size” they are not shown at all, even those which are in stock.

    Heres my code:

    // Hide out of stock products from filter
    add_action( 'woocommerce_before_shop_loop_item_title', 'wk_out_of_stock_variations_loop' );
    function wk_out_of_stock_variations_loop(){
        global $product;
        if ( $product->product_type == 'variable' ) { // if variation product is out of stock
            $available = $product->get_available_variations();
            if ( $available )foreach ( $available as $instockvar ) {
                if ( isset($instockvar['attributes']['attribute_pa_size'] ) ) {
                  
                  
            if(isset($_GET['filter_size'])){
               
               $destostock = $_GET['filter_size'];
                  
              
              $array = explode(',', $destostock);
              
    
        if (in_array($instockvar['attributes']['attribute_pa_size'], $array )&& (!$instockvar['max_qty']>0)){
               global $product;
               $id = $product->get_id();
          
                echo "<style>.post-$id{display: none}</style>";
    
        }
              else{
                
              if (in_array($instockvar['attributes']['attribute_pa_size'], $array )&& ($instockvar['max_qty']>0)){
               global $product;
               $id = $product->get_id();
          
                echo "<style>.post-$id{display: block !important}</style>";
              
              }
              }
                
            }
        }   
     
    }
        }
    }
    Attachments:
    You must be logged in to view attached files.
    #121557

    Hello,

    1. Navigate to Woocommerce > Settings > Product tab > Inventory and find the option to hide out of the stock product. Your filter would show the product count as if they are all in stock, however, when you search our of the stock product would not appear.

    2. as point #1 You would better hide the product by means of hiding the product which is out of stock. Yes, you disable the variation, however, the products contain the attribute, so filter shows all the product containing the attribute.

    Best Regards

    #121575

    newsprince
    Participant

    @tsyganov

    Go to Woocommerce > Products > Inventory and Uncheck the Out of stock visibility

    #121580

    tsyganov
    Participant

    @newsprince

    The Out of stock visibility checkbox is unchecked.

    Attachments:
    You must be logged in to view attached files.
    #121588

    Hello,

    If you check this option the out of stock products would be hidden. If you uncheck they will appear.

    Best Regards

    #121590

    newsprince
    Participant

    @tsyganov

    You have to enable manage stock to each variation of the products. Now your stock is unlimited in each variation.

Viewing 9 posts - 1 through 9 (of 9 total)