Home Forums WoodMart support forum Hide out of stock variations in filter

Hide out of stock variations in filter

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #632375

    produto
    Participant

    I 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.
    #632503

    Hello,

    Navigate to WooCommerce > Settings > Products > Inventory and enable the option “Hide out of stock items from the catalog”.

    Best Regards

    #632613

    produto
    Participant

    This option is already enabled

    #632683

    Hello,

    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

    #633258

    produto
    Participant

    Of 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.
    #633469

    Hello,

    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

    #633630

    produto
    Participant

    Hi!

    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

    #633776

    Hello,

    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

    #633977

    produto
    Participant

    But 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.
    #634147

    Hello,

    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.jpg

    Let me know if you need further help!

    Best Regards

    #636408

    produto
    Participant

    My 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?

    #636487

    Hello,

    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,

Viewing 12 posts - 1 through 12 (of 12 total)