skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    So, I don't have a "real" answer to this, but in case others have the same issue and stumble on this question that I asked, my solution was not what I expected, but more than I hoped for.

    I moved from Azure (where I was running Wordpress on Linux with Flexible MySQL) to AWS (where I'm running a Lightsail WP instance and a Lightsail MySQL database).

    Cost is about the same per month - as of this answer, in the $20 range - but holy smokes is the AWS platform so much more performant.

    Not just this call for the WC cart, but everything on my site is orders of magnitude faster. Almost feels like I don't need a caching plugin, though I continue to use one as it's clearly good practice.

    Migration was easy as well - just used MySql Workbench to copy over the database, and then FTP to grab the wp-content directory. Was up and running in less than a few hours, and it was a simple DNS change to point the domain to the new IPs.

    Hope this helps anyone else considering perf on Azure.


  2. As noted by the comments on the first question, the cancellation doesn’t timeout, it get’s cancelled, which means, that we can safely assume, that it happens on the client-side.

    So I searched for somewhere this timeout is set on the client side, and as of woocommerce 8.3.0, in wp-content/plugins/woocommerce/includes/class-wc-frontend-scripts.php you have a method called get_script_data($handle), which includes a case for wc-cart-fragments:

    case 'wc-cart-fragments':
        $params = array(
            'ajax_url'        => WC()->ajax_url(),
            'wc_ajax_url'     => WC_AJAX::get_endpoint('%%endpoint%%'),
            'cart_hash_key'   => apply_filters('woocommerce_cart_hash_key', 'wc_cart_hash_' . md5(get_current_blog_id() . '_' . get_site_url(get_current_blog_id(), '/') . get_template())),
            'fragment_name'   => apply_filters('woocommerce_cart_fragment_name', 'wc_fragments_' . md5(get_current_blog_id() . '_' . get_site_url(get_current_blog_id(), '/') . get_template())),
            'request_timeout' => 5000,
        );
        break;
    

    Which has 'request_timeout' => 5000,

    Be aware that this is probably a performance parameter set by woocommerce intentionally, so the best solution is still to fix your site’s responsiveness. However, if you want to change it, I have two suggestions:

    1. Since I only experience this during development, I have just modified the file directly on my local wordpress instance. In this case I won’t accidentally push the code to production.
    2. If you actually need to change this timeout setting, you should do it through a filter instead. In the end of the above method, you have a line return apply_filters('woocommerce_get_script_data', $params, $handle);, so you can add a filter like this:
    add_filter('woocommerce_get_script_data', 'custom_woocommerce_get_script_data', 10, 2);
    function custom_woocommerce_get_script_data($params, $handle)
    {
        if ($handle === 'wc-cart-fragments') {
            $params['request_timeout'] = 10000;
        }
        return $params;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search