• Resolved kieronboz

    (@kieronboz)


    Hey guys – I have the following function in my functions.php:

    function cart_count_shortcode() {
    if (class_exists('WooCommerce')) {
    $cart_count = WC()->cart->get_cart_contents_count();
    if ($cart_count) {
    return '' . $cart_count . '';
    }
    }
    return '';
    }
    add_shortcode('cart_count', 'cart_count_shortcode');

    and then in a template I have:

    <?php echo do_shortcode('[esi cart_count ttl="1" cache="private"]'); ?>

    But I can go onto an incognito window, add something to my woocommerce cart, but the source HTML comes out as:

    <a class="square-button green-bg" href="/cart">
    <i class="fas fa-shopping-cart"></i>
    <!-- lscwp esi-shortcode -->
    <!-- Block cached by LiteSpeed Cache 6.4 on 2024-08-14 23:01:44 -->
    <!-- lscwp esi-shortcode esi end -->
    </a>

    So the ttl/private doesn’t really seem to work for me, as that timestamp is yesterday.

    Do you know if I’m missing something?

    Thanks!

    • This topic was modified 7 months, 1 week ago by kieronboz.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support qtwrk

    (@qtwrk)

    if you just run a simple function like rand() in that function , does it return different number every time you refresh ?

    Thread Starter kieronboz

    (@kieronboz)

    Hey, I have added the following now

    function esi_test_shortcode() {
    if (class_exists('WooCommerce')) {
    return rand();

    }
    return '';
    }
    add_shortcode('esi_test', 'esi_test_shortcode');

    and then in the footer at the bottom

    debug: <?php echo do_shortcode('[esi esi_test ttl="1" cache="private"]'); ?>

    on initial glances, that appears to behave better. i am just testing it thoroughly now, but thought id mention it to you quick also

    Plugin Support qtwrk

    (@qtwrk)

    just follow up, how thing goes ?

    Thread Starter kieronboz

    (@kieronboz)

    i still can’t make it work reliably

    Plugin Support qtwrk

    (@qtwrk)

    the rand() didn’t work either ?

    Thread Starter kieronboz

    (@kieronboz)

    Rand did work, which is what im confused on.

    Plugin Support qtwrk

    (@qtwrk)

    I tested your cart count code on storefront, and it works on me

    <!-- lscwp esi-shortcode -->5
    <!-- Block cached by LiteSpeed Cache 6.4.1 on 2024-08-20 09:12:28 --><!-- lscwp esi-shortcode esi end -->

    I got this as result , where 5 is the cart count

    maybe you can add something like error_log within that cart count function , see if it was executed or not

    Thread Starter kieronboz

    (@kieronboz)

    I had to disable Cache Logged-in Users as it was not working – that’s why it’s working OK now I believe.

    I will try to add some error outputting next

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘ESI Shortcode Still Caching even with private/low ttl’ is closed to new replies.