Modify the Ajax Variation Threshold

When your variable product has more than 30 variations, WooCommerce starts to use ajax to load your selected variation. This changes the way the dropdown fields work – where before you could select some options and others would become unavailable/disabled, now you have to select all options before finding out the variation you selected is not available. You may have noticed this when using our WooCommerce Attribute Swatches plugin to change your product dropdowns into graphical swatches.

Fortunately, as with most things WooCommerce, you can modify this setting. Try adding this to your theme’s functions.php file:

This means ajax will only kick in when there is more than 50 variations. You can adjust this accordingly.

You could also use the $product object to do this for a specific product only. Very useful!


  1. Reuben says:

    Thanks for this, 1 follow up question. How do I only apply this to certain products, like you mentioned is possible? Thanks

    • James Kemp says:

      Hey, sorry – didn’t see the comment come in! Inside the function you can use the $product variable to check the ID:

      if( $product->get_id() !== 42 ) {
      return $qty;

      return 50;

      This would return the normal qty for all products where the ID *is not* equal to 42, otherwise, return 50.

      Better yet, use the product ID to fetch a meta field, then you can tick/untick this in the backend of WordPress on a per-product basis.

      • Arnim Pommeranz says:

        Hi James, thank you for this great solution, that save me really. Unfortunately, it also has a disadvantage. It takes much longer to put the product in the shopping cart. Could you please explain your suggestion “Better yet, use the product ID to fetch a meta field, then you can tick / untick this in the backend of WordPress on a per-product basis.”? Best with code example.

        Many Thanks!

  2. Websites Templates says:

    Thanks for this. I really great.. I was working last couple of hours but not find the issue then I found this and it’s save my time thanks…

  3. eleni says:


    any screenshot how to become with the custom?

  4. Debora says:

    Thanks for this.

  5. Rajendra Banker says:

    Thanks very much, it is working fine for me as well!

  6. stefano says:

    hi, what is the function of the digits 10 and 2 at the end of the string?
    many thanks

  7. Faizan says:

    Do you think it’ll have any performance benefits for small sites with a few variations?

  8. antonella says:

    Hi, I used your code and it works perfectly! Only on some products it does not seem active … they have 225 variants and I changed the return 200 code to return 230, but it still doesn’t work … where can the problem be?

Leave a Reply

Your email address will not be published. Required fields are marked *