Shopify 部分SKU搜索功能实现咨询:支持SKU片段匹配
Hey there! Let's tackle this partial SKU search issue for your Shopify store. I’ve dealt with this exact scenario a handful of times, so here are the most reliable solutions depending on your technical comfort level and store size:
First, let's rule out the simplest fix—Shopify’s built-in search might already support partial matches, but it’s easy to overlook the setting:
- Head to your Shopify Admin > Online Store > Navigation
- Find your search bar menu item (usually labeled "Search") and click "Edit"
- Look for the Search behavior section and ensure "Partial matches" is enabled.
A quick note: Shopify’s native partial matching works best for prefixes (e.g., searching "DPT" would find DPT10203), but it might not catch middle/suffix fragments like "10203" out of the box. If that’s the case, move on to the solutions below.
If you have basic Liquid skills, you can manually check each product’s SKU for the search term and display matching items. Here’s how:
- Go to Shopify Admin > Online Store > Themes > Actions > Edit Code
- Locate the
search.liquidtemplate (ortemplates/search.liquid, depending on your theme) - Replace the default product loop with this custom logic (adjust the product card code to match your theme’s design):
{% assign search_term = search.terms | downcase %} {% assign matching_products = collections.all.products | where_exp: 'product', 'product.sku | downcase contains search_term' %} {% if matching_products.size > 0 %} <h2>Products matching SKU fragment: "{{ search_term }}"</h2> <div class="product-grid"> {% for product in matching_products %} <div class="product-card"> <a href="{{ product.url }}"> <img src="{{ product.featured_image | img_url: '300x300' }}" alt="{{ product.title }}"> <h3>{{ product.title }}</h3> <p>SKU: {{ product.sku }}</p> <p>{{ product.price | money }}</p> </a> </div> {% endfor %} </div> {% else %} <!-- Fallback to default search results if no SKU matches --> {{ content_for_layout }} {% endif %}
This code:
- Converts both the search term and SKUs to lowercase for case-insensitive matching
- Checks every product in your store (or replace
collections.allwith a specific collection to narrow it down) - Displays matching products first, or falls back to default search results if no matches are found
Warning: If you have 1000+ products, this method might slow down your search page load time. For larger catalogs, use the metafield approach below.
For stores with lots of products, metafields let you index SKU fragments directly, so Shopify’s native search can find them without looping through every item:
- Create a metafield definition:
- Go to Shopify Admin > Settings > Metafields > Products > Add definition
- Name it "Searchable SKU Fragments"
- Set Namespace and key to
search.sku_fragments - Choose "Single line text" as the type
- Populate the metafield:
- For each product, add all relevant SKU fragments to the metafield. For SKU
DPT10203, you could use:DPT10203, DPT1020, DPT102, DPT10, DPT, 10203, 1020, 102, 10 - To save time, use bulk editing or Shopify Flow to auto-generate these fragments for all products (e.g., a Flow that splits the SKU into chunks and saves them to the metafield when a product is updated)
- For each product, add all relevant SKU fragments to the metafield. For SKU
- Index the metafield in search:
- Go to Shopify Admin > Online Store > Navigation > Edit Search menu item
- Under "Searchable resources", ensure "Products" is checked
- Under "Product fields", add the
search.sku_fragmentsmetafield you created
Now, when a user searches for "10203", Shopify’s native search will find the metafield containing that fragment and return the correct product.
If you don’t want to touch code or metafields, there are dozens of Shopify App Store tools that support partial SKU search out of the box. Popular options include:
- Instant Search +: Offers fast partial matching for SKUs (and other product fields)
- Searchanise: Advanced search with built-in partial SKU detection
- Algolia Search: Enterprise-level search with full support for partial SKU queries
These apps replace your default search bar and handle indexing/matching automatically—great for stores that want a polished, hands-off solution.
内容的提问来源于stack exchange,提问作者JimKT

