Require a custom Change in Trade Theme Filter

Require a custom Change in Trade Theme Filter

big99dev
Visitor
1 0 0

We are having a store which is using shopify theme Trade 

=> want a help to make some custom change in filter like when we have category of product and the particular  category is selected  then that category should move to the top in category filter 

 

=> if the particular category is selected then in other filter option the option option should be visible which is related to that category other should get hide automatically 

 

require a solution code and file name which need to be changed 

 

Thanks & Regards

Screenshot 2025-06-02 122147.png

Screenshot 2025-06-02 131608.png

  

  

Reply 1 (1)

Small_Task_Help
Shopify Partner
1120 53 111

Hi,

Hope this will work

- Make Selected Category Go to Top
- Show Only Relevant Filter Options Based on Category
Code Example (add to collection.js or facets.js)

document.addEventListener("DOMContentLoaded", function () {
  const categoryFilter = document.querySelector('[name="filter.v.category"]');
  const filterGroups = document.querySelectorAll('.facets__disclosure');

  // Define which filters are allowed per category
  const categoryToFilters = {
    "Shoes": ["Size", "Color"],
    "Shirts": ["Color", "Material"],
    "Bags": ["Type", "Size"]
  };

  function updateFilters() {
    let selectedCategory = document.querySelector('[name="filter.v.category"]:checked');
    if (!selectedCategory) return;

    let allowed = categoryToFilters[selectedCategory.value] || [];

    filterGroups.forEach(group => {
      let label = group.querySelector('.facets__summary').textContent.trim();
      if (label === "Category") return; // Always show category
      if (allowed.includes(label)) {
        group.style.display = "";
      } else {
        group.style.display = "none";
      }
    });
  }

  // Run initially
  updateFilters();

  // Re-run on category change
  categoryFilter?.addEventListener("change", updateFilters);
});
To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad