Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save arfinmilondev/dac93a345dff60da0978df8af2d34728 to your computer and use it in GitHub Desktop.

Select an option

Save arfinmilondev/dac93a345dff60da0978df8af2d34728 to your computer and use it in GitHub Desktop.
Increase the default number limit of variations for a product in WooCommerce
<?php
add_filter( 'woocommerce_ajax_variation_threshold', function(){
return 100;
});
// Add this code to your function.php file
add_filter( 'woocommerce_ajax_variation_threshold', function( $quantity, $product ) {
return 50;
}, 10, 2 );
/*
In that code, we’re just returning a new quantity of 50 for the maximum value allowed for variations.
If you wanted to do this for just a single product, here’s what that would look like:
================================================================================================
*/
add_filter( 'woocommerce_ajax_variation_threshold', function( $quantity, $product ) {
// If you want change the default limit for just one product, set the ID here:
if ( 401 === $product->get_id() ) {
return 100;
}
}, 10, 2 );
/*If you have any questions or suggestions for improvements, let me know!*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment