skip to Main Content

Whenever I remove a product from cart page on woocommerce it scrolls to top. I managed to do that for quantity change but its not working when removing item.

this is Working with quantity change. I want to stop scrolling to top after deleting a product from cart page. Searched everywhere didn’t get any answer.

var timeout;
 
jQuery( function( $ ) {
        $('.woocommerce').on('change', 'input.qty', function(){

            if ( timeout !== undefined ) {
                clearTimeout( timeout );
            }

            timeout = setTimeout(function() {
                $("[name='update_cart']").trigger("click");
                document.location.reload(true);
            });
        });
});

4

Answers


  1. Chosen as BEST ANSWER

    So, I haven't found a nice solution to this anywhere. So went into the code of woocommerce and changed some code.

    Open this file wp-content/plugins/woocommerce/includes/wc-template-functions.php and search for this at line 3640.

    wc_print_notices();
    

    and comment or remove this line. then it will work for change in quantity and removing items from cart and it won't scroll to top every time when you have 100's of products.

    Also you don't need to use document.location.reload(true); for this.

    P.S. You have to change it every time when you update the plugin.


  2. remove_action('woocommerce_before_cart', 'woocommerce_output_all_notices', 10);
    
    Login or Signup to reply.
  3. Try fixing it in CSS by adding

    body {
        overflow-x: visible !important;
    }
    
    Login or Signup to reply.
  4. jQuery(document).ready(function($) {
        $(document).ajaxComplete(function() {
        if ($('body').hasClass('woocommerce-checkout') || $('body').hasClass('woocommerce-cart')) {
            jQuery( 'html, body' ).stop();
        }
      });
    });
    

    Only this worked for me, if you dont want disable woocommerce notices.
    Add this code wrapped on <script>...</script> tag in the footer

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search