Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - Change ajax variation threshold
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
@guru75

This comment has been minimized.

Copy link

@guru75 guru75 commented Sep 25, 2018

not working on 200 variation product.

@guru75

This comment has been minimized.

Copy link

@guru75 guru75 commented Sep 25, 2018

This works for 200 variation product

function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 200;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 100, 2 );

@dnavarrojr

This comment has been minimized.

Copy link

@dnavarrojr dnavarrojr commented Apr 14, 2019

Not working in WordPress 5.1 and WooCommerce 3.5.7

@jcvikl

This comment has been minimized.

Copy link

@jcvikl jcvikl commented May 24, 2019

Do you generate new file under Woocoomerce plugin folder or you put code into functions.php themes file?

@ZanekShaw

This comment has been minimized.

Copy link

@ZanekShaw ZanekShaw commented Jul 5, 2019

Hey, I'm using the following code but it doesn't seem to work for me.
Any advice would be greatly appreciated.


/**
 * Change woocommerce_ajax_variation_threshold
 */
function custom_wc_ajax_variation_threshold( $qty, $product ) {
	return 200;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 100, 2 );

@VdVwebdesign

This comment has been minimized.

Copy link

@VdVwebdesign VdVwebdesign commented Jul 5, 2019

Hey, I'm using the following code but it doesn't seem to work for me.
Any advice would be greatly appreciated.


/**
 * Change woocommerce_ajax_variation_threshold
 */
function custom_wc_ajax_variation_threshold( $qty, $product ) {
	return 200;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 100, 2 );

I have the same problem.
Can anyone help us?

@claudiosanches

This comment has been minimized.

Copy link
Owner Author

@claudiosanches claudiosanches commented Jul 8, 2019

This code works just fine in WooCommerce 3.6.5.

@GoElemental

This comment has been minimized.

Copy link

@GoElemental GoElemental commented Nov 21, 2019

Code works great in WP 5.3

I have a product with 250 variations and used this code:
function custom_wc_ajax_variation_threshold( $qty, $product ) { return 300; } add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 100, 3 );

No problems whatsoever. Thank you Claudio!

@thefacc92

This comment has been minimized.

Copy link

@thefacc92 thefacc92 commented Dec 24, 2019

I'm new in this and have the same problem with 350+ variations.
Where can i put this code in?
Thank you btw.

@rajeshraval

This comment has been minimized.

Copy link

@rajeshraval rajeshraval commented Jun 22, 2020

add 1 value into backend

steps : WooCommerce Variation Swatches Settings --> advanced --> Ajax variation threshold add 1 value into it and everything works fine.

Thank you

@risingrun

This comment has been minimized.

Copy link

@risingrun risingrun commented Feb 9, 2021

I have lots of 7 attributes with lots of options I mentioned bellow.

The first attribute has 7 option
The 2nd attribute has 4 option
The 3rd attribute has 15 option
The 4th attribute has 20 option
The 5th attribute has 20 option
The 6th attribute has 20 option
The 7th attribute has 3 option

7x4x15x20x20x20 = 10080000 variation. How do I made those variations? Anybody can help me?

@AhmadDastageer

This comment has been minimized.

Copy link

@AhmadDastageer AhmadDastageer commented Mar 26, 2021

I have a product with 1680 variations. How to resolve site speed?

@Propelevate

This comment has been minimized.

Copy link

@Propelevate Propelevate commented May 9, 2021

risingsun and AhmadDastageer:

That is definitely too many variations. This will slow your site down way too much probably. I would recommend using Gravity Forms for WooCommerce. Then your users are just filling out a form instead of choosing from a huge list of options. You do loose some other cool functionality like showing swatches for product colors, or specifying images for certain selections, but I'm guessing with that many options, you aren't using features/plugins to do those things anyway.

The other options is to split out your variations into multiple products. Not sure if this is logical for your products, but you definitely need to bring that number way down.

I sell customizable apparel on WooC, so I literally have unlimited variations. I can then just create the one item and add the Gravity Form. It will even let you adjust the price based on options chosen in the form. all the options are recorded with the order and very easy to use. Very cool!

If you need to try Gravity Forms before buying a license, you can get the current open source copy here

I have a product with 1680 variations. How to resolve site speed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment