1. Home
  2. Knowledge Base
  3. WooCommerce Product Filters
  4. Developer Documentation

Prevent auto-scroll on filter changes

The following filter prevents the page from automatically scrolling when product filters are applied in the WooCommerce Product Filters plugin. This is useful when you want users to maintain their scroll position while filtering. Disabling the auto-scroll behavior allows customers to see results appearing without the page jumping or changing position.

If you don't know how to add code snippets, then please see our article.

jQuery(function($) {
  let y = 0;
 document.addEventListener('wcf:products:beforeScroll', function() {
  y = window.scrollY
 })
 document.addEventListener('wcf:products:afterScroll', function() {
  window.scrollTo(0, y)
 })
})

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.