I have a 1.000 shoes store, so for my costumers, filtering by size is the best way to quickly find what they are looking for and to purchase it.
The default size woocommerce widget can't help my users because it show every items that have size selected by the users, even if the variations stock is set 0.
So, if a costumer filters for size 41, the widget shows shoes that has actually 41 in stock and shoes that had 41 in stock but have not actually.
This is very frustating for users that have to look into every item to see if the size 41 is avalaible or not. Consequently, they quit after the first few items which don鈥檛 have the size they are looking for.
Here you can see a little screencast to better explain what i'am talking about: https://youtu.be/pYZqnLMe_4k
Is it possible to improve size widget, so that it only shows items that have selected size INSTOCK?
P.s: backorder are not allowed; manage stock is checked for every item
Hi,
This is currently a 'wontfix' item - I'll briefly explain why it's not possible to do this at this point.
In the future we may try to revisit this, but as it stands, looping over all variations during layered nav queries would be a massive bottleneck and would cause too large of a performance issue to warrant it's inclusion. It may be possible once product tables are in WooCommerce core, but right now it's not possible. Hope you understand.
Thanks.
Dear claudiulodro,
thank for your help.
I've notice that you copy&paste your answer from an old ticket opened four years ago. So i think "future" it will be a long wait.
Sorry dude, but i can't understand. It's incredible that an advanced platform like woocommerce doesn't have a simple feature like filtering by attributes.
You should warn every user about this issue, because it' s a serious problem for who sells clothes, shoes, and others variable items.
I want to be honest with you: i I would never have chosen Woocommerce for my store if I had known about this problem.
Future is coming in 2019. The product custom tables are under development now and will be in WooCommerce 4.0. These should make it possible to do the sort of variation attribute filtering you are trying to do since attributes will have their own optimized database tables instead of the WP terms tables.
SOUNDS GOOD!
when is it going to come out, approximately?
@ifede84
I made a solution based on this snippet and it works
https://github.com/ctuxboy/Woocommerce-out-of-stock-variations-loop
You can find it here.
Change the $_GET['filter_megethos'] with your URL filter that is generated when you apply a filter and change ['attribute_pa_megethos'] with your attribute. Don't forget to change the widgets' filter condition to OR
Dear @Moultrex , thank you for your help!
I've tried it but it' doesn't run. Maybe i did something wrong.
This is a filtered url before adding your snippet:
_https://www.website.com/shop/scarpe/?filter_numero=35_
@ifede84 Change $_GET['filter_megethos'] to $_GET['filter_numero']
Change attribute_pa_megethos to attribute_pa_numero
It still not running: this is the code i've added to functions.php
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_numero'] ) ) {
if(isset($_GET['filter_numero'])){
$destostock = $_GET['filter_numero'];
$array = explode(',', $destostock);
if (in_array($instockvar['attributes']['attribute_pa_numero'], $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_numero'], $array )&& ($instockvar['max_qty']>0)){
global $product;
$id = $product->get_id();
echo "<style>.post-$id{display: block !important}</style>";
}
}
}
}
}
}
}
Your attribute slung is numero? You have to put attribute_pa_insert-attribute-slung
Where did you put that code on child-theme? Or on main theme functions.php file?
I guarantee you it is working. Something is wrong on your end. Do you have additional snippets on custom functions enabled? What are your shop permalinks settings?
hello,
I have the same identical problem of ifede84, and the code doesn't work for me too...
@scoxnet Probably you have write the wrong attribute inside the code. Dm me your shop url to check how the filters work. We have this function in our shop and is working flawlessly
the website is pattyshoes.it
@scoxnet You can find the code for your store here
Add this code with a plugin like
>
Future is coming in 2019. The product custom tables are under development now and will be in WooCommerce 4.0. These should make it possible to do the sort of variation attribute filtering you are trying to do since attributes will have their own optimized database tables instead of the WP terms tables.
@claudiulodro Any idea when WOO 4.0 is goint to be released?
@Moultrex Sorry dude, i've tried many times, but your code still doesn't run. I've removed every other code from child functions.php, uncheck the "hide out of stock feature" and set filter size widgent on OR
This is the code i've added:
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_numero'] ) ) {
if ( ( $instockvar['attributes']['attribute_pa_numero'] == $_GET['filter_numero'] ) && (!$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>';
}
}
@ifede84
I don't know maybe you have any other custom modification or maybe your theme overrides the url and adds something else.
We have this code in our store and is working like it should be.
@Moultrex I double check the code, fix one error and now it's running :) The problem now is that are shown also out of stock items: is there any way to hide them?
@ifede84
Check again on woocommerce settings the option hide out of stock feature you have unchecked
EDIT: Sorry if you choose that option the whole product would be hidden although you have available variations. Leave it unchecked.
Can you explain when you select a variation that is out of stock what the shop page is showing?
Can you explain when you select a variation that is out of stock what the shop page is showing?
If hide of stock is unchecked: only shoes with chosen size on stock are shown
if hide of stock is checked: even shoes with chosen size out of stock are shown, despite your code
Can you explain when you select a variation that is out of stock what the shop page is showing?
If hide of stock is unchecked: only shoes with chosen size on stock are shown
if hide of stock is checked: even shoes with chosen size out of stock are shown, despite your code
If hide of stock is unchecked: only shoes with chosen size on stock are shown
Ok this is how it should work.
Hi
And a real big thanks for work and explainations about this huge problem.
You've understood I also have the exact same issue, and try to find the solution ; so I have tried @Moultrex code, but for now it doesn't work ; but I permit myself to post here to ask if i'm doing it well
my website : https://bellemme.com/
woocommerce : 3.5
theme : Xstore
1/ I have copied the code
2/ I have edited the code to replace atributes slung with the good info (in my case megethos > imprimes)
3/ I have pasted this code in the child theme functions.php
4/ I have unchecked the 'hide the out of stock' option in woocommerce
Is there anything i forgot to do ?
Regards !
ps i paste here my modified code
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_imprimes'] ) ) {
if(isset($_GET['filter_imprimes'])){
$destostock = $_GET['filter_imprimes'];
$array = explode(',', $destostock);
if (in_array($instockvar['attributes']['attribute_pa_imprimes'], $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_imprimes'], $array )&& ($instockvar['max_qty']>0)){
global $product;
$id = $product->get_id();
echo "<style>.post-$id{display: block !important}</style>";
}
}
}
}
}
}
}
@woolityourslef
Do you have the child theme enabled?
Does your url when you apply a filter look something like this?
On your attributes on wordpress admin page if you hover above the edit button do you see down left at the web page something like this on the url?
@woolityourslef
Try to add this code i make it on pastebin based on your attribute.
Remove yours first.
Thks again for your help @Moultrex !
to answer to your questions
the child theme is enabled
my urls do not change
here the hover attribut : https://prnt.sc/mqwzur
I have changed the code
regards
@woolityourslef
Do you have products that are out of stock to check it?
I had a demo of Xstore theme and try it. It works.
Remove the code from your child theme and use this plugin
https://wordpress.org/plugins/code-snippets/
Maybe you have some other code in functions.php file and is conflicting.
I can guarantee you the code works.
@Moultrex
you can see the an out of stock variation here : https://bellemme.com/produit/sac-rond-albertine ; where the term "bangalore" is out of stock (in the middle)
I try whith code snippets, and i believe you that it works, i'm only worried about my abaility to do it well ;)
@woolityourslef
But you don't have Widget Filter on your sidebar with the attribute to filter the products. You have the category filters only.
The out of stock swatch is not showing Out of stock message instead it shows a notification pop up
Sorry, no products matched your selection. Please choose a different combination
You have something not set right in your variations.
@Moultrex
I've seen your exemple, and that's effectivly exactly what i try to do (that and do not show the variations not available in the product detail page)
So i'm sure your solution could work, and that's only due to my settings ; I let you here a sample of a variation setting for an out of stock variation : https://prnt.sc/mr7d0p
Is there a mistake in it ? Should i configure it differently ?
Thanks again
@woolityourslef
The variation seems ok. Did you add on the sidebar the product filter for this attribute? I only see the category filter.
@Moultrex
sorry i hadn't save it :/ .. so know the attributes filter is on
ps : for example the "bangalore" term should not show the "sac rond albertine" product cause its out of stock
@woolityourslef
I think something is strange with your permalink structure. Normally after accessoires there must be a trailing slash /
Must be
https://bellemme.com/categorie-produit/accessoires/?filter_imprimes=bangalore&query_type_imprimes=or
But yours is
https://bellemme.com/categorie-produit/accessoires?filter_imprimes=bangalore&query_type_imprimes=or
Without the slash, maybe that's the problem.
@Moultrex
I see ... and do you think there is a way to "force" the permalink to this structure (with the "/") ?
@woolityourslef
Normally is on by default with the trailing slash, i try it with no trailing slash on my demo site and it still works.
Something is clearly misconfigured. Did you add the code in code snippets plugin and run it every where?
Maybe you have something else and it is conflicting. I don't know how you configured your site.
@Moultrex , once again huge thks for help, and time spent on my case !
I confirm i added the code (first removed manualy from the functions file) via Code Snippets, and checked the option "everywhere" (admin+website)
For a conflict, I have a classical configuration for catalog and products, but use obviously some plugin, one is related to variation, it is Smart Variation , it permits to manage an alternative galery for a variation
@woolityourslef
Can you temporarly disable this plugin to check how it works? Leave enable only the theme's vital plugins.
@Moultrex
done ;) .. the Smart Variation Images Pro is off .. but that do not solve it
I also have shut off some other plugin .. the on ly "heavy" plugin still on for the woocommerce management is Stripe
@woolityourslef
I still see the image swatches. Disable and the Free version of the plugin. The variations must be like a drop down selection like i saw you on our demo site.
@Moultrex
sorry at this step, i'm not sure my english is enough good to understand ... i have disabled the plugin (so no version is used, even not the free version) ..
or do you mean, i have to change setting of the widget for a drop down selection ?
@woolityourslef
I can still see the swatches
The default woocommerce plugin has something like that
@Moultrex
Is your screenshot made with a Xstore ? cause i thought it is my theme that sets the display of that .. i'm looking for a way on the theme options .. and let you know
@Moultrex
ok, i have discussed with the shop manager, and he needs that the attributes "imprimes" to be displayed by image and not by drop down area :/ .. so seems to be a dead end, isn't it ?
@woolityourslef
Sorry, i don't know what and how exactly you setup your store. The code you saw it works. Maybe your manager can tweak it to suit your needs.
@Moultrex
I'll ask for it ...and once again, thanks a lot for help ! I'll let you know if we work it differently. Or will wait for woocommerce 4, that could fix the problem
I'm struggling with this issue too. The code works, however; products that are filtered out with the css are creating white spaces. Any fix for this?
@Pixelstart i don't have any solution for your CSS. We use flexbox and everything is arragned normally. Try to implement a flexbox layout
Guys. @ifede84 is absolutely right @claudiulodro c'mon, we live in 2019. Fix this already. Still can't believe that such a huge community of developer can't seem to find a fix for a feature that is so important to shops.
A weird fix in this topic is not gonna fix the issue. This is a huge issue, see it through please. Give us an ETA so we can tell our clients what to expect.
Hi @Pixelstart , thanks for support. I've found a third part plugin that solve the issue, but i don't know if i can say the name here. Send me a private message :)
@ifede84
Can you share the name here to. Interested to know. Thank you.
Sure. It's a premium plugin, FACET WP ( https://facetwp.com/ )
You can see it running here, the widget is SCEGLI IL TUO NUMERO (choose your size) https://www.supermarketdellascarpa.com/shop/brands/scarpe-skechers-shop-online/
(if this post violates the netiquette, delete it and send me a pm)
Yes facetwp does the job have tested it too.
@ifede84 I'm about to test FacetWP. However, I just find it very absurd that WooCommerce doesn't come with a solution on something this basic.
They just want to sell own Product Filters plugin, thats all. I think that fix that known problem?
https://woocommerce.com/products/product-filters/?_ga=2.192635945.2083807797.1572010923-1736748441.1536312205
Its 2020 now. Is there any update?
I have shoes website where I have few product variations size:36-41. Each size has few products in stock. Is there any way to hide the variations that go out of stock in the drop-down list from front-end? There only 39 size has 1 product in stock others should be removed from the frontend because they haven鈥檛 any product in stock of these sizes[red marked].
Thanks
check the screenshots:
@khmahfuzhasan You should raise this issue here: https://github.com/woocommerce/woocommerce/issues/25524
I too landed here today searching for some solution to this nonsense!
I thought this was something I haven't configured correctly in woocommerce. I am glad I found this.
The people I work with find it incredible that I can't make woocommerce to filter products based on the sizes that are available in stock and hide the ones that have zero stock with backorders not allowed or are just out of stock.
It's essential for many shops having different sizes that people can filter through variations to find the ones available in stock.
Is there any news on this, is 2020? We should be thousands that could use this to work this way, currently there is no use for filters for these kind of shops. Woocommerce must notice this affect all these kind of businesses and in this cases now our websites don't perform as well as others due to this. I really hope this is on the works and is to be released soon.
@fedosh Amen. Please see https://github.com/woocommerce/woocommerce/issues/25524
Most helpful comment
I thought this was something I haven't configured correctly in woocommerce. I am glad I found this.
The people I work with find it incredible that I can't make woocommerce to filter products based on the sizes that are available in stock and hide the ones that have zero stock with backorders not allowed or are just out of stock.
It's essential for many shops having different sizes that people can filter through variations to find the ones available in stock.
Is there any news on this, is 2020? We should be thousands that could use this to work this way, currently there is no use for filters for these kind of shops. Woocommerce must notice this affect all these kind of businesses and in this cases now our websites don't perform as well as others due to this. I really hope this is on the works and is to be released soon.