This question is from Thomas:

How can I include my WooCommerce SKUs in my site’s search? Right now, customers enter the SKU and can’t find the product in my shop and I don’t see settings for search.


Currently, you can only search for WooCommerce SKUs in the admin of your shop (the “Products” list), and this search is restricted to only parent product SKUs, not variation SKUs. In WooCommerce 2.5 (due for release in a couple of weeks), you’ll be able to search your admin by SKU for parent product SKUs and variation SKUs.

However, this search functionality isn’t available on the frontend of your site; customers cannot search for product SKUs to return a list of products. If customers search for all or part of a SKU, and the search query isn’t contained anywhere else on the site, they’ll get no results.

WooCommerce SKU Search no results

We can make some changes that will let customers search for products by SKU on your site instead using search plugins that modify the default WordPress search.

WooCommerce SKU Search: Simple Products

If you have mostly simple products, then the easiest way to allow customers to search by SKU is to install the free Relevanssi plugin. This will replace you WordPress and WooCommerce product searches with the Relevanssi search, and will allow you to include product SKUs in the search index.

First, go to Settings > Relevanssi and configure your desired settings. The most important one to change right now is to include the “product” post type in your site’s search results.

WooCommerce Relevanssi product search

Enable products in search results

Once you’ve done that, you’ll want to add the custom field for your product SKU to your search index. Scroll down to “Custom Fields to index” and add _sku to this field (the underscore matters). This will tell Relevanssi to include SKUs in the search index, and lets customers enter the SKU as a search query.

WooCommerce Relevanssi Add SKUs to search

Add SKU to search index

Now when a customer searches for a string that’s part of your simple / parent product’s SKU, the product will be returned as a result:

WooCommerce SKU Search results

However, variation SKUs (if different from the parent product’s SKU), will not be searchable. Product variations are stored with some data separated from the parent product, and the SKU is one of these pieces of data. Therefore, if the variation’s SKU is different, searching for the variation SKU will not return the product in search results.

WooCommerce SKU Search: Variable Product SKUs

If you need to have variation SKUs included in your search index as well as simple / parent product SKUs, you’ll need to use SearchWP ($49+) instead of Relevanssi. The WooCommerce add-on / integration for it (included with any license) will let you include products within your search.

However, you can also add a bit of custom code to store variation SKUs on the parent product, as outlined by the plugin documentation. You can then include this custom field in your search, and variation SKUs will also be included in your search index.


Cover Photo Credit: Stefan Baudy (CC BY 2.0 license)
Articles you may also like:

Posted by Beka Rice

Beka Rice manages the direction of Sell with WP content and writes or edits most of our articles to share her interests in eCommerce. Or she just writes as an excuse to spend more time jamming out to anything from The Clash to Lady Gaga. Who knows.

7 Comments

  1. Hi there, tried the free plugin on our site full of simple products and searching for SKUs pulled in the results for seemingly every single product instead of the one in question. Any ideas? Website included for reference.

    Reply

    1. did you add the sku to the custom fields as well? is the SKU a generic bit of text that’s present on every product page? ie in my shop, if I search for a sku of “tee-“, I would get a ton of products because many have “tee-shirt” in the description.

      Reply

  2. hi Beka,

    great article, but I have the same issue as Amie with Relevanssi.

    I have SKUs like BS-6-FPR0439071 where BS- prefix for many SKUs , so I get back loads of results when searching for a SKU.

    Reply

  3. Experiencing the same issue – and that’s a feature and/or the point of Relevanassi plugin. It intentionally outputs “fuzzy matches” in search results, so if your sku is RLSF-12-B it’s going to return any product in the output that has RL, SF- or -12-B.

    So this isn’t actually a great solution to the problem of SKU searching.

    Reply

  4. Hi,

    Our website is an online bookshop and each SKU is a unique ISBN, with 99% of products being simple products. I’ve installed Relevansi and included _sku as a custom field but when I search by ISBN no results can be found.

    Is there any other workarounds to get this to work?

    Reply

    1. (1) are products indexed? (2) did you rebuilt the search index after saving these options?

      If both of those are done I’m afraid I’m not sure what could be the issue since I’ve set this up again myself and searching by SKU is looking good for me.

      Reply

  5. First of all, the article is plain wrong: Relevanssi can handle product variation SKUs just as well as SearchWP. If you want to index product variations, just adding “_sku” to the list of custom fields to index will cover them as well as the products. If you don’t want to index product variations but want to find the product when searching for the variation SKU, you can add one function to your theme functions.php to cover that: https://www.relevanssi.com/knowledge-base/indexing-product-variation-skus-main-product/

    No big deal there.

    What comes to problems searching for SKUs, if Relevanssi sees something like “BS-6-FPR0439071”, it’s interpreted as “BS 6 FPR0439071”. That’s not quite what you want, isn’t it. There’s a simple fix for this: just adjust how Relevanssi handles the hyphens. The default option is to replace them with spaces, but if you have SKUs like that, you either want to remove them (so the SKU becomes “BS6FPR0439071”) or to keep them. Here’s how you do that: https://www.relevanssi.com/knowledge-base/words-ampersands-cant-found/

    If you have Relevanssi problems, the WP.org support forum is a good place to ask, as I patrol it almost daily. https://wordpress.org/support/plugin/relevanssi

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *