Support » Plugin: WP Menu Cart » Cache Issue (Cart empty on home page)

  • Good afternoon,

    We have been running this plugin, with comet cache enabled, and have noticed that every time you go back to the home screen, after adding items to the shopping cart; the cart contents are then empty.

    We have identified this as a cache issue; as disabling comet cache, fixes this issue.

    We are running this plugin with the wp-ecommerce plugin.

    Any help, or advise, would be greatly appreciated.

    Kind Regards,

    Andrew

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Andrew,
    Because the userbase of wp-ecommerce is so small compared to WooCommerce and Easy Digital Downloads, we don’t get to spend a lot of time with this platform. Caching issues are always difficult to resolve. What you could try to do is to load the AJAX call on each page load so that the menu cart bit is always replaced with an uncached version. Here’s a code snippet that should do that, could you try adding this to your site?

    
    add_action( 'wp_footer', 'wpo_menucart_always_ajax', 999 );
    function wpo_menucart_always_ajax() {
        ?>
        <script type="text/javascript">
        jQuery( function( $ ) {
            function WPMenucart_Load_AJAX() {
                var data = {
                    security:   wpmenucart_ajax.nonce,
                    action:     "wpmenucart_ajax",
                };
    
                xhr = $.ajax({
                    type:       'POST',
                    url:        wpmenucart_ajax.ajaxurl,
                    data:       data,
                    success:    function( response ) {
                        $('.wpmenucartli').html( response );
                    }
                });
            }
            WPMenucart_Load_AJAX();
        });
        </script>
        <?php
    }
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters.

    Let us know if that works for you, so that we can look into adding this to the core plugin scripts too.

    Thread Starter Andrew1977

    (@andrew1977)

    Hello,

    Many thanks for taking the time to look at this, and provide this code.
    It’s very much appreciated!

    I added the code to the functions.php file in the theme, but it through an error, and prevented the website from loading. I’m not sure if the error was related to one of the } symbols in the code that you provided?

    Kind Regards,

    Andrew

    Plugin Contributor Ewout

    (@pomegranate)

    Sorry to hear that Andrew. I suspect it may have been a copy paste error, since I tested this on my own site before posting and didn’t get any errors. Try copying from here instead:
    https://pastebin.com/raw/kfZayJH1

    Let me know if that works for you!

    Thread Starter Andrew1977

    (@andrew1977)

    Firstly, thanks again for all your help on this.

    I added the code that you have provided to the bottom of the functions.php file and got this error:

    Warning: Cannot modify header information – headers already sent by

    Kind Regards,

    Andrew

    Thread Starter Andrew1977

    (@andrew1977)

    Hello again,

    Quick update!

    Got your code to work, and the cart updates.

    The only thing we have now is our normal wp-ecommerce shopping cart not being displayed anymore, when this plugin is activated.

    Kind Regards,

    Andrew

    Plugin Contributor Ewout

    (@pomegranate)

    Glad to hear the cart updates work!

    The regular cart nog displaying anymore is strange… Do you mean when the plugin is activated or when this particular snippet is activated? Can I see this live somewhere?

    Thread Starter Andrew1977

    (@andrew1977)

    Good Morning,

    Thank you for your reply.

    Much appreciated!

    Bascially, when the menu cart plugin is activated the normal wp ecommerce shopping cart won’t display. As soon as the menu cart plugin is deactivated, the normal wp ecommerce shopping cart appears again.

    The strange this is, we have tried the menu cart on a test site, and the normal wp-ecommerce shopping cart will display, but when you clear the cart, the menu cart items still remain.

    I think from memory, if you click the remove button, instead of clear cart, it worked on the test site.

    Kind Regards,

    Andrew

    Thread Starter Andrew1977

    (@andrew1977)

    Sorry, forgot to say, on the test site; if you click clear cart, the menu cart will clear; however, you have to right click the mouse button and click reload page for the page to reload, and then the other cart updates.

    Kind Regards,

    Andrew

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Andrew,
    The fact that the normal cart works on the test site but not on the live site makes me suspect it’s some sort of plugin conflict/configuration issue. Are both sites identical? Did you add the snippet to both sites?

    Can I see either the live or test site somewhere so I can see the problem in action? It’s a bit difficult to assess it properly with just your description of it.

    Thanks!

    Thread Starter Andrew1977

    (@andrew1977)

    Many thanks for the reply.

    We’ve had our website developer look into this and he has got the menu cart working with the wp ecommerce cart.

    Details below of the fix:

    At the top of wpmenucart.js this has now been added:

    jQuery( function( $ ) {
    var buttons = [
    “.emptycart”, //: for wp-e-commerce cart

    The other change was to comment out this line:

    //add_action(‘wpsc_alternate_cart_html’, array( &$this, ‘wpec_cart_ajax’
    ) );

    in wpmenucart-wpec.php which was preventing the update of the “native”
    cart widget.

    Also of course the addition of the functions.php :
    add_action( ‘wp_footer’, ‘wpo_menucart_always_ajax’, 999 ); function wpo_menucart_always_ajax() {

    Kind Regards,

    Andrew

    Thread Starter Andrew1977

    (@andrew1977)

    One other thing I forgot to mention with this plugin – the following is affecting our page load time by an average time of 1 second for the following:

    wp-menu-cart/font/fontawesome

    I’m guessing this is to do with the mini cart logo?
    Kind Regards,

    Andrew

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Cache Issue (Cart empty on home page)’ is closed to new replies.