Home Forums WoodMart support forum Hide Out of stock products from archive page "Layered nav: filter" widget

Hide Out of stock products from archive page "Layered nav: filter" widget

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #331653

    Theofilos
    Participant

    Hi,
    I had a problem with the filter “WOODMART WooCommerce Layered Nav”

    When I chose to show only the specific size in the filters, it also showed me the products that were out of stock.

    I searched I found this code here and it worked for my website. But when I update the theme and plugins it stopped working.

    I also tried to run the old theme with the old plugins locally, the code was running normally,
    I only upgraded the theme without the plugins and the code stopped working.
    So I assumed that in the theme update some change was made and the code did not work

    I found the code from here:
    https://github.com/ctuxboy/Woocommerce-out-of-stock-variations-loop

    
    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 ( ( $instockvar['attributes']['attribute_pa_size'] == $_GET['filter_size'] ) && (!$instockvar['max_qty']>0) ) {
    		   global $product;
    		   $id = $product->get_id();
    	           echo "<style>.post-$id{display: none}</style>";
    		   // echo  '<p style="color:red;font-weight: bold;">OUT OF STOCK</p>';
                    }
                }
            }
        }	
        if ( !$product->is_in_stock() ) { // if single product is out of stock
       //     echo  '<p style="color:red;font-weight: bold;">OUT OF STOCK</p>';
        }
    }
    #331673

    Hello,

    Thank you very much for choosing our theme and for contacting us.

    Please try to enable the option “Hide out of stock items from the catalog” in Woocommerce > Settings > Product > Invetory.

    Best Regards

    #331716

    Theofilos
    Participant

    I have tried it but hide only if all variations out of stock, if you have one size (one variation) out of stock and second size (variation) is stock, the product is visible.

    #331790

    Hello,

    Unfortunately, Woocommerce does not provide the option and WoodMart does not either. You will have to search for a plugin, we have not met or tested any to recommend.

    Best Regards

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