Clearing All Filters Set by Woocommerce Layered Navigation
For a project I’m working on, I wanted to use Woocommerce’s built in Layered Navigation widgets. Unfortunately, the functionality Woo provides to clear the filters just wasn’t working for me, likely due to various other customizations I’ve been making to get the platform to bend to my will, so to say.
Regardless, I’ve figured a smooth little trick to doing so, which only requires three lines of code.
<?php $filterreset = $_SERVER['REQUEST_URI'];
$filterreset = strtok($filterreset, '?'); ?>
<a href="<?php echo $filterreset; ?>">Clear Filters</a>
In that little piece of poetry we simply check the current URL, then remove any parameters, and finally create a new link with the current URL minus any parameters.