arslion
arslion

Reputation: 440

Stop scroll to top after removing an item from woocommerce cart page

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);
            });
        });
});

Upvotes: 0

Views: 2923

Answers (4)

Aleksandr Abramov
Aleksandr Abramov

Reputation: 540

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

Upvotes: 1

Switch900
Switch900

Reputation: 161

Try fixing it in CSS by adding

body {
    overflow-x: visible !important;
}

Upvotes: 0

the_alex_mark
the_alex_mark

Reputation: 21

remove_action('woocommerce_before_cart', 'woocommerce_output_all_notices', 10);

Upvotes: 2

arslion
arslion

Reputation: 440

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.

Upvotes: 0

Related Questions