Skip to content

Instantly share code, notes, and snippets.

@bjornpatje
Created July 19, 2022 14:46
Show Gist options
  • Save bjornpatje/3e7d71831d4b1b03e5c23783e294e088 to your computer and use it in GitHub Desktop.
Save bjornpatje/3e7d71831d4b1b03e5c23783e294e088 to your computer and use it in GitHub Desktop.
Collapse Woo categories
<script type="text/javascript">
jQuery(document).ready(function() {
// The button
jQuery('<span class="toggle">More</span>').appendTo('#shop-sidebar .product-categories, #shop-sidebar .woocommerce-widget-layered-nav-list');
// Hide categories when more than 5
jQuery("#shop-sidebar .product-categories li").slice(5).hide();
// Hide attribute filter options when more than 5
jQuery("#shop-sidebar .woocommerce-widget-layered-nav-list").each(function() {
jQuery(this).find('li').slice(5).hide();
});
// Button function and toggle
jQuery(".woocommerce .toggle").click(function(){
jQuery(this).siblings("li").slice(5).slideToggle();
jQuery(this).text(jQuery(this).text() == "More" ? "Less" : "More");
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment