Created
July 19, 2022 14:46
-
-
Save bjornpatje/3e7d71831d4b1b03e5c23783e294e088 to your computer and use it in GitHub Desktop.
Collapse Woo categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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