Home › Forums › WoodMart support forum › Size filter showing products which are out of stock
Size filter showing products which are out of stock
- This topic has 8 replies, 3 voices, and was last updated 6 years, 3 months ago by
newsprince.
-
AuthorPosts
-
April 29, 2019 at 7:05 pm #121481
tsyganovParticipantFor 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?
April 29, 2019 at 7:17 pm #121482
tsyganovParticipant2. 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?
April 29, 2019 at 8:17 pm #121487
newsprinceParticipantThis 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.
April 30, 2019 at 5:30 am #121514
tsyganovParticipantI’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.April 30, 2019 at 9:17 am #121557
Elise NoromitMemberHello,
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
April 30, 2019 at 10:39 am #121575
newsprinceParticipantGo to Woocommerce > Products > Inventory and Uncheck the Out of stock visibility
April 30, 2019 at 11:14 am #121580
tsyganovParticipantThe Out of stock visibility checkbox is unchecked.
Attachments:
You must be logged in to view attached files.April 30, 2019 at 11:24 am #121588
Elise NoromitMemberHello,
If you check this option the out of stock products would be hidden. If you uncheck they will appear.
Best Regards
April 30, 2019 at 11:32 am #121590
newsprinceParticipantYou have to enable manage stock to each variation of the products. Now your stock is unlimited in each variation.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register