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
- This topic has 3 replies, 2 voices, and was last updated 3 years, 1 month ago by Elise Noromit.
-
AuthorPosts
-
November 14, 2021 at 12:11 am #331653
TheofilosParticipantHi,
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 workI found the code from here:
https://github.com/ctuxboy/Woocommerce-out-of-stock-variations-loopadd_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>'; } }
November 14, 2021 at 10:48 am #331673
Elise NoromitMemberHello,
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
November 14, 2021 at 4:27 pm #331716
TheofilosParticipantI 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.
November 14, 2021 at 11:52 pm #331790
Elise NoromitMemberHello,
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
-
AuthorPosts
- You must be logged in to create new topics. Login / Register