Documentation

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.

Are you using WooCommerce Attribute Swatches yet?

Start your 14-day free trial right now and get instant access to the features described in this article.

or learn more

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.

WooCommerce Attribute Swatches

WooCommerce Attribute Swatches

Not got the plugin yet? Get instant access right now, free for 14 days.

or learn more

Still need help?

If you haven't found what you're looking for in our documentation, please contact support.

Get Support