Hi @stefacchio,
Could you share the URL? AJAX requests shouldn’t cached by default.
Thread Starter
Stefano
(@stefacchio)
Hi @m_uysl,
here https://www.luxuryconcept.website/
If you add the product into the cart it works fine, the header cart icon is updated correctly, but when you change the page, it returns to 0 products.
Without cache it works fine.
Thanks
Thread Starter
Stefano
(@stefacchio)
This is the code that generates cart icon:
function luxuryconcept_mini_cart_header() {
if ( luxuryconcept_is_woocommerce_activated() ) {
if ( ! is_cart() and ! is_checkout() ) {
global $woocommerce;
$count = $woocommerce->cart->cart_contents_count;
?>
<ul class="header__mini_cart">
<li class="btnOpenCart_container">
<button aria-label="<?php esc_html_e( 'Open Cart', 'luxuryconcept' ) ?>" data-toggle="dropdown"
aria-expanded="false" id="btnOpenCart" class="mini_cart_button">
<svg class="at-icon icon-32 no-pointer-events" fill="none">
<use href="#cart-outline"></use>
</svg>
</button>
<span class="badge-cart-items-count"><?php echo esc_html( $count ); ?></span>
</li>
<?php if ( esc_attr( get_theme_mod( 'luxuryconcept_cart_type', LC_DEFAULT_CART_TYPE ) ) == 'classic' ) : ?>
<li class="li__classic_cart">
<div class="classic_shopping_cart top-chevron-border">
<?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
</div>
</li>
<?php endif; ?>
</ul>
<?php
}
}
}
where <span class="badge-cart-items-count"><?php echo esc_html( $count ); ?></span> is the issue.
Hey @stefacchio,
Could you please add woocommerce_items_in_cart to the Rejected Cookies section under Advanced Options? This should help because when items are added to the cart, the cart updates dynamically, but cached pages don’t reflect these changes. By serving a dynamic version of the page for users with items in their cart, the issue should be resolved.
Give it a try, and let me know how it goes!
Thread Starter
Stefano
(@stefacchio)
But in this way I’ll serve a dynamic version for all page cause the cart icon is visible on all pages… or not?
Yes! If you want to have to cache and count properly working you can also implement a custom solution that updates badge-cart-items-count with an AJAX call.
Or, instead of rejecting the cookie you can add it as vary cookie – https://docs.poweredcache.com/advanced-options/#vary-cookies
I’m marking this thread as resolved, since the question is not particularly related to Powered Cache, it’s how the caching layer works.