• We’re currently developing a website where products can have lots of variations (around 400 variations per product).

    I’ve found that on the product category pages, the load time of the page is very slow (10-20 seconds). We have it set to 30 products per page. When you click on the pagination and go to page 2, 3, 4, etc the load time is also slow.

    However, second time around, when you look at the same pages it loads quickly (1-2 seconds).

    I notice that if I clear all transients, the issue returns. So I believe that on the product category pages, Woo is delving into each product and looping through the variations, perhaps to find the smallest price or for some other reason, and then caching the values in transients.

    Is this a known issue when using lots of variations? I tried enabling object cache and also page cache, but obviously these things don’t help when it’s time for the cache to be cleared and Woo repeats the above process.

    Thanks,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hey @1stwebdesigns,

    Handling products with a large number of variations can really slow things down. Some users have been able to speed this up a bit by increasing the max_imput_vars on their servers.

    https://docs.woocommerce.com/document/problems-with-large-amounts-of-data-not-saving-variations-rates-etc/#php-539-and-max_input_vars

    It may be helpful to see if you can break some of these product variations out into separate products. That would decrease the number of variations per product and speed up the site.

    In some cases, people have skipped variations altogether and used “Add-ons” as a way of giving customers the same options without the speed penalty.

    If you have any questions, please let us know.

    Thanks!

    Thread Starter 1stwebdesigns

    (@1stwebdesigns)

    Thanks for your reply, we looked at splitting the products up, and also the Product Add-ons plugin, but neither of these solutions were suitable in our case.

    We’ve already increased the maximum input vars, time limit and memory allocation, but the problem remains that the initial product category page loads are slow.

    Thanks for giving those changes a try. The next step might be to use a system that can automatically rebuild the cache when it expires. That way it would lessen the chances that a customer visits a page that doesn’t have cache ready to go.

    Thread Starter 1stwebdesigns

    (@1stwebdesigns)

    Thanks. I’m not sure how we’d go about this though.

    There is something else… for these particular products we don’t need to show the price on the product category page. I’m assuming Woo is looping through each variant within each product to get the smallest product price (and perhaps other things I’m not aware of) and then caching them in transients.

    Is there any way of preventing it from doing this? I already removed the item price from the action hook, which removed the price but didn’t resolve the issue. But I’m thinking if it is looping through the varations to find the smallest price, we don’t actually need it to do this since we don’t want to show the item price on the product category page anyway.

    I haven’t tested to see what all is loaded there. I know it also checks the stock status of the variations. That’s part of what takes so long. It’s one of the main reasons why add-ons can be so much faster than variations. They don’t have stock levels like variations can.

    I would suggest reaching out to the WooCommerce Slack Community. There are lots of developers there who offer advice and suggestions to one another. It would be a good place to get some additional perspectives on how to approach this and possible remedies.

    https://woocommerce.com/community-slack/

    Thread Starter 1stwebdesigns

    (@1stwebdesigns)

    OK, here’s what I’ve done to resolve the issue:

    1. I copied the template content-product.php to our theme directory and changed the opening product tag from:

    <li <?php wc_product_class( '', $product ); ?>>

    To:

    <li class="product">

    The above means it no longer needs to check the variations to see if they’re in stock.

    2. Then, I removed the prices from the product category page and replaced them with a custom price note field:

    
    add_action( 'woocommerce_before_shop_loop_item', function() {
    	global $product;
    	if ( $product->is_type( 'variable' ) ) {
    		remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
    		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    		add_action( 'woocommerce_after_shop_loop_item_title', 'custom_price_text', 10 ); // Have some custom text, instead of the price
    	} else {
    		add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
    		add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    		remove_action( 'woocommerce_after_shop_loop_item_title', 'custom_price_text', 10 );
    	}
    }, 10);
    

    We have a rather unique situation where on the product category page we don’t need to display the price. Obviously for most installs that wouldn’t be a practical work-around.

    3. Finally, the list of products in the admin area was also slow, so I removed the price and stock columns from the admin:

    
    add_filter( 'manage_edit-product_columns', function( $columns ) {
    	unset( $columns['price'] );
    	unset( $columns['is_in_stock'] );
    	return $columns;
    }, 10, 1 );
    

    Unfortunately I couldn’t find a way yet of selectively disabling the data in the price and stock column only when it’s a variable product.

    These changes have resulted in a massive speed increase. Do they seem reasonable, or am I overlooking anything?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Slow transient updates when using lots of variations’ is closed to new replies.