Site logo

Archived topic

EDD shop icon in menu, caching issue?

11 replies · Started by Halil on April 11, 2022

Viewing posts 1–12 of 12

Hi,

I'm trying the code below which Tom gave in one of older posts about EDD chart icon in menus. The code is working but there is a caching issue, if not logged in user does not refresh the page then the icon is not available. I know that GP/GB uses EDD, what is it that you r excluding from caching? As soon as I add GP/GB to cart I can see the icon as not logged in user on GB/GP sites.

 add_action( 'generate_menu_bar_items', function() {
	$cart_quantity = edd_get_cart_quantity();

	if ( ! $cart_quantity ) {
		return;
	}

	?>
	<a class="gp-cart-menu-item" title="Checkout" href="<?php echo edd_get_checkout_uri(); ?>"><?php generate_do_svg_icon( 'shopping-bag' ); ?> <span class="gp-cart-quantity"><?php echo $cart_quantity; ?></span></a>
	<?php
} );

Hi Ying,
I have checked settings for autoptimize, tried a few thing but it didnt work. Without hitting refresh I cant see the Shop icon as not logged in user. I'm using litespeed cache.

Can you link me to your site?

Let me see if the issue happens on my end as well.

Paste the link in the notes. This has nothing to do with GP directly but since you r also using EDD I though u might help me out. Thanks

I think it's not a cache issue.

In GP's default settings, the cart is loaded in the initial page load, but the code you are using loads nothing if there's no product in cart.

Can you try this code instead:

 add_action( 'generate_menu_bar_items', function() {
	$cart_quantity = edd_get_cart_quantity();

	?>
	<a class="gp-cart-menu-item" title="Checkout" href="<?php echo edd_get_checkout_uri(); ?>"><?php generate_do_svg_icon( 'shopping-bag' ); ?> <span class="gp-cart-quantity"><?php echo $cart_quantity; ?></span></a>
	<?php
} );

this is exactly what I want Ying, icon shouldnt be loading if there is no product in the cart?

just add the product, icon should show 1, and then open a new incognito browser, as if u r a different person, that 1 product cart shows up! I think it's a cache issue. not 100% sure.

this is exactly what I want Ying, icon shouldnt be loading if there is no product in the cart?

This is exactly I think the reason of the issue.

Can you try my code first and see if the issue is fixed (don't need refresh page to see it)?

Let me know.

hi Ying,
the code works only if I go to "checkout" page. Clicking/adding product does not update shop icon, even refresh does not show it. And it's always available unlike first code.

Hi there,

This isn't something the code above has control over. Your caching is preventing the page from receiving the data it needs.

You may need to reduce the aggressiveness of your caching a bit to allow some stuff to stay dynamic. If you're using a plugin you may want to contact their support team as they may have suggestions for working with EDD.

thanks Tom & Ying

No problem!

This archived topic is closed to new replies.