Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Last active November 22, 2023 06:17
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save claudiosanches/6f91ad228c2176b986b2 to your computer and use it in GitHub Desktop.
Save claudiosanches/6f91ad228c2176b986b2 to your computer and use it in GitHub Desktop.
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 );
@Propelevate
Copy link

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?

@brunelu
Copy link

brunelu commented Apr 29, 2022

Hello Claudio,

Thank you for sharing this useful snippet - way better than the standard approach.
Do you know if there is a way to have Amazon's behavior instead?

So instead of showing "Sorry, no products matched your selection. Please choose a different combination.", to have the option to see the available options:
image

Here's the listing I am referring to:
https://www.amazon.com/OULUOQI-Stainless-Magnetic-Replacement-iWatch/dp/B099JF5S9Z/
Thank you!

Regards,
John

@nonye924
Copy link

nonye924 commented May 1, 2023

Product page is not loading after making changes to the product variation

The product page is not saving after i make changes to the product variation. I have more than 100 variations
I have attached a video. The cache has been cleared and the issue is still the same.

http://www.colourwarehouse.com/wp-content/uploads/2023/05/www_screencapture_com_2023-5-1_08_44.mp4

@impetudigital
Copy link

It worked correctly for 100 variations.
To be cautious and not to touch the "functions.php" file, I inserted this code through the WP Code plugin.

Thank you very much!

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