title: WooCommerce: Mini cart in header seems to be cached
body: <p>I've been tearing my hair out over this for two days, and every time I think I've solved it, it just pops up again.</p>
  
  <p>In my <code>header.php</code> I have the following code for displaying the number of items in the cart, and a simple show/hide div displaying the items themselves, along with a total:</p>
  
  <pre><code>&lt;a id="miniart" href="&lt;?php echo WC()-&gt;cart-&gt;get_cart_url(); ?&gt;" class="cart icon red relative"&gt;
      &lt;div class="number bold"&gt;
          &lt;?php echo sprintf('%d', WC()-&gt;cart-&gt;cart_contents_count); ?&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          &lt;?php returnIcon('cart');   // This function simply displays an inline SVG  ?&gt;
      &lt;/div&gt;
  
      &lt;div id="cartcontents"&gt;
          &lt;div class="widget_shopping_cart_content"&gt;
              &lt;?php woocommerce_mini_cart(); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>I also have a filter to return the cart fragments via AJAX when a new item is added:</p>
  
  <pre><code>function woocommerce_header_add_to_cart_fragment($fragments) {
  
      ob_start();
  
      ?&gt;
          &lt;div class="number bold"&gt;
              &lt;?php echo sprintf('%d', WC()-&gt;cart-&gt;cart_contents_count); ?&gt;
          &lt;/div&gt;
  
      &lt;?php
  
      $fragments['#minicart .number'] = ob_get_clean();
  
      return $fragments;
  }
  
  add_filter('woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
  </code></pre>
  
  <p>The filter always works - I've never had a problem with that. What's totally throwing me is that the standard, pre-processed calls in the header (<code>cart_contents_count</code> &amp; <code>woocommerce_mini_cart()</code>) seem to be totally cached. If I add a new item, the AJAX will update both to display <strong>1</strong> and the actual item added; but if I change the page or refresh, it defaults back to <strong>0</strong> and <strong>No items</strong>. If I go to my cart, despite the mini-cart still saying I have nothing, the <em>actual</em> cart page displays the cart contents correctly.</p>
  
  <p>It only appears to update if I go to my cart page and delete something from my cart; for example, if I've <em>actually</em> got 7 items in my cart but the minicart displays 0, and then delete an item from my cart, suddenly the minicart will corectly display 6. However, from that point it will stay at 6, even if I add another dozen items. </p>
  
  <p>Here's what I've tried:</p>
  
  <ul>
  <li><strong>Change the classes/IDs of the elements</strong> (i,e, <code>#minicart</code> to <code>#tinycart</code>, etc.) - works once, then immediately starts caching again.</li>
  <li><strong>Turned off the filters:</strong> This has no effect, since the filter is only for returning fragments when new items are added. Also worth noting that there doesn't appear to be any kind of AJAX call fired at page load that would interfere with the minicart display.</li>
  <li><strong>Turned off all plugins except WooCommerce:</strong> made no difference.</li>
  <li><strong>Turned off 'Enable AJAX add to cart buttons on archives' in WC settings:</strong> This <em>kinda</em> works, insofar as it reloads the entire page when an item is added, and the minicart displays number of cart items correctly (<em>hooray!</em>), but obviously disables the ability to add items via AJAX, which is a requirement of the site (<em>boo.</em>)</li>
  <li><strong>Deleting my own <code>mini-cart.php</code> template file:</strong> Just in case, to see if that was an issue. Made no difference.</li>
  <li><strong>Putting the <code>woocommerce_mini_cart()</code> function literally anywhere else:</strong> This, infuriatingly, works. If I take this function and the <code>echo sprintf('%d', WC()-&gt;cart-&gt;cart_contents_count)</code> line and put them <em>anywhere</em> - within the header, within the page body, even inside the <em>same element</em> that's getting 'cached', they work. They display the correct number of items, and the correct list of items. But the other calls to this function, as noted above, still appear to be cached.</li>
  </ul>
  
  <p>As noted, this occurs even with no other plugins running; it happens both locally (a completely standard XAMPP installation on Windows) and remotely (a niftier nginx setup, slightly newer PHP version), and neither have any kind of caching enabled. </p>
  
  <p>Any suggestions would be very gratefully received, as I have totally lost my mind on this one.</p>