Side cart dont work on cached page

I have a problem that the ajax side cart does not work in the latest version with the cache. The site is https://www.tilt.rs/

It correctly displays how many products are in the cart, but the entire sidebar is cached, it should load via ajax

Comments

  • Hi,

    Do you use a caching plugin for that?

    If yes, can you tell me the name of it, please?


    Thanks

  • I am using w3 total cache

  • Hey,

    Please send us WordPress dashboard access privately thru the contact form, which is on the right side at http://themeforest.net/user/muffingroup#contact, and we will check what might be the reason.

    Notice!

    Please attach a link to this forum discussion.

    Sending incorrect or incomplete data will result in a longer response time.

    Therefore, please ensure that the data you are sending is complete and correct.

    Thanks

  • I have adjusted some settings, please check it now.


    Best regards

  • It's still not solved. I saw you changed to basic caching, but its ususaly worse than advance. I have few licenses where I have the same problem on different server environment, it's not always been like that. Definitely the mini cart is updated via ajax fragment when a product is added to the cart, while when loading the page the mini cart is generated via php and only counter for product in basket work via ajax. Same problem is for the popup on top off navigation, when turned off on x it should stay off. I will investigate source code till Tuesday and I will contact you after, if you come up with something, let me know. Maybe this problem is for tier 3 or development, but I believe that one correct jQuery snippet can solve it. External mini cart plugin work well, but they don't fit into my design concept

  • Dear All,


    In the woocommerce.js file there is no update of the cart at all when the page is opened.

    If anyone needs this option, I made a fix.

    It would be good if developers pay attention to this.



    Copy/Paste this code in: Betheme -> Theme Options -> Custom CSS & JS -> JS


    ----------------------- code ------------------------------


    jQuery(function($) {

      var cartElement = $(".mfn-cart-holder");


      // Refreshing basket data based on new fragment

      function refreshCart(fragment) {

        var cartContent = fragment['div.widget_shopping_cart_content'];

        var cartCount = fragment['.header-cart-count'];

        var cartTotal = fragment['.header-cart-total'];


        // Updating cart information

        cartElement.find('.mfn-ch-content').html(cartContent);

        cartElement.find('.header-cart-count').replaceWith(cartCount);

        cartElement.find('.header-cart-total').replaceWith(cartTotal);


        $('.mfn-cart-holder').attr('aria-expanded', 'false');

      }


      // Sending an Ajax request to get a new fragment

      function getUpdatedCart() {

        $.ajax({

          type: 'POST',

          url: wc_add_to_cart_params.ajax_url,

          data: {

            action: 'woocommerce_add_to_cart',

            current_cart: $('.header-cart-count').first().text()

          },

          success: function(response) {

            if (response === 'error') {

              // Here you can process the error if there was a problem adding the product to the cart

              return;

            }


            $(document.body).trigger('refresh');



            refreshCart(response);

          }

        });

      }


      // Initiating cart updates on page load

      getUpdatedCart();


      $(document.body).on('refresh', function(e) {

        cart.refresh();

      });


      cart = {


        refresh: function() {

          $.ajax({

            url: mfnwoovars.ajaxurl,

            data: {

              'mfn-woo-nonce': mfnwoovars.wpnonce,

              action: 'mfnrefreshcart'

            },

            type: 'POST',

            cache: false,

            success: function(response) {

              $('.mfn-cart-holder .mfn-ch-content').html(response.content);

              $('.mfn-cart-holder .mfn-ch-footer .mfn-ch-footer-totals').html(response.footer);

              $('.mfn-cart-holder').removeClass('loading');


              // side cart buttons

              $('.mfn-ch-footer-buttons').show();

              return;

            }

          });

        }

      }


    });

  • Good to see that you found a workaround.

    I have passed this to the dev team, and we will take a look at this.


    Best regards

  • We have prepared a solution for that.

    Please send us WordPress dashboard access privately thru the contact form, which is on the right side at http://themeforest.net/user/muffingroup#contact and we can implement it on your website.

    Notice!

    Please attach a link to this forum discussion.

    Sending incorrect or incomplete data will result in a longer response time.

    Therefore, please ensure that the data you send are complete and correct.

    Thanks

Sign In or Register to comment.