Hierarchical category filters missing on brand archives

Hi,

I found an issue with hierarchical taxonomy filters when using a Shop Archive template and template set for a Brands taxonomy.

The template contains a Filters element alongside Shop Products. The Categories filter is configured as:

  • Filter by: Taxonomy
  • Taxonomy: Product categories
  • Field type: Checkbox

Products and other filters display correctly, but the Categories filter disappears entirely on the brand archive. It displays in the builder’s general shop preview.

Changing the field type to Switch makes the categories appear, but we need the hierarchical checkbox layout. Toggling “Exclude parent taxonomy terms” makes no difference.

Example scenario

Consider this category structure:

Clothing
└── Outerwear
    ├── Jackets
    └── Coats

A product belongs to Brand A and is assigned only to Jackets. Coats contains products from Brand B.

On the Brand A archive, the expected category filter would show:

Clothing
└── Outerwear
    └── Jackets

Instead, the Categories field can disappear completely.

Why the current code appears to fail

In sc_filters() in functions/theme-shortcodes.php, Checkbox, Radio and Select fields set:

$terms_params['parent'] = 0;

On an archive, the query also adds:

$terms_params['object_ids'] = $product_ids;

Together, these request only top-level terms directly assigned to products in the current archive.

In the example, the product is directly assigned to Jackets, not Clothing. The query therefore returns no root terms, and the filter field is omitted.

Proposed change

For hierarchical controls:

  1. Fetch the terms assigned to the archive’s products, without the top-level restriction.
  2. Add their ancestors so the hierarchy can be displayed.
  3. Restrict the root query and every child query to that combined set.

This preserves the relevant hierarchy without introducing unrelated branches. It uses the selected taxonomy rather than hard-coding brands or product categories.

The proposed minimal diff against 28.5.10 is:

--- a/functions/theme-shortcodes.php
+++ b/functions/theme-shortcodes.php
@@
 					if( ( is_tax() || is_tag() || is_category() || is_archive() ) && !empty($product_ids) ) {
 						//$terms = mfn_get_available_attr_terms_in_current_view($product_ids, $excl_ids, $field['tax_filter'], $hierarchical);
 						$terms_params['object_ids'] = $product_ids;
+
+						if( isset($terms_params['parent']) ) {
+							$term_ids = get_terms(array_merge($terms_params, [
+								'parent'       => '',
+								'fields'       => 'ids',
+								'hierarchical' => false,
+							]));
+
+							if( is_wp_error($term_ids) || empty($term_ids) ) continue;
+
+							$included_ids = $term_ids;
+							foreach( $term_ids as $term_id ) {
+								$included_ids = array_merge(
+									$included_ids,
+									get_ancestors($term_id, $field['tax_filter'], 'taxonomy')
+								);
+							}
+
+							unset($terms_params['object_ids']);
+							$terms_params['include'] = array_unique($included_ids);
+							$terms_params['hide_empty'] = false;
+						}
 					}
@@
-							$term->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $term->term_id]);
+							$term->childrens = get_terms(array_merge($terms_params, [ 'parent' => $term->term_id ]));
@@
-									$termm->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $termm->term_id]);
+									$termm->childrens = get_terms(array_merge($terms_params, [ 'parent' => $termm->term_id ]));
@@
-											$termmm->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $termmm->term_id]);
+											$termmm->childrens = get_terms(array_merge($terms_params, [ 'parent' => $termmm->term_id ]));

Could you review this approach and consider incorporating a fix into the theme? I’ll leave the final implementation and wider compatibility/regression testing with your team.

This has been applied and working in my current setup at [Links visible only for registered users]

Thanks!

Comments

Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.