Very slow add_to_cart function
-
Hi !
I updated a website with woocommerce 2.1.12 (old one, yep)
I now have the latest Woocommerce and WordPress.To be sure, as we have a lot of custom edits in our theme, I used the twenty nineteen theme for the tests. I also disabled WPML as we use it.
The problem is that this simple function is slow as hell :
$product_id = 273; $quantity = 1; $variation_id = 4227; WC()->cart->add_to_cart( $product_id, $quantity, $variation_id);
This product have 11 variations.
I’m using microtime to measure the time it takes to add product on cart.
It can take 500ms when it’s fast (nice timing) but 9 times out of 10 it takes +/- 2seconds.
So, when we use that function with an ajax call, to add products on cart, it can take up to 5-6 seconds (!!) to see the cart updating value…In the js file I measured the 5-6 seconds delay right after this line :
$.post( wc_add_to_cart_params.ajax_url, parameters, function( response ) {
This is not a mysql problem, the query time is +/- 0.03seconds.
Any help ?
Thanks
- The topic ‘Very slow add_to_cart function’ is closed to new replies.