• Resolved whyess

    (@whyess)


    Is there a way to disable attributes based on the selection of the previous ones?

    Say I was selling packs of Windshield Wipers:

    [Vehicle]
    Car, Truck, Van
    [Color]
    Red, Green, Blue, Yellow
    [Size]
    One Size, Small, Big

    The idea would be to only be able to select [One Size] as a Size in Attribute 3 when [Van] is selected in Attribute 1, and also if [Truck] is selected as Vehicle then all colors are available except Yellow… Essentially what I’m looking for is that only displays attributes if it’s available to the prior Attribute, if through a plugin or otherwise, where I could (preferably in a bulk fashion) add:

    On (Truck): [ available COLOR – Red | Green | Blue ] [available SIZE – One Size | Small | Big

    On (Van): [ available COLOR – Red | Green | Blue | Yellow ] [available SIZE – One Size ]

    On (Car): [ all colors available ] [all sizes]

    Because basically going through the Variable Product page so far it seems I have to define EVERY SINGLE available variable combination which ends up being 100s of near-identical on some products, whereas I feel there’s more than likely a way to simply remove or disable those particular variations from the dropdown easier.

    As is currently, all options appear under all variations & attempts to add to cart.

    • This topic was modified 3 years, 10 months ago by whyess.
    • This topic was modified 3 years, 10 months ago by whyess.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello @whyess ,

    So, you are looking for a way to disable or hide the variation selection which is out of stock. Is that right?

    Out of the box, WooCommerce does not come with this feature however we can achieve the result using this custom code in your theme’s functions.php file or using a snippet plugin

    add_filter( 'woocommerce_variation_is_active', 'custom_grey_out_variations_out_of_stock', 10, 2 );
     
    function custom_grey_out_variations_out_of_stock( $is_active, $variation ) {
        if ( ! $variation->is_in_stock() ) return false;
        return $is_active;
    }

    I hope the information helps.

    Thank you ??

    Thread Starter whyess

    (@whyess)

    It’s basically trying to achieve the effect of either Setting the particular combination of variations to “disable visibility of Yellow as an option in [COLOR] dropdown once TRUCK is selected in [Vehicle] Option amongst another variation choice of ([Vehicle-Truck] [any] [any] $price)” in the Porduct Data menu of hte Product page, or swomehow removing from visibility any options that are not available for that selected Vehicle type.

    I just tried this code but I think the most that has been achieved is that the variations (Option Yellow is still visible when Truck is selected) are there, yet after attempting to Add To Cart an error message pops up saying “COLOR IS A REQUIRED FIELD” and it kinda glitches out sometimes (I also installed a piece of code I found that tries to hide “choose a product”-esque variables in the dropdown, but I’m sure this is having no bearing on the efficacy of the above-mentioned code).

    I appreciate the assistance still, in reading your code logically it seems it should work but i’m not seeing the change , maybe it’s just applying the changes slowly .

    Thread Starter whyess

    (@whyess)

    This is what I’ve tried so far because logically I thought this should do it, in order to reduce the number of Variables:

    View post on imgur.com

    Thread Starter whyess

    (@whyess)

    Sorry for the double post, was trying to remove the prior one

    This is what I’ve tried so far because logically I thought this should do it, in order to reduce the number of Variables:

    View post on imgur.com

    Still able to select the selection on it but getting “Out Of Stock” messages… Or maybe there is a bulk way to add it, as is “On [Option 1], display this array of attributes in [color] option, and in third option [size] only display (this array of attributes) based off the two prior selected options”, without having to do: [Car | Blue | Small] [Car | Red | Small] etc. until infinity!

    Helo @whyess ,

    I understand your end goal now.

    Let’s first figure out the current structure you have now. You are can get out of the stock message for several reasons –

    1. You have not set any price for these 3 variations
    2. In the inventory tab you have set quantity as 0 – https://prnt.sc/xig9c6
    3. In the individual variations you have selected “out of stock” – https://prnt.sc/xigatr

    Check the above options and you can fix the out of stock issue on variations.

    Now, going back to your original goal. I previously mentioned that WooCommerce is unable to hide attribute values based on the previous selection which was not accurate. Actually, your customer will not see a value of the attribute if the previous selection does not have a variation created with that.

    The actual setup you want to have without creating individual variation has some issues. In WooCommerce each variation is a kind of simple product having different prices and other options. Without creating the variation you are unable to set those.

    Instead of using variations when you have a long selection of item to select under a product you can use Composite Products extension to let the customer choose only the items you want to show. You can use conditional features here as well.

    Here is another good article about showing variations conditionally – Conditionally Displaying Fields Based on Product Variations

    I hope the information helps.

    Thank you ??

    Thread Starter whyess

    (@whyess)

    I must have no idea how either of these work… Is it that I must make Single Variable products, define the variables of each variance, and combine them through something like Composite Products? Because it seems completely unreasonable to need so much handwork just to add a third selector (I’m over 500 variants). I’ve also seen the “Hide unavailable options” tickbox amongst one of the two plugins, can’t remember now but even after checking that box the out-of-stock options are visible & now throw two variants of the error message upon selecting: One has the Woocommerce modal saying “SORRY, NO PRODUCTS MATCHED YOUR SELECTION. PLEASE CHOOSE A DIFFERENT COMBINATION.”, the other says a slight variation of the same message but without the Woocommerce modal box around it — I’m assuming that has to do with one of the plugin throwing its own errors…

    More efficiently, another platform allowed for entering [option1|option2|option3|price] with boolean in this simple way, defining the three categories & its order prior but able to add the varying combination of options in bulk (as in a non-accordion-expanding modal or simple view), is there a way to initiate that? Or am I missing something with either Extra Product Options or the Composite Products plugins that would allow that easily (I am looking at videos on Youtube but they are using a different context for what I thought could be a simple task)

    Hello @whyess ,

    Do you have a short example of the structure you are looking for?

    It will be easier for me to understand your use case if you can share a screenshot of your list of variations you want to create. You can keep the example short to 5-6 variations. I will try to reproduce and see if there are any better ways.

    In addition to my previous message, WooCommerce by default can hide unavailable variations options only up to 30 variations. To increase that you can see this documentation – Change Limit on Number of Variations for Dynamic Variable Product Dropdowns

    If you already have one of those extensions, you can also share your example with WooCommerce.com by creating a ticket and they can confirm if that’s possible.

    Thank you ??

    Thread Starter whyess

    (@whyess)

    Okay yes, I was missing something simply: Extra Product Options added a particular section to the New/Edit Product screen, with a tab entitled “Builder” where I was able to make the varying selections & price adjustments, & even add the boolean entries in bulk! Though some extra messages now showing up & extra prices/nags like multiple $price prints under the description (can’t find out what’s producing them) but I guess I can csshack my way around it! Thank you very much!

    I used WooCommerce Extra Product Options Pro to solve this issue from the advice provided by @rur165 at: https://themehigh.medium.com/conditionally-displaying-fields-based-on-product-variations-woocommerce-checkout-field-editor-44bf64c39a54

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Trying To Display One Variation Set Per Previous Selection’ is closed to new replies.