Home › Forums › WoodMart support forum › Hide out of stock variations in filter
Hide out of stock variations in filter
- This topic has 11 replies, 2 voices, and was last updated 1 month ago by
Aizaz Imtiaz Awan.
-
AuthorPosts
-
January 24, 2025 at 6:43 am #632375
produtoParticipantI have this problem with the product filter. It is returning variations that do not have stock.
I need to only show attributes that contain stock of the product in the filter.
Attachments:
You must be logged in to view attached files.January 24, 2025 at 3:28 pm #632503
Aizaz Imtiaz AwanKeymasterHello,
Navigate to WooCommerce > Settings > Products > Inventory and enable the option “Hide out of stock items from the catalog”.
Best Regards
January 25, 2025 at 12:04 am #632613
produtoParticipantThis option is already enabled
January 25, 2025 at 11:55 am #632683
Aizaz Imtiaz AwanKeymasterHello,
Sorry to hear about the inconvenience. Kindly, please share your Site WP-ADMIN Login details in the Private Content field so that we can check this concern on your Site and help you out accordingly.
Best Regards
January 27, 2025 at 10:01 pm #633258
produtoParticipantOf course, to access this test site, you need to access it through the hostinger panel. I’ll give you the login. Just don’t publish the changes to the staging site
Attachments:
You must be logged in to view attached files.January 28, 2025 at 2:27 pm #633469
Aizaz Imtiaz AwanKeymasterHello,
Please add the code in the functions.php file in your child theme:
add_filter('woocommerce_product_attribute_query', 'filter_attributes_by_stock', 10, 2); function filter_attributes_by_stock($query_args, $taxonomy) { global $wpdb; // Join the term relationships with product variations $query_args['join'] .= " INNER JOIN {$wpdb->prefix}term_relationships AS tr ON tr.object_id = p.ID INNER JOIN {$wpdb->prefix}woocommerce_product_meta_lookup AS stock ON stock.product_id = p.ID "; // Add condition to filter only in-stock variations $query_args['where'] .= " AND stock.stock_quantity > 0"; return $query_args; }
After adding the snippet, go to Settings > Permalinks in your WordPress admin and click Save Changes.
Best Regards
January 28, 2025 at 9:21 pm #633630
produtoParticipantHi!
I’ve added the script in the functions.php of the theme and save changes in permalink but didn’t work… The issue stay the same
January 29, 2025 at 1:06 pm #633776
Aizaz Imtiaz AwanKeymasterHello,
Navigate to the product edit page, go to the “Variations” tab, select the desired variation, and then set its “Stock Status” to “Out of Stock” and check the variation on the shop page.
Best Regards
January 30, 2025 at 12:18 am #633977
produtoParticipantBut these out-of-stock variations (all those that are appearing as text, without a defined color) are appearing in the filter even if there is no product with these colors registered. Take the product in the print I’m going to send as an example, it only has the colors beige, navy blue and black registered, but even when I filter the “YELLOW/RED” variation it appears as if it had this color registered, but it doesn’t.
-
This reply was modified 1 month, 1 week ago by
produto.
Attachments:
You must be logged in to view attached files.January 30, 2025 at 2:56 pm #634147
Aizaz Imtiaz AwanKeymasterHello,
It looks like the attribute terms are still linked to the product even though there are no variations in stock. Try going to Products > Attributes, select the attribute, and remove any unused terms.
Also, try to use the disabled swatch style, Navigate to Products > Attributes > edit attribute > Choose the disabled swatch. So, you need to have the variant of the Product not checked with the Enable option on it and then the Disabled Swatch style will work accordingly.
See these images for reference:
https://snipboard.io/BMehIF.jpg
https://snipboard.io/NbOzfP.jpgLet me know if you need further help!
Best Regards
February 7, 2025 at 6:24 pm #636408
produtoParticipantMy woocommerce is linked via REST API to my ERP system, so all registered attributes and products are imported directly from my system. So, by default, when a product is registered, it uploads all the terms of the color attribute, but it only leaves ACTIVE the colors that the product actually has (like the example I gave you of the previous product, it has the color attribute registered with all the terms, but the colors available are actually only those 3, beige, navy blue and blue).
I can’t do what you suggested of deleting the terms that the product doesn’t use, because first, since it’s integrated with my system, the products are updated all the time… And second, because there are more than 100 products.
It took me a while to answer because I was searching the internet all that time for a solution… I even found some people with the same problem, some managed to solve it via script, I tried using it but it seems that after there was a Woodmart update it stopped working…
It’s from this topic: https://xtemos.com/forums/topic/filter-attributes-dont-show-out-of-stock-variations/
Is there any other solution?
February 8, 2025 at 10:11 am #636487
Aizaz Imtiaz AwanKeymasterHello,
Sorry to say that but it is not our theme issue. it requires customization and is beyond our support policy. Additional code customizations are out of our theme support scope.
Hope you can understand!
Best Regards,
-
This reply was modified 1 month, 1 week ago by
-
AuthorPosts
- You must be logged in to create new topics. Login / Register