Change Limit on Number of Variations for Dynamic Variable Product Dropdowns in WooCommerce

By default, if a Variable product has fewer than 30 variations, the dropdowns for selecting variations on the frontend will be dynamic. For example, with a T-shirt that has “Size” and “Color” attributes, after the customer selects a Size, the Color dropdown will be updated via AJAX to only display options that are available with the chosen Size.

However, if there are more than 30 variations, the dropdowns will be static and will display all attributes. Following the example above, if the T-shirt has more than 30 variations, the Color dropdown will continue showing all of the color options even if they are not available for the selected Size. Instead, after they select an unavailable combination, they will see the message “Sorry, no products matched your selection. Please choose a different combination.”

This is done to improve performance on the site. For large numbers of variations, if it has to calculate the available combinations after each selection, it can slow things down quite a bit.

However, this limit can be changed from 30 to another number if desired using the woocommerce_ajax_variation_threshold filter.

function custom_wc_ajax_variation_threshold( $qty, $product ) {
	return 10;
}

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

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Dessky Snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be overwritten completely when you update the theme.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...Loading...
Oopps, sorry. This discussion is closed.

If you are a paying customer and you are looking for Tech Support please post a ticket on our Support Tickets page and we will respond promptly.

If you are not a paying customer and you would like to post a pre-sale question or a quote request please use our Contact form.

Why did we close the discussion?

Many of the customers started reporting issues as comments instead of the ticketing system and this started delaying our response time.

We are making this change to serve our customers better. We have ramped up our support team and we are trying to get the reply out on the same day.

Thanks for understanding.

eisenberger budreau@mailxu.com ahalt@mailxu.com