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.

Still need help? Contact Us Contact Us