• Resolved Janis Ozolins

    (@janisozolins)


    So basically I have two attributes to my variable product:

    Type: A and B

    Colour: for type A they are Red, Blue, Yellow; for type B they are Green and Pink

    However, in the dropdown list of variable, if I select any of the product types, the “Colour” dropdown will have all 5 colour options, even the ones that are not compatible with that particular variation. They can be selected, too. But it will cause error if user tries to add non existing variation to the cart.

    How can I make sure that only the available variation colours are showing in the “Colour” dropdown list? In my case, if I select type A, only Red, Blue, Yellow will be available but if I select B, only Green and Pink options available?

    • This topic was modified 8 years, 9 months ago by Janis Ozolins.
Viewing 15 replies - 1 through 15 (of 23 total)
  • I have the same Problem here.

    Its confusing for the user. The user can’t know which combinations are avialable and which not…

    @janis
    Did you simplify the question? The variations threshold is usually 30. If the number of variations is less than the threshold, the customer is only able to select available variations. If the number of variations is greater than the threshold, the customer may get the unavailable variation message. There’s a short code snippet on github to change the threshold.

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi there!

    Lorro is correct! There is a cut off at pre-loading 30 variations: https://github.com/woocommerce/woocommerce/blob/657c312caeef7345b225ffb899da6dbb84692936/includes/wc-template-functions.php#L1027)

    In the front-end, if a variable product has more than 30 variations, the data will be loaded via AJAX rather than handled inline. It is possible to change this quantity using the woocommerce_ajax_variation_threshold filter and can be used like so:

    add_filter( 'woocommerce_ajax_variation_threshold', 'wc_ninja_ajax_threshold' );
    function wc_ninja_ajax_threshold() {
        return 150;
    }

    The default variation threshold in the following code is 150 — you can change this value to be more if you’d like.

    Also, this custom code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as Code Snippets. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

    Cheers!

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

    Thank you for posting this limitation and fix! We have a product that had 44 variations and we were scratching our heads why it wasn’t showing the matched variation options. Once I added your function, it worked like it should. Cheers!

    darrie91

    (@darrie91)

    Hi, I’m encountering this issue too. But I do not have any background on coding.
    Does anybody has the step to step guide or video guide on this threshold code?

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy, @darrie91!

    You can add that very same code to your site via a plugin, like Code snippets found here: https://wordpress.org/plugins/code-snippets/

    I’ve outlined the steps to add code using that plugin, here:

    http://rynaldostoltz.com/how-to-add-custom-code-to-your-woocommerce-wordpress-site-the-right-way/

    Cheers!

    darrie91

    (@darrie91)

    SUCH A BIG HELP!

    THANKS A LOT!

    This code I used and it was success but it calls for both the button attributes can we use this hide for only one attribute
    Check this link
    http://media3devserver.com.cp-45.webhostbox.net/wpteam2/neorest/product/orthopedic-memory-foam-mattress-72306inch-182-976-215-2cm/

    @rynald0s This filter has sorted an issue I’ve been trying to crack for days!

    Many thanks.

    Can someone help me with this I tried adding this code and it is not working. I also have no background in coding. I have a child theme setup.

    @mirrorlure7m
    There are different ways. Try putting it in functions.php for your child theme:
    wp-content/themes/my-child-theme-name/functions.php

    Use a plain text editor, not MS Word or similar which would add unwanted formatting information.

    The first line in the file should be to turn on php:
    <?php

    Ensure any quotes in the code are straight quotes not curly or smart quotes.

    Then copy and paste the whole contents of functions.php here to validate the code:
    http://phpcodechecker.com/

    @lorro Thank you. I got it all worked out thank you for your help. I really appreciate it!

    unfortunately the snippet doesn’t prevent Variable products showing all possible product combos. What could be the reason for that?

    I tried this fix as my first ever time using Code Snippets. I pasted the exact code in a clone of the example HTML snippet and it worked right away.

Viewing 15 replies - 1 through 15 (of 23 total)

The topic ‘Variable products showing all possible product combos (even nonexisting)’ is closed to new replies.