Swatches Are Not Being Disabled

It’s quite common that your products are not available in certain combinations, like a Blue XL, for example. Ideally, if the customer chooses Blue you’d want the XL swatch to be disabled.

However, if your AJAX variation threshold is too low, WooCommerce will allow you to select this swatch and then say “Sorry, no products matched your selection”.

This is caused when you have a large number of variations (usually more than 30) for your product.

WooCommerce will only load the variation data once you select all the options; it is at this point it finds out that variation is not available.

If you increase the AJAX variation threshold, all the variation data is loaded when the page loads. This means your swatches will be disabled before the user can click on them.

To increase the threshold, simply add the follow code to your theme using your preferred method, or the Code Snippets plugin.

function iconic_wc_ajax_variation_threshold( $qty, $product ) {
    return 50;

add_filter( 'woocommerce_ajax_variation_threshold', 'iconic_wc_ajax_variation_threshold', 10, 2 );

Set the return value to something higher than the number of variations your product has.

WooCommerce Attribute Swatches

Turn your WooCommerce product options into color, image, or text swatches. Instantly enhance your customers’ online experience.

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.