woocommerce_ajax_variation_threshold
Allows you to change the variation-count threshold after which product variations are loaded via AJAX rather than immediately.
Default behavior:
-
If there are < 30 variations:
- The drop-down lists (such as “Color” and “Size”) are dynamic.
- After selecting one attribute, the others update through AJAX and show only available options.
-
If there are ≥ 30 variations:
- The drop-down lists are static — they show all options, including unavailable ones.
- Selecting an unavailable combination shows an error message: “Sorry, no products matched your selection. Please choose a different combination”.
This limitation is intended to optimize performance on sites with many variations.
This filter lets you change the limit from 30 to another number, for example, 100:
add_filter( 'woocommerce_ajax_variation_threshold', fn() => 100 );
Usage
add_filter( 'woocommerce_ajax_variation_threshold', 'wp_kama_woocommerce_ajax_variation_threshold_filter', 10, 2 );
/**
* Function for `woocommerce_ajax_variation_threshold` filter-hook.
*
* @param $30
* @param $product
*
* @return
*/
function wp_kama_woocommerce_ajax_variation_threshold_filter( $30, $product ){
// filter...
return $30;
}
- $threshold(int)
- Maximum number of variations to load upfront.
- $product(WC_Product)
- Product object.
Examples
#1 Change the number of product variations displayed at once
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 40;
}Where the hook is called
woocommerce_ajax_variation_threshold
woocommerce/includes/wc-template-functions.php 2240
$get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );