• Resolved BJ

    (@kossahl)


    Hi there,

    somewhen with the last versions of either ‘Woocommerce’ or ‘WooCommerce Menu Cart’ I started to encounter a strange bug which I’m not able to find the source for.

    The problem is as follows:

    1. I visit my page (https://wamiki.de/shop). You can see the menu cart working in the top right corner. It is configured to only show the current value of the cart. When you have nothing in your cart it correctly shows 0,00 €.

    2. I add a product to my cart. The product is added correctly to the cart, BUT the menucart will still show 0,00 €

    Now in debugging I encountered all of the following Informations which might help find the source of this bug:

    a) when you have products in your cart and the page starts loading, the menu cart will show the correct amount in the menu, but at some point (after a few milliseconds) some javascript kicks in and resets the amount to 0,00 € and also changes the href for the menu cart from /cart to /shop.

    b) I disabled all other plugins (only Woocommerce and Woocommerce Menu Cart are running)

    c) I switched the theme to twentytwenty and others, still same bug.

    d) I can reproduce the problem in the latest versions of Firefox and Google Chrome

    e) If I open a new browser window! (not tab!) to browse to wamiki.de suddenly all tabs in all windows will show the correct amount in the menu cart.

    f) when doing e) there will be an xhr post to https://wamiki.de/?wc-ajax=get_refreshed_fragments on all tabs in all windows

    please help

    • This topic was modified 3 years, 9 months ago by BJ.

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

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @kossahl

    When i add something to the cart the site redirects me to the cart, probably it doesn’t have time to refresh WC fragments and that’s why it shows 0€. Can you remove that redirect and try again?

    Let me know.

    Thread Starter BJ

    (@kossahl)

    Hey @alexmigf

    i tested as you suggested and it works. But the behaviour of redirecting to the cart is wanted by the customer and much more important it used to work (I dont know when it stopped working).

    And shouldn’t it also work and show the correct amount in the menu cart after I visit any other page (after I added a product to the cart)?

    So I’m not sure what changes are responsible for the changed behaviour.

    Anymore hints?

    • This reply was modified 3 years, 9 months ago by BJ.
    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @kossahl

    If you could delay the redirect a few seconds should be enough. Can you test?

    Thread Starter BJ

    (@kossahl)

    How can I delay the redirect?

    Also the delay can be a couple of ms max. It would not be acceptable to wait a “few seconds” till the customer gets redirected to the cart obvoiusly.

    Still I wonder what the actual problem can be, as this used to work and the redirect is a standard woocommerce option. As I layed out in my first post, this problem even occurs with just woocommerce and woocommerce menu cart plugin activated an a standard twentytwenty theme.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @kossahl

    I understand. Can you show me your settings under WooCommerce > Settings > products?

    Let me know.

    • This reply was modified 3 years, 9 months ago by alexmigf.
    Thread Starter BJ

    (@kossahl)

    Hi @alexmigf

    I tried you redirect delay as you suggested in you post (before you changed it). It didn’t work (I tried up to 5 seconds delay).

    Furthermore I tested on a fresh WordPress Install (on a local server), just adding Woocommerce (with demo content) and Woocommerce Cart plugin together with theme twentytwenty. The problem did not! occure there.

    Also here are the settings you asked for:

    https://i.ibb.co/h7N3rLK/product-settings.jpg

    Thank you for investigating.

    • This reply was modified 3 years, 9 months ago by BJ.
    • This reply was modified 3 years, 9 months ago by BJ.
    • This reply was modified 3 years, 9 months ago by BJ.
    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @kossahl

    Disable the redirect on WC settings and add the code snippet below to your theme functions.php file:

    add_action( 'wp_footer', 'wc_modify_update_cart_totals' );
    function wc_modify_update_cart_totals() {
        ?>
        <script>
    		jQuery(document).ready(function($){
    			$('body').on( 'added_to_cart', function(){
    				window.location.href = '<?php echo wc_get_cart_url(); ?>';
    			});
    		});
        </script>
        <?php
    }

    Let me know if it works.

    Thread Starter BJ

    (@kossahl)

    Hey @alexmigf

    it works. Should i stay with this as a fix or is it only to get more detailed info about the source of the problem?

    Thanks
    BJ

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @kossahl

    Themes could replace the add to cart classes that our plugin uses to refresh the cart contents, but because you’re using the free version you can’t change that. If you keep using the free version i believe that you will need that code.

    Thread Starter BJ

    (@kossahl)

    I dont think this is the case. As reported the bug also occures with the wordpress standard twentytwenty theme which does not include any woocommerce templates thus not changing any classes concerning woocommerce and all other plugins but menu cart and woocommerce deactivated.

    And again as stated before: it used to work!
    I used the combination of menu cart plugin and woocommerce on the same site for several years with cart redirection and there never was a problem.

    Also your provided code snippet does not rely on any css classes, it basically just replaces the redirect. So anything depending on some css classes seems to work.

    So I dont see any advantages in buying the pro version.

    Don’t get me wrong, I’m grateful you provided a working solution (which I allready deployed to production), but it feels more like a workaround to cover up the symptoms.
    I would be interested in how to solve the actual source of the problem.

    Thanks again
    BJ

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @kossahl

    Of course, you’re totally right.

    Let’s do a test. Disable our plugin and follow this steps:

    • Enable redirect and show the WooCommerce Cart widget on the page somewhere
    • Add something to the cart – you’ll be redirected
    • Navigate to another page – see if the cart widget have been updated

    Let me know what you find.

    Thread Starter BJ

    (@kossahl)

    I will test and report.

    Meanwhile I discovered that the solution you found does not work for me when adding a variable product to the cart:

    1. menu cart gets updated accordingly

    but

    2. the redirect to the cart does not happen.

    You can test this yourself if you like for example with this product:

    https://wamiki.de/shop/material/kleiner-koffer-aus-pappe/

    sorry its only in german, but basically just chose an option “Wähle eine Option” (grey drop down box) and hit “In den Warenkorb” (blueish button) to add it to the cart.

    I’ll report what you asked for as soon as I find the time to test.

    BJ

    Thread Starter BJ

    (@kossahl)

    Hey @alexmigf

    tl/dr
    cart widget shows no products in cart

    I tested as you suggested.
    I tested with the websites custom theme and all plugins activated. I tested with several different products.
    Cart widget shows empty.

    I deactivated all plugins except woocommerce and menu cart and tested with themes twentytwenty and twentynine.
    Cart widget shows empty.

    I then additionally deactivated the menu cart plugin.
    Cart widget shows empty.

    So it seems the problem is not connected to the menu cart plugin.

    Do you have suggestions nevertheless?

    Thanks
    BJ

    • This reply was modified 3 years, 9 months ago by BJ.
    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @kossahl

    I can’t replicate the same issue, i tested with Storefront theme with and without widget (without Menu Cart) and in both scenarios it gets updated.

    Can you do a test with the Storefront theme?

    Thread Starter BJ

    (@kossahl)

    Hey @alexmigf

    I tested with storefront, same issue.

    Furthermore I tried all of the following:

    1. deactivate and reactivate woocommerce
    2. deactivate, delete and reinstall woocommerce
    3. deactivate, delete + delete all woocommerce db tables (via define( ‘WC_REMOVE_ALL_DATA’, true ); ) and reinstall woocommerce + democontent

    In alle these cases the same issue persisted.

    Like you I did a clean local test installation with just woocommerce and a pretty standard theme. I had no issues there.

    Next I will try a clean/new test installation of wordpress+woocommerce+democontent on the server the actual website runs and see what i come up with.

    Do you have any more suggestions?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Cart in menu resets to empty on pageload’ is closed to new replies.