0

I’m running into a bit of a strange (to me) situation, and would appreciate help. I’m not even entirely sure that this is the right forum to ask for help, so pointers somewhere else would be great if there’s a better place.

I have WP with WooCommerce installed, and it’s been working great for a couple of years. In the last little while (month? – not quite sure when this started), the WooCommerce cart widget has not been updating when a customer adds a product to their cart.

This can be seen on the following page (https://adventuretaco.com/product/tacoma-to-tundra-hard-brake-line-kit/) by

  1. Open browser developer tools and switch to the Networking tab

  2. Click the Add to Cart button Edit/update: ==> Page reloads as expected

  3. Watch the “cart” widget on the right and note that it does not update

  4. As the page is reloading and loading all resources, watch the browser dev tools, and look for the request to https://adventuretaco.com/?wc-ajax=get_refreshed_fragments

  5. The result is that it is always cut off after exactly 5 seconds. (or 5.01/5.02 seconds).

REPRO 2:

  1. Open browser developer tools and switch to the Networking tab
  2. browse to https://adventuretaco.com/minimal
  3. watch the browser dev tools, and look for the request to https://adventuretaco.com/?wc-ajax=get_refreshed_fragments

Because the response doesn’t come back in that time, the cart never updates. However, direct requests (non-AJAX) to that URL do return correctly (after more than 5 seconds) with the correct cart data.

Why is this request getting cut off? The answer might be in the browser dev tool data, but I don’t see it (or know what I’m looking for).

I’m not sure if it matters, but the backend is linux/nginx.

Thanks!

Dan
  • 123
  • 11
  • 1
    The ajax request gets cancelled (note, not timed out!) because your entire page gets refreshed and reloaded from the server. So somewhere you're not preventing a default form submission when the Add to Cart button is pressed (notice in the Network too, the first request after the button press is a non-XHR request to tacoma-to-tundra-hard-brake-line-kit/, followed by a whole pile of reuqests to reload the rest of the site's assets, just like when the page was originally loaded). – ADyson Jun 21 '23 at 15:45
  • 1
    Provide a [mre] of the issue here in the question if you want to get a formal answer. (see also [Something in my web site or project doesn't work. Can I just paste a link to it?](https://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste-a-link-to-it) and [ask]). But essentially you probably need to use [preventDefault](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) in the right place in the JS code. – ADyson Jun 21 '23 at 15:47
  • This thread can help: https://stackoverflow.com/questions/76495561/woocommerce-mini-cart-is-coming-blank-on-add-to-cart-from-product-page – LoicTheAztec Jun 21 '23 at 17:00
  • Thanks @ADyson, the clarification of cancelled/timed out is a good one. Note however that the entire page being refreshed is expected, and it is *when the page reloads after the refresh,* that the AJAX call is cancelled after 5 seconds. Or, are you saying that the cancelled call is one from *before* the refresh, that then shows up in the network trace *after* the refresh as other resources are being loaded? – Dan Jun 22 '23 at 01:23
  • @LoicTheAztec - thanks, but I'm using a theme that does not disable the cart fragments, and it is the exact call that is shown in the other thread that is being cancelled/not completing for me. – Dan Jun 22 '23 at 01:25
  • 1
    @ADyson - I've created a page that is a minimal repro. I can't paste the code here, as this is happening as part of the Wordpress "flow" but this page has essentially no content on it except for the WooCommerce Mini-Cart. Simply loading the page with the Network tab of browser dev tools up shows the behavior I mentioned. There's no need to click a button/submit a form/etc. The request is - for some reason - cancelled after 5 seconds. https://adventuretaco.com/minimal/ – Dan Jun 22 '23 at 03:48
  • That `?wc-ajax=get_refreshed_fragments` is known to cause performance issues, https://www.webnots.com/fix-slow-page-loading-with-woocommerce-wc-ajaxget_refreshed_fragments/ Do you have any "performance enhacing" plugins in use? One of those might perhaps deliberately set a low timeout for this AJAX request. – CBroe Jun 22 '23 at 08:35

0 Answers0