[Resolved] EDD shop icon in menu, caching issue?

Home Forums Support [Resolved] EDD shop icon in menu, caching issue?

Home Forums Support EDD shop icon in menu, caching issue?

  • This topic has 11 replies, 3 voices, and was last updated 4 months ago by Tom.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2185373
    Halil

    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
    } );
    #2185432
    Ying
    Staff
    Customer Support

    Hi Halil,

    This is the recommended caching setting for Autoptimize, it should be the same for other cache plugins as well.
    https://docs.generatepress.com/article/configuring-autoptimize/

    #2185509
    Halil

    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.

    #2185575
    Ying
    Staff
    Customer Support

    Can you link me to your site?

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

    #2186289
    Halil

    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

    #2186620
    Ying
    Staff
    Customer Support

    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
    } );
    #2186726
    Halil

    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.

    #2186849
    Ying
    Staff
    Customer Support

    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.

    #2187840
    Halil

    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.

    #2188198
    Tom
    Lead Developer
    Lead Developer

    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.

    #2188913
    Halil

    thanks Tom & Ying

    #2189287
    Tom
    Lead Developer
    Lead Developer
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.