Viewing 7 replies - 1 through 7 (of 7 total)
  • Just started having a problem with the cart being cleared, too. Commenting to get updates in this thread. Will post her if I find a solution.

    1) wc_session_cookie no longer exists in WC2.1, which “will be released shortly” – https://github.com/woothemes/woocommerce/issues/3513

    2) modification for your Varnish VCL – https://docs.woothemes.com/document/configuring-caching-plugins/

    Thanks for the link to github issue!

    Commenting to get updates in this thread.

    You don’t have to. There is a “Subscribe to Topic’ link at the right side-bar on all topics.

    You don’t have to. There is a “Subscribe to Topic’ link at the right side-bar on all topics.

    I didn’t know about that (or forgot) – thanks!

    Documentation on WooCommerce (linked above) doesn’t work for AJAX shopping carts. I struggled for a while with AJAX “add to cart” functionality in all browsers. I found I had to use “pipe” to appease some browsers (FF + XP, Safari + iPhone) for AJAX to work. Not sure why.

    Season to taste:

    backend default {
      .host = "127.0.0.1";
      .port = "8080";
    }
    
    sub vcl_recv {
      if (req.request != "GET" &&
          req.request != "HEAD" &&
          req.request != "PUT" &&
          req.request != "TRACE" &&
          req.request != "OPTIONS" &&
          req.request != "DELETE") {
        return (pipe);
      }
      # don't cache POSTs
      if (req.request == "POST") {
          return (pipe);
      }
      # don't cache for users logged into WP backend
      if (req.http.Cookie ~ "wordpress_logged_in_") {
          return (pipe);
      }
      if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php" ) {
          return (pipe);
      }
      # don't cache ajax requests
      if (req.http.X-Requested-With == "XMLHttpRequest") {
          return (pipe);
      }
      if (req.url ~ "^/(cart|my-account|checkout|addons|sitemap)") {
        return (pipe);
      }
      if (req.url ~ "/feed/") {
        return (pipe);
      }
      unset req.http.cookie;
      return (lookup);
    }
    
    sub vcl_fetch {
      if (beresp.status == 404) {
        set beresp.ttl = 0m;
        return (hit_for_pass);
      }
      unset beresp.http.set-cookie;
      set beresp.ttl = 60m;
      return (deliver);
    }
    
    sub vcl_deliver {
        if (obj.hits > 0) {
            set resp.http.X-Cache = "HIT";
        } else {
            set resp.http.X-Cache = "MISS";
        }
    }
    
    sub vcl_pipe {
      set bereq.http.connection = "close";
    }

    Works for me! What means the “set beresp.ttl = 60m;” ?

    @yolabingo thanks, your config works!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocommerce and Varnish cache’ is closed to new replies.