Shopify Menu customisation....

Shopify Menu customisation....

UboraGroup
Visitor
3 0 0

I think it's possible to alter the menu system a lot on a store front by using CSS...

 

Is there a way to code a menu to come up as a selector box instead if a long list of options. This is for a Search & Discovery powered menu, I've got 3 metafields per product however these are options that will go into the hundreds, which I don't mind but I don't need hundreds of menu items to display at the same, a drop down would shorten it a lot and a customer can select 1 item from each menu using the drop down and each menu filters the other menus down based on any of the selections of the other 2, in any order.

Replies 8 (8)

rajweb
Shopify Partner
814 70 151

Hey @UboraGroup ,

Yes, you can definitely achieve a dynamic and interactive menu system using CSS, JavaScript, and Shopify's metafields to create a dropdown menu for your Search & Discovery-powered navigation. This approach will help manage long lists of options while allowing customers to filter products based on their selections from the dropdown menus.

 

1. HTML Structure for the Dropdown Menus:

You can create dropdowns for each category (based on your metafields), and use JavaScript to filter the other dropdowns based on the selection. Here’s an example structure:

<div class="dropdowns">
  <select id="filter1">
    <option value="">Select Option 1</option>
    <!-- Dynamically populate with metafield values -->
  </select>

  <select id="filter2">
    <option value="">Select Option 2</option>
    <!-- Dynamically populate with metafield values -->
  </select>

  <select id="filter3">
    <option value="">Select Option 3</option>
    <!-- Dynamically populate with metafield values -->
  </select>
</div>

2. Populating the Dropdowns Dynamically:

You can use Shopify's Liquid templating language to pull the values from the product metafields and create the options dynamically. Here’s a simplified example of how to populate the dropdowns with metafield data:

{% assign metafield1_values = product.metafields.custom.filter_1 %}
{% assign metafield2_values = product.metafields.custom.filter_2 %}
{% assign metafield3_values = product.metafields.custom.filter_3 %}

<select id="filter1">
  <option value="">Select Option 1</option>
  {% for value in metafield1_values %}
    <option value="{{ value }}">{{ value }}</option>
  {% endfor %}
</select>

<select id="filter2">
  <option value="">Select Option 2</option>
  {% for value in metafield2_values %}
    <option value="{{ value }}">{{ value }}</option>
  {% endfor %}
</select>

<select id="filter3">
  <option value="">Select Option 3</option>
  {% for value in metafield3_values %}
    <option value="{{ value }}">{{ value }}</option>
  {% endfor %}
</select>

3. JavaScript for Filtering Selections:

Now, you'll need some JavaScript to dynamically filter the dropdowns based on the user’s selections. Here's an approach where each dropdown is filtered based on previous selections:

document.addEventListener("DOMContentLoaded", function() {
  const filter1 = document.getElementById("filter1");
  const filter2 = document.getElementById("filter2");
  const filter3 = document.getElementById("filter3");

  // Function to filter options in dropdowns based on previous selections
  function filterOptions() {
    // Get selected values from the filters
    const selected1 = filter1.value;
    const selected2 = filter2.value;
    const selected3 = filter3.value;

    // Filter logic based on selected values
    // Update options of filter2 based on filter1, and filter3 based on filter2, etc.
    // For simplicity, assuming you have pre-defined data for filtering
    const data = {
      filter1: ["Option 1", "Option 2", "Option 3"],
      filter2: {
        "Option 1": ["Sub-option 1a", "Sub-option 1b"],
        "Option 2": ["Sub-option 2a", "Sub-option 2b"],
      },
      filter3: {
        "Sub-option 1a": ["Sub-sub-option 1aa", "Sub-sub-option 1ab"],
        "Sub-option 2a": ["Sub-sub-option 2aa", "Sub-sub-option 2ab"],
      },
    };

    // Update filter2 options based on filter1 selection
    const options2 = data.filter2[selected1] || [];
    filter2.innerHTML = '<option value="">Select Option 2</option>';
    options2.forEach(option => {
      const optionElement = document.createElement("option");
      optionElement.value = option;
      optionElement.textContent = option;
      filter2.appendChild(optionElement);
    });

    // Update filter3 options based on filter2 selection
    const options3 = data.filter3[selected2] || [];
    filter3.innerHTML = '<option value="">Select Option 3</option>';
    options3.forEach(option => {
      const optionElement = document.createElement("option");
      optionElement.value = option;
      optionElement.textContent = option;
      filter3.appendChild(optionElement);
    });
  }

  // Add event listeners to trigger filtering
  filter1.addEventListener("change", filterOptions);
  filter2.addEventListener("change", filterOptions);
  filter3.addEventListener("change", filterOptions);

  // Initial filter load
  filterOptions();
});

4. CSS for Styling:

To style the dropdowns and the overall look of your menu, you can add some CSS to make the interface clean and user-friendly:

#filter1, #filter2, #filter3 {
  width: 200px;
  padding: 10px;
  margin: 10px 0;
  border-radius: 4px;
  border: 1px solid #ddd;
  background-color: #fff;
}

#filter1, #filter2, #filter3 {
  display: inline-block;
}

This method allows you to simplify your menu system significantly by using dropdowns instead of showing hundreds of options at once. The selections can be dynamically filtered based on what the customer chooses, making for a more intuitive and interactive shopping experience.

Let me know if you need any further clarification or help with the implementation!

 

If I was able to help you, please don't forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!

Best Regard,
Rajat Sharma

 

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev
UboraGroup
Visitor
3 0 0

Hi,

 

I probably need to be more specific, a menu already exists, powered by Shopify Search & Discovery, it is auto-matically populated using Metafield data held in each product using a custom metafield. These are assigned to the collection pages. On the lefthand side appears a navigation menu, starting with the main menu set by Shopify default which are the main parent categories set by shopify, modified to my store, so for example you'd have clothes, books, electronics etc.

 

below this is search and discovery navigation which is set by search and discovery, not the normal shopify navigation. This includes by default, brand, product type, price etc, now i've added categories to this, which is where as mentioned above the navigation grows because lets say the price menu display items at £1, £2, £3 all the way to a million there would be a huge navigation menu reaching to china.

 

Instead of this, the price portion has a slider, what dictates that this part of the menu is a slider of prices, rather than a list? That is what I want to do to my menu, but instead of a slider I want it to dictate these metafield options are in a drop down box, rather than a list, but as it is a search and discovery powered menu I can't make alterations to the normal navigation.

 

I don't need menu html, the menu already exists and is live in the store, and I don't need CSS as the CSS style is already dictated in the shopify template, I just want those 3 portions of the search and discovery metafield powered menu to come up as a selector box instead of a list. I will try to track down where in the code that the price field is dictated to be a slider as this must be where the code dictates how a menu is displayed and functions for the search and discovery powered fields.

rajweb
Shopify Partner
814 70 151

@UboraGroup ,

Ah, I see! You're working with the Search & Discovery app, and you want to change the behavior of the metafield-powered filters so they show as a dropdown selector instead of a long list, similar to how the price filter is displayed as a slider.

Since Search & Discovery  is managed via Shopify's dynamic filtering system and doesn't allow direct customizations of its interface via the theme, achieving this effect may require overriding the default rendering behavior of these filters using JavaScript.

Here’s how you can approach it:

1. Identify the Price Slider Code:

As you mentioned, the price filter is already displayed as a slider. The feature that controls this might be part of the  Shopify Search & Discovery app or a custom script that is applied to the price range filter:

To adjust the other metafield filters in a similar manner, you'll need to identify the script that handles the price slider.

-Check your theme’s JavaScript files, especially in theme.js or filters.js. Look for code related to the price slider, likely involving an input range (e.g., <input type="range">)and an event listener for filtering.

-Look for sections like:

 

const priceSlider = document.querySelector('.price-slider');
// Code for price slider interactions

 

Once you locate this section, you can base your custom dropdown functionality on it.

2. Transform Other Filters into Dropdowns:

You will need to use JavaScript to manipulate the HTML of the filters, turning the long lists of options (e.g., brands, categories, etc.) into dropdowns instead of checkboxes or list items.

Here’s an outline of what needs to happen:

-Step 1: Target the filter containers for your metafield-powered options. These are likely rendered in a ul or div format with list items.

-Step 2: Replace those elements with <select> dropdowns, and populate the dropdown options with the corresponding values.

-Step 3: Use JavaScript to listen for changes in the dropdown and apply the filters accordingly.

Example JavaScript Outline for Dropdown Transformation:

 

document.addEventListener("DOMContentLoaded", function() {
  // Example selectors for filters (modify these based on your theme structure)
  const brandFilter = document.querySelector('.brand-filter');
  const categoryFilter = document.querySelector('.category-filter');
  const metafieldFilters = document.querySelectorAll('.metafield-filter');

  // Function to convert filters to dropdowns
  function convertToDropdown(filter) {
    const options = filter.querySelectorAll('li');  // Assuming the filter items are <li> elements
    const dropdown = document.createElement('select');

    // Create a default "Select" option
    const defaultOption = document.createElement('option');
    defaultOption.textContent = 'Select an option';
    dropdown.appendChild(defaultOption);

    // Populate dropdown options with the filter items
    options.forEach(option => {
      const value = option.textContent.trim();  // Get the filter text
      const optionElement = document.createElement('option');
      optionElement.value = value;
      optionElement.textContent = value;
      dropdown.appendChild(optionElement);
    });

    // Replace the filter list with the dropdown
    filter.innerHTML = '';  // Clear the existing filter content
    filter.appendChild(dropdown);

    // Optional: Add event listener to apply filters when the dropdown selection changes
    dropdown.addEventListener('change', function() {
      applyFilter(filter, dropdown.value);
    });
  }

  // Apply the selected filter to update the products displayed
  function applyFilter(filter, value) {
    // Your logic to update products based on the selected filter
    console.log(`Applying filter: ${filter}, with value: ${value}`);
    // Make an API call or manipulate the DOM to update product list
  }

  // Convert each metafield filter into a dropdown
  metafieldFilters.forEach(convertToDropdown);
});

 

3. Integrating with Search & Discovery:

You might need to hook into the Search & Discovery filter system itself. If Shopify’s filters are powered via JavaScript (AJAX), the filter selections will need to trigger the re-filtering of products. If you're handling metafield filters, ensure that:

-Your dropdowns are capturing the right filter data.

-You're triggering the product filtering dynamically without reloading the page.

The  Search & Discovery app likely uses AJAX to dynamically load products based on the selected filters. In that case, you'd need to ensure that when a selection is made in the dropdown, it sends the correct parameters to the Shopify filters.

 

4. Test and Debug:

Once you’ve written the JavaScript code:

  1. Load your collection page and check if the dropdowns are appearing correctly.
  2. Test if the filter options change dynamically as expected when selections are made.
  3. Check if the page updates the product listings or refines the product selection according to the selected options.

5. Consider Shopify Plus or Custom Apps for More Control:

If you're using  Shopify plus or a custom app, you may be able to integrate more deeply with the Shopify search system. This can allow you to bypass the limitations of the Search & Discovery app and have more control over the filtering UI and behavior.

 

 

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev
JesseSuarez
Visitor
3 0 0

 

Hey! Love your answer, so detailed! 
may be you also could help me with my question. 
i need to show inventory visible live in dropdown product menu for client like on screenshot 

half of products options are ready to order and some all “make to order”, but all are available and i need to show what option is what without choosing it. Is it possible to make ?

IMG_6070.jpeg

rajweb
Shopify Partner
814 70 151

Hey @JesseSuarez ,

Yes, We've updated the product dropdown to display live inventory status. Customers can now see whether a product is "In Stock" or "Made to Order" without selecting it.

Here’s the code we implemented:

<select name="id" id="ProductSelect">
  {% for variant in product.variants %}
    {% assign stock_status = "Made To Order" %}
    {% if variant.inventory_quantity > 0 %}
      {% assign stock_status = "In Stock" %}
    {% endif %}
    
    <option value="{{ variant.id }}">
      {{ variant.title }} - {{ stock_status }}
    </option>
  {% endfor %}
</select>

Let me know if you need any adjustments!

If I was able to help you, please don't forget to Like.

If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out in my signature below—I’m here to help bring your vision to life!

Best,

Rajat

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev
JesseSuarez
Visitor
3 0 0

Rajweb, thank you for your answer
Could you please leet me know where exactly i need to paste this code? 
Main-product.liquid?

JesseSuarez
Visitor
3 0 0

  I've paste this code to main-product.liquid and it works, but new field appear (you could see result in 1st screenshot). But what i need is on 2nd screenshot. Is it possible to make it?

IMG_6229.PNG

IMG_6230.jpg

rajweb
Shopify Partner
814 70 151

@JesseSuarez 

I understand your concern! Could you please DM me using the contact details in my signature? That way, I can assist you more effectively and guide you step by step to achieve the exact result you're looking for. Thanks!

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev