WooCommerce Filter: Show Only Attributes of the Current Category
When several product categories share one attribute, a WooCommerce filter often offers values that make no sense on the page: Grill under refrigerators, 512 GB under headphones, brands that are not sold in this category. Clicking them gives an empty result. To make the WooCommerce filter show only attributes of the current category, HUSKY counts the products behind every term on the page and hides the terms whose count is zero. Below is how that works, the exact settings, how to keep the numbers invisible, and the cases where the category is not known at all.
How the filter knows what belongs to the current category
On a product category page, and on any other product taxonomy archive (a tag, an attribute archive, a brand), HUSKY remembers the term that the page is showing. With Dynamic recount switched on, the number next to each filter term is calculated as: products of this category that match everything the visitor has already selected and also have this term. A value that no product in the category has gets 0.
Hide empty terms then removes every term with 0 from the form. When all terms of a section are removed, the whole section, title included, disappears too, so an attribute that is not used in the category vanishes from the sidebar. The category section itself is trimmed to the subcategories of the category being viewed; why the filter shows only subcategories explains that part and its exceptions.
Nothing has to be configured per category. The same form placed in a sidebar or on the category template adapts to every category page on its own.
The three settings that hide empty terms
Open the plugin settings, tab Options, and set:
- Show count: Yes
- Dynamic recount: Yes
- Hide empty terms: Yes
Save, then clear every cache that can hold old counts: Cache dynamic recount number for each item in filter and Cache terms in Advanced → Options if you use them, and the page cache of your site.
The three options depend on each other, and the settings page enforces it: an empty term can only be found by counting. Switching Hide empty terms on also switches the other two on, and switching Show count off also switches the other two off. If you set Show count to No to get rid of the numbers, empty terms come back on every page. The possible combinations:
| Show count / Dynamic recount / Hide empty terms | What visitors see |
|---|---|
| No / No / No | All terms, no numbers |
| Yes / No / No | Store-wide numbers; terms without any product are greyed out |
| Yes / Yes / No | Numbers for the current category and selection; zero terms stay visible but greyed out and cannot be selected |
| Yes / Yes / Yes | Zero terms are hidden; empty sections disappear |
The third line is the choice when you prefer to show unavailable values as inactive instead of removing them. A few more places can override the global options:
- In the free version Hide empty terms and Hide terms count text (below) are greyed out; they are part of the premium version.
- The HUSKY filter widget has its own Dynamic recount field (Default, No, Yes). If it is set to No, that widget ignores the global setting. The [woof] shortcode has the same switch as
dynamic_recount=1ordynamic_recount=0. - When Turbo mode is enabled, the Options tab shows separate copies of these three settings for Turbo mode. Set them again after enabling it.
- A taxonomy displayed as a range slider is not recounted by the global options. Open its additional options (the gear icon next to the taxonomy in the Structure tab) and set Enable dynamic recount to Yes; values without products are then left out of the slider scale.
The Options tab documentation describes the other settings on the same screen.
Hide empty terms without showing the count
The most common wish is to hide empty terms without printing numbers like (12). Keep all three options on and go to Advanced → Options: set Hide terms count text to Yes. The plugin still calculates the counts, which it needs in order to know what is empty, but does not print them. To do this for one form only, add hide_terms_count=1 to its shortcode, for example [woof hide_terms_count=1].
Hiding the counter with CSS also works for checkboxes and radio buttons (.woof_checkbox_count, .woof_radio_count), but not for drop-downs: there the number is part of the option text and has no element of its own. The setting covers every filter type.
To change the counter only in some sections, use the woof_term_count_format hook. It receives the format, (%d) by default, and the taxonomy slug:
/*
* HUSKY: counter format per filter section.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('woof_term_count_format', function ($format, $tax_slug) {
// no numbers at all in the Tags and Brand sections
if (in_array($tax_slug, array('product_tag', 'pa_brand'), true)) {
return '';
}
// "12" instead of "(12)" everywhere else
return '%d';
}, 10, 2);
Empty terms are still hidden in those sections, because hiding depends on the calculated count, not on the printed text. To show numbers only on the lowest level of a category tree, hide the counters of terms that have children with CSS (Custom CSS field of your theme):
.woof_childs_list_li > .woof_checkbox_label > .woof_checkbox_count {
display: none;
}
A selected term never shows a number. This is by design: the recount skips terms that are already part of the search.
Why other values disappear after the first selection
Dynamic recount narrows the form with every choice: after Brand: Bosch is selected, only the colours that Bosch products in this category have remain. That is the point of the feature. It cannot be switched off for one section only.
A different case is when picking one colour hides all the other colours. That comes from the section's logic. Open the taxonomy's additional options (the gear icon in the Structure tab) and look at Logic of filtering:
- OR (default): products that have at least one of the selected values. Every other colour is counted on its own (within the selections in the other sections), so the colours that exist in the category stay.
- AND: products that have all selected values at once. The count of every other colour becomes "products that are red and blue at the same time", usually 0, so with Hide empty terms they vanish.
- NOT IN: excludes products with the selected values.
For colours, sizes and most attributes where a visitor wants "this or that", OR is the right logic. Keep AND for features that must all be present, such as "Wi-Fi and Bluetooth".
For options that narrow before any products load (a finder made of dependent drop-downs), use [woof ajax_redraw=1 autosubmit=1]: every change redraws only the form with recounted options, and the filter button loads the products. ajax_redraw is not meant for AJAX mode, so keep Try to ajaxify the shop off for that form.
Shop page, custom pages and page builders
The automatic narrowing needs a taxonomy archive. Elsewhere there is no current category:
- The main Shop page shows the whole catalogue, so until the visitor selects something, only values without any product in the store are hidden. That is correct behaviour.
- A WordPress page (a home page, a landing page, a page built with Elementor or Divi that lists one category) is not a category archive, even if it shows only that category's products. The filter cannot know it and lists everything.
On such a page, tell both shortcodes which category the page is about. Use the term ID from Products → Categories:
[woof taxonomies=product_cat:15]
[woof_products taxonomies=product_cat:15 per_page=12]
The taxonomies attribute of [woof] makes the counts and hiding follow that category, and the same attribute in [woof_products] limits the products shown. Several IDs of one taxonomy are separated with commas (product_cat:15,16, products in either), several taxonomies with a plus sign (product_cat:15+pa_color:22). It works only with the three options above switched on. The full setup of such pages is in the product filter on a custom page or homepage.
If you need a different set of sections per category rather than different values, see how to show different filters per category.
If the filter on a real category archive still behaves as on the Shop page, the theme's archive template may hide the current category from the plugin; this happens mostly with block-based templates. In Advanced → Options set Additional check of the category page to Yes.
A lighter option without dynamic recount
If you only need to hide terms that have no products anywhere in the store (old sizes, a brand you stopped selling), you do not need dynamic recount. This snippet asks WordPress to skip such terms when HUSKY loads them:
/*
* HUSKY: do not list terms that have no published products at all.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('woof_get_terms_args', function ($args) {
$args['hide_empty'] = true;
return $args;
});
It costs nothing at page load, but it does not know about the current category or the visitor's selection: a size that exists only in shoes still shows in the shirts category. If Cache terms is on, clear the terms cache after adding the code. The FAQ how to hide empty terms shows the same snippet.
What dynamic recount costs on large catalogues
Every term in the form needs its own count query on every page view, hidden ones included, so a form with 300 terms runs about 300 count queries. On a few thousand products this is unnoticeable; on tens of thousands it can slow every category page. Before switching the feature off:
- enable Cache dynamic recount number for each item in filter in Advanced → Options;
- use
dynamic_recount=0on forms where narrowing is not needed, for example a search form in the header; - consider Turbo mode, which filters and counts from a prepared data file instead of database queries.
The details are in how to speed up product filtering in large catalogues.
Checklist when irrelevant options still show
- Show count, Dynamic recount and Hide empty terms are all Yes (or the Turbo mode copies of them, if Turbo mode is on).
- The numbers are hidden with Hide terms count text, not by setting Show count to No.
- The widget's Dynamic recount field is Default or Yes; no
dynamic_recount=0in the shortcode. - You are testing on a real category archive, or the shortcode has
taxonomies=on a custom page. - The recount cache, the terms cache and the page cache were cleared after the change.
- The attribute's Logic of filtering is OR if other values must stay after a selection.
If all of this is in place and a category still lists values without products, open a topic on the HUSKY support forum with a link to the category page and the value that should be hidden.