caching problem with woocommerce cart widget
-
Hello there,
thank you for the great plugin.Wordpress 4.6.1 / Woocommerce 2.6.4
I am experiencing a crucial issue with the plugin, hoping you can help.
The plugin currently caches my cart, which is in a dedicated widget position on every page (cart)
The code in the widget position is :<?php if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { $wc = WC(); $count = $wc->cart->cart_contents_count; if ($count !=0) { ?><a class="cart-contents" href="<?php echo WC()->cart->get_checkout_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo '(' . $count . ')'; ?></a><?php } else { ?><a class="cart-contents" title="<?php _e( 'Your Cart is Empty' ); ?>"><?php echo '(0)'; ?></a><?php } } ?>
The code in the functions.php file is
add_filter( 'woocommerce_add_to_cart_fragments', 'my_header_add_to_cart_fragment' ); function my_header_add_to_cart_fragment( $fragments ) { ob_start(); $count = WC()->cart->cart_contents_count; if ($count !=0) { ?><a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View Cart and Checkout' ); ?>"><?php echo '(' . $count . ')'; ?></a><?php } else { ?><a class="cart-contents" title="<?php _e( 'Your Cart is Empty' ); ?>"><?php echo '(0)'; ?></a><?php } $fragments['a.cart-contents'] = ob_get_clean(); return $fragments; }
I do not seem able to remove this snippet from page caching; as the user (non-logged in) adds goods to the cart, the cart is updated. Moving to another page in the site results in “(0)” goods appearing again (as the code is not executed, the cached version being called).
What I need to achieve is for the specific widget position ‘cart’ not to be cached , but I am not succeeding.
I Tried adding
define('COMET_CACHE_ALLOWED', FALSE); or $_SERVER['COMET_CACHE_ALLOWED'] = FALSE; or define('DONOTCACHEPAGE', TRUE);
to the code snippets above, but without success.
Could you please advise? It is essential for us. We would love to use your plugin (we are PRO customers).
Thank you in advance
- The topic ‘caching problem with woocommerce cart widget’ is closed to new replies.