Home › Forums › WoodMart support forum › Filter Attributes – Don't Show Out of Stock Variations
Filter Attributes – Don't Show Out of Stock Variations
- This topic has 17 replies, 1 voice, and was last updated 4 months ago by Mike.
-
AuthorPosts
-
October 9, 2018 at 12:57 pm #81773
newsprinceParticipantHello.
I want to ask about Woodmart Woocomemrce Layered Nav widget
For example.
We have clothes that have the size Small, Medium, Large.
If some Variation is out of stock for example Medium, and the customer select from filters to bring all the products that have variation Medium in size, it also brings the products with the Medium variation that are out of stock.
Is there a way or snippet to not filter and show in results the variations of a product that is out of stock?
Thank you.
October 9, 2018 at 1:07 pm #81781
Elise NoromitMemberHello,
You can hide out of stock products in Woocommerce:
Woocommerce > Settings > Product > Inventory
Best regards
October 9, 2018 at 1:29 pm #81791
newsprinceParticipantNo the problem is related to this
https://github.com/woocommerce/woocommerce/issues/20800
https://github.com/woocommerce/woocommerce/issues/20689
I guess not even an official woocommerce fix is available except maybe you develop this function to check against out of stock variations and don’t show them.
Thank you.
October 9, 2018 at 2:58 pm #81814
Artem TemosKeymasterUnfortunately, we are not able to influence this functionality. It seems to be a general WooCommerce problem and we can’t fix it in our theme.
October 10, 2018 at 2:50 pm #82017
newsprinceParticipantI made a solution based on this snippet and it works
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_megethos'] ) ) { if ( ( $instockvar['attributes']['attribute_pa_megethos'] == $_GET['filter_megethos'] ) && (!$instockvar['max_qty']>0) ) { global $product; $id = $product->get_id(); echo "<style>.post-$id{display: none}</style>"; } } } } if ( !$product->is_in_stock() ) { // if single product is out of stock global $product; $id = $product->get_id(); echo "<style>.post-$id{display: none}</style>"; } }
Now if you select a variation from the widget filter that is out of stock the product gets hidden from the shop results.
October 10, 2018 at 5:59 pm #82047
Artem TemosKeymasterGreat, we are glad that you found the solution.
October 17, 2018 at 8:30 am #83191
duniesParticipantI have the same problem but the script doesn’t work for me.
Xtemos this is a serious issue and you have to consider fixing it. When I choose size 40, I expect to see all shoes of available size 40. Instead I see even the out of stock ones and this is bad for the end user.
Please give us a solution!
October 17, 2018 at 8:31 am #83192
Artem TemosKeymasterHello, @dunies,
But it is not our theme issue and we can’t fix it. It is a problem with WooCommerce, not related to WoodMart.
Regards
October 18, 2018 at 7:53 am #83483
newsprinceParticipant@dunies i made a better version of the script
I forked it from the original developer and edit it to match our need and it is working flawlesly
Go here
copy the snippet and change the following 3 things
Line 10 – 12 change the
filter_megethos
with the string your URL has when you apply the filter
and change at lines
7 – 19 – 28
the string
attribute_pa_megethos
with the attribute name you have on your products
attribute_pa_your-attribute-name
Last change the query type to your filter widget from AND to OR
Add the above code to functions.php file from your child theme.
Now in our shop when you filter a size that is out of stock the results don’t show that product
P.S.: Xtemos Team we have renewed our support period. You guys deserve it. Keep up the good work!
Attachments:
You must be logged in to view attached files.October 18, 2018 at 8:08 am #83494
newsprinceParticipantIf you have problem editing the file post the url of your site to see the filters you have and post back the right code for your site
October 23, 2018 at 6:18 pm #84590
duniesParticipantThank you very much! This is very kind of you! I’ve just seen your messages so I’ll try it out and get back to you!
THANK YOU SO MUCH!
October 10, 2019 at 1:47 am #149359
uandiParticipantThank you so much for your solution that was published on GitHub. However, the link you posted gives a 404 error. Where can I see the solution?
By the way, this plugin (free version) gives a solution for removing out of stock variations from results: https://berocket.com/product/woocommerce-ajax-products-filter
I would rather use WoodMart filters, but also include the above plugin solution. This is so basic & important. Why would someone want to show results of out of stock products, if the store is set to not show out of stock products…
I really hope you can help.
Thank you
October 10, 2019 at 7:56 am #149388
newsprinceParticipant@uandi
You ca find it here.
Change attribute_pa_megethos to your attribute_pa_name-of-your-attribute
and filter_megethos to your filter_name-of-your-attribute
and paste it in your child theme or a snippet plugin
October 12, 2019 at 10:13 pm #149843
uandiParticipantThank you for the link. I tried it, but it does not work. I replaced the attribute name in all 5 places with my attribute name, but I still see out of stock variations in the results. Try the size 3 for example (should have very few results): https://demostore.work/WoodMart/
I’m including the login to my test site in the private content box.
Thanks again
October 13, 2019 at 9:20 pm #149913
newsprinceParticipant@uandi
Sorry i am not working for woodmart can’t see the login details.
Try this code to your child theme and have child theme enabled.
//Filter attributes and variations that are in stock 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_toddlers-size'] ) ) { if(isset($_GET['filter_toddlers-size'])){ $destostock = $_GET['filter_toddlers-size']; $array = explode(',', $destostock); if (in_array($instockvar['attributes']['attribute_pa_toddlers-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_toddlers-size'], $array )&& ($instockvar['max_qty']>0)){ global $product; $id = $product->get_id(); echo "<style>.post-$id{display: block !important}</style>"; } } } } } } }
March 12, 2021 at 6:30 am #272901
inputchipParticipant@newsprince will this work if the product is set to “allow backorder” or will it get filtered out as “out of stock”?
We have some products that take us weeks to build for our clients, they aren’t necessarily “in stock”, but sometimes we keep some styles in stock. Is it best to use the two cases “In stock” for products that are available immediately, and then “allow backorder” for those that are available to order?
July 19, 2024 at 9:37 pm #584501
MikeParticipantHello newsprince ,
has anyone tried it if it works?July 20, 2024 at 12:50 pm #584556
MikeParticipantHello,
I made a variation and it works very well. anyone who wants i can help them. -
AuthorPosts
- You must be logged in to create new topics. Login / Register