{"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

\"active<\/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

1. Install Enhanced Text Widget<\/h2>\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

2. Position the Widget for\u00a0your “Clear All Filters”\u00a0hyperlink<\/h2>\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

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
  1. Firstly it checks to see if any filters have been applied – it checks checks for normal attribute filters, min_price filter and a max_price filters.<\/li>\n
  2. If filters are not currently applied, then it doesn’t output anything. \u00a0If any filter is\u00a0applied, it shows the hyperlink.<\/li>\n
  3. The hyperlink is the current URL,\u00a0with the filter parameters\u00a0stripped off. \u00a0When\u00a0the user clicks the page reloads with the filters removed.<\/li>\n<\/ol>\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>\n

    Joe<\/strong>Tannorella:\u00a0How to Clear\/Reset Woocommerce Layered Nav Widget Filters<\/a><\/p>\n

     <\/p>\n","protected":false},"excerpt":{"rendered":"

    WooCommerce Layered Navigation is great for giving your online store visitors easy to use filters. 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: But I also wanted to add a link to “Clear All Filters” with one […]<\/p>\n","protected":false},"author":5,"featured_media":505,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"yoast_head":"\nClearing All Filters in WooCommerce Layered Navigation - Geektactics<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Clearing All Filters in WooCommerce Layered Navigation - Geektactics\" \/>\n<meta property=\"og:description\" content=\"WooCommerce Layered Navigation is great for giving your online store visitors easy to use filters. 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: But I also wanted to add a link to “Clear All Filters” with one […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\" \/>\n<meta property=\"og:site_name\" content=\"Geektactics\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-07T11:01:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-13T21:53:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"269\" \/>\n\t<meta property=\"og:image:height\" content=\"130\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Josh Moore\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Josh Moore\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\"},\"author\":{\"name\":\"Josh Moore\",\"@id\":\"https:\/\/geektactics.co.nz\/#\/schema\/person\/6bb496f93975e50731c7b169c39bc4ab\"},\"headline\":\"Clearing All Filters in WooCommerce Layered Navigation\",\"datePublished\":\"2015-04-07T11:01:58+00:00\",\"dateModified\":\"2024-06-13T21:53:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\"},\"wordCount\":297,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/geektactics.co.nz\/#organization\"},\"image\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg\",\"articleSection\":[\"Wordpress\"],\"inLanguage\":\"en-NZ\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\",\"url\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\",\"name\":\"Clearing All Filters in WooCommerce Layered Navigation - Geektactics\",\"isPartOf\":{\"@id\":\"https:\/\/geektactics.co.nz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg\",\"datePublished\":\"2015-04-07T11:01:58+00:00\",\"dateModified\":\"2024-06-13T21:53:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#breadcrumb\"},\"inLanguage\":\"en-NZ\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-NZ\",\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage\",\"url\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg\",\"contentUrl\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg\",\"width\":269,\"height\":130},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/geektactics.co.nz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Clearing All Filters in WooCommerce Layered Navigation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/geektactics.co.nz\/#website\",\"url\":\"https:\/\/geektactics.co.nz\/\",\"name\":\"Geektactics\",\"description\":\"Interesting Stuff for Geeks\",\"publisher\":{\"@id\":\"https:\/\/geektactics.co.nz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/geektactics.co.nz\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-NZ\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/geektactics.co.nz\/#organization\",\"name\":\"Geektactics\",\"url\":\"https:\/\/geektactics.co.nz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-NZ\",\"@id\":\"https:\/\/geektactics.co.nz\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2024\/06\/geektactics-logo.png\",\"contentUrl\":\"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2024\/06\/geektactics-logo.png\",\"width\":2001,\"height\":831,\"caption\":\"Geektactics\"},\"image\":{\"@id\":\"https:\/\/geektactics.co.nz\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/geektactics.co.nz\/#\/schema\/person\/6bb496f93975e50731c7b169c39bc4ab\",\"name\":\"Josh Moore\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-NZ\",\"@id\":\"https:\/\/geektactics.co.nz\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2bea43488633fc79ace340300f8ab6d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2bea43488633fc79ace340300f8ab6d6?s=96&d=mm&r=g\",\"caption\":\"Josh Moore\"},\"description\":\"I love marketing and technology. I run Duoplus Online Marketing and enjoy helping companies grow their income especially through using online marketing effectively.\",\"sameAs\":[\"https:\/\/www.duoplus.nz\"],\"url\":\"https:\/\/geektactics.co.nz\/blog\/author\/josh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Clearing All Filters in WooCommerce Layered Navigation - Geektactics","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/","og_locale":"en_US","og_type":"article","og_title":"Clearing All Filters in WooCommerce Layered Navigation - Geektactics","og_description":"WooCommerce Layered Navigation is great for giving your online store visitors easy to use filters. 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: But I also wanted to add a link to “Clear All Filters” with one […]","og_url":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/","og_site_name":"Geektactics","article_published_time":"2015-04-07T11:01:58+00:00","article_modified_time":"2024-06-13T21:53:08+00:00","og_image":[{"width":269,"height":130,"url":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg","type":"image\/jpeg"}],"author":"Josh Moore","twitter_misc":{"Written by":"Josh Moore","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#article","isPartOf":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/"},"author":{"name":"Josh Moore","@id":"https:\/\/geektactics.co.nz\/#\/schema\/person\/6bb496f93975e50731c7b169c39bc4ab"},"headline":"Clearing All Filters in WooCommerce Layered Navigation","datePublished":"2015-04-07T11:01:58+00:00","dateModified":"2024-06-13T21:53:08+00:00","mainEntityOfPage":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/"},"wordCount":297,"commentCount":4,"publisher":{"@id":"https:\/\/geektactics.co.nz\/#organization"},"image":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage"},"thumbnailUrl":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg","articleSection":["Wordpress"],"inLanguage":"en-NZ","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/","url":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/","name":"Clearing All Filters in WooCommerce Layered Navigation - Geektactics","isPartOf":{"@id":"https:\/\/geektactics.co.nz\/#website"},"primaryImageOfPage":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage"},"image":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage"},"thumbnailUrl":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg","datePublished":"2015-04-07T11:01:58+00:00","dateModified":"2024-06-13T21:53:08+00:00","breadcrumb":{"@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#breadcrumb"},"inLanguage":"en-NZ","potentialAction":[{"@type":"ReadAction","target":["https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/"]}]},{"@type":"ImageObject","inLanguage":"en-NZ","@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#primaryimage","url":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg","contentUrl":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2015\/04\/active-filters.jpg","width":269,"height":130},{"@type":"BreadcrumbList","@id":"https:\/\/geektactics.co.nz\/blog\/clearing-all-filters-in-woocommerce-layered-navigation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/geektactics.co.nz\/"},{"@type":"ListItem","position":2,"name":"Clearing All Filters in WooCommerce Layered Navigation"}]},{"@type":"WebSite","@id":"https:\/\/geektactics.co.nz\/#website","url":"https:\/\/geektactics.co.nz\/","name":"Geektactics","description":"Interesting Stuff for Geeks","publisher":{"@id":"https:\/\/geektactics.co.nz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/geektactics.co.nz\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-NZ"},{"@type":"Organization","@id":"https:\/\/geektactics.co.nz\/#organization","name":"Geektactics","url":"https:\/\/geektactics.co.nz\/","logo":{"@type":"ImageObject","inLanguage":"en-NZ","@id":"https:\/\/geektactics.co.nz\/#\/schema\/logo\/image\/","url":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2024\/06\/geektactics-logo.png","contentUrl":"https:\/\/geektactics.co.nz\/wp-content\/uploads\/sites\/2\/2024\/06\/geektactics-logo.png","width":2001,"height":831,"caption":"Geektactics"},"image":{"@id":"https:\/\/geektactics.co.nz\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/geektactics.co.nz\/#\/schema\/person\/6bb496f93975e50731c7b169c39bc4ab","name":"Josh Moore","image":{"@type":"ImageObject","inLanguage":"en-NZ","@id":"https:\/\/geektactics.co.nz\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2bea43488633fc79ace340300f8ab6d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2bea43488633fc79ace340300f8ab6d6?s=96&d=mm&r=g","caption":"Josh Moore"},"description":"I love marketing and technology. I run Duoplus Online Marketing and enjoy helping companies grow their income especially through using online marketing effectively.","sameAs":["https:\/\/www.duoplus.nz"],"url":"https:\/\/geektactics.co.nz\/blog\/author\/josh\/"}]}},"_links":{"self":[{"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/posts\/504"}],"collection":[{"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/comments?post=504"}],"version-history":[{"count":6,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/posts\/504\/revisions"}],"predecessor-version":[{"id":20281,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/posts\/504\/revisions\/20281"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/media\/505"}],"wp:attachment":[{"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/media?parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/categories?post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geektactics.co.nz\/wp-json\/wp\/v2\/tags?post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}