{"id":504,"date":"2015-04-07T23:01:58","date_gmt":"2015-04-07T11:01:58","guid":{"rendered":"http:\/\/geektactics.geektamin.com\/?p=504"},"modified":"2024-06-14T09:53:08","modified_gmt":"2024-06-13T21:53:08","slug":"clearing-all-filters-in-woocommerce-layered-navigation","status":"publish","type":"post","link":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/","title":{"rendered":"Clearing All Filters in WooCommerce Layered Navigation"},"content":{"rendered":"
WooCommerce Layered Navigation is great for giving your online store visitors easy to use filters.<\/p>\n
I added the “Active Filters” widget to my sidebar so that users could easily see and remove any filters they have applied. It looks like this:<\/p>\n
<\/p>\n
But I also wanted to add a link to “Clear All Filters” with one click. \u00a0 Here’s how I did that.<\/p>\n
If you don’t yet have a widget that allows you to paste PHP code, you need to install one. \u00a0I recommend the Enhanced Text Widget<\/a>.<\/p>\n Drag an Enhanced Text Widget onto your shop sidebar. \u00a0If you’re using the Active Filters widget it makes sense to put it directly under this. \u00a0Otherwise, position it wherever you want the “Clear All Filters” link to appear for your users.<\/p>\n If you don’t want to use PHP in a widget you can insert this code into\u00a0a custom plugin or functions.php in your child theme.<\/p>\n <\/p>\n This article combined code snippets from these two great articles, (plus\u00a0a bit of additional code from me):<\/p>\n ClickNathan:\u00a0Clearing All Filters Set by Woocommerce Layered Navigation<\/a><\/p>\n2. Position the Widget for\u00a0your “Clear All Filters”\u00a0hyperlink<\/h2>\n
3. Paste this Code into the Widget<\/h2>\n
\r\n<?php $filterreset = $_SERVER['REQUEST_URI'];\r\nif ( strpos($filterreset,'?filter_') !== false | strpos($filterreset,'?min_price') !== false | strpos($filterreset,'?max_price')) {\r\n $filterreset = strtok($filterreset, '?');\r\n echo '<div class=\"clear-filters-container\"><a id=\"woo-clear-filters\" href=\"'.$filterreset.'\">Clear All Filters<\/a><\/div>';\r\n }\r\n\r\n<\/code><\/pre>\n
What this code does:<\/h3>\n
\n