1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Advanced Usage

Code snippet: How to restore partial matching in WooCommerce Product Table search

WooCommerce Product Table (5.0 and later) uses an indexed search system which is designed to make searches faster, especially on larger stores. The indexed search matches the beginning of each indexed word or token. For example, if your table contains:

  • Information about Glass
  • Form for Glass

Searching for "form" with the indexed search will find "Form for Glass", because "form" is a complete token. However, it will not find "Information about Glass", because "form" appears in the middle of the "Information" token.

If you need the search to match a term anywhere within the data, you can disable the indexed search and restore the default WordPress search behavior by adding the following code to your website. If you're unsure how to use it, then read our article about code snippets:

add_filter( 'wc_product_table_use_indexed_search', '__return_false' );

This switches WooCommerce Product Table back to the standard WordPress search instead of using the indexed search. As a result, searches can match text anywhere within a value.

Performance

The indexed search was introduced to improve search performance, so disabling it can make searches slower. This is more likely to be noticeable on stores with a large number of products or a lot of searchable data. For smaller stores, the difference may be minimal.

Partial SKU matching

SKUs are indexed as special tokens, so a search for a full SKU or the start of a SKU will match. If your customers search for a fragment from the middle of a SKU, for example the last four characters of a part number, the indexed search will not find it and this snippet is the simplest fix. See search tokenization and language support if you would rather change how SKUs are tokenized instead of turning the index off.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.