WooCommerce Product Search and Custom Taxonomies

A common support request we get for the WooCommerce Product Search extension, is the following:

I’m using a custom taxonomy on my WooCommerce shop, but when I search by its terms, I get no results. How can I achieve this?

For the majority of shops out there, the core taxonomies provided by WooCommerce should be enough. But there are always special cases where a custom taxonomy is needed. Added to that, there are also shops where a custom taxonomy was used prior to WooCommerce Product Search and it can be difficult to change the setup or the taxonomy structure because of that.

For those reasons and because we are constantly trying to provide tools that are as flexible as possible, we have added a filter hook exactly for that purpose since version 2.16.0 of the plugin.

woocommerce_product_search_indexer_filter_content

This filter hook allows you to include any custom taxonomy you are using, in the search engine’s index table. Once the taxonomy is indexed, the engine can produce results whenever you search by keyword using Product Search Field and Product Filter Search features.

In order to provide a complete example for this use case, we’ve implemented a small plugin called WooCommerce Manufacturer, which adds a new custom taxonomy called Manufacturer to the shop. This plugin uses the WordPress API for registering a new taxonomy and for simplicity reasons we won’t go into further details on how it works.

Once this plugin is installed and activated, we can create new Manufacturer terms and use them for our products.

For example, we have created a new Manufacturer called OnlyCotton and assigned it to two products, our Boho Skirt and Mini Skirt products. Obviously, the taxonomy can be used for any of the products in a shop.

The manufacturer archive for OnlyCotton term, looks like the following.

Product archive page for Manufacturers – OnlyCotton taxonomy term

Next step needed, is to install and activate WooCommerce Product Search Manufacturer addon and finally Rebuild our products index. As we mentioned earlier, this plugin will guide the search engine’s index to include the custom taxonomy for the products using it.

Once the index is rebuilt, keyword searches using Product Search Field, for terms of the Manufacturer taxonomy will result in matching products in the dropdown,

Product Search Field results dropdown when searching for onlycotton

and in the search results page, once we hit ENTER.

Search results page after searching for onlycotton

Also, when using the Product Filter Search that filters the products in a given context by keyword, for example when viewing the Shop archive and filter by onlycotton.

Shop archive after filtering by onlycotton

The WooCommerce Product Search Manufacturer addon can work with any product taxonomy that is using the WordPress API for custom taxonomies and all you need to do is modify a single line to make it compatible with yours.

private static $manufacturer_taxonomy = 'manufacturer';

Once you replace the ‘manufacturer’ with the name of your own product taxonomy, you should be able to enjoy the extension features.

If you have any questions regarding the implementation or how to customise it for your taxonomy, feel free to comment below.

Featured image and Shop screenshots by me.

, , , , , ,

No comments yet.

Leave a Reply

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share