Filtering by custom field
The WooCommerce Product Filters plugin comes with a custom field filter, which you can display as dropdown lists, radio buttons, checkboxes, range sliders, or text input fields.
This article explains how custom field filters work, and how to create the custom fields.
How to create custom fields
We have decided the custom field filter in WooCommerce Product Filters to work with custom fields created using the following plugins:
- Easy Post Types and Fields (free) - Easily add Text or Visual Editor custom fields to the 'Products' post type in WooCommerce. Both field types work with your custom field filters.
- Advanced Custom Fields (free or pro) - Add a wide range of custom fields to the 'Products' post type. The custom field filter supports the following field types: radio, select, true/false, text, and number. For true/false custom fields, the Filter type dropdown is hidden so that the filter always appears as radio buttons.
We recommend using Easy Post Types for the simplest and easiest to use solution, or Advanced Custom Fields (ACF) if you need more features, such as additional field types.
Text input custom field filters
You can choose to display custom field filters as a text input field, where the customer types a keyword in order to filter the list of products. For example, if you are using a custom field to store a reference number for each product, then the customer can enter a reference number.
Tip #1: Use Easy Post Types to create the custom field
If you are creating a 'Text input' custom field filter then we recommend using the Visual Editor field type in Easy Post Types and Fields. This is because the logic used for the search is more advanced, and uses the same logic as the main search which is part of WordPress itself.
If you use any other field type (e.g. any ACF field, or an Easy Post Types text field), then the search will be exact match. This means that it is case sensitive and results will only be found if the customer enters a query that exactly matches the data stored in the custom field.
Tip #2: Use the 'button click' filter method
For best results, if you're displaying a custom field filters as a text input search box, then we recommend enabling the button click filter mode. This is because if you use the default AJAX method for your filtering, then the list of products will start updating as soon as the customer starts typing into the search box, which might look strange. With this type of filter, it's better for the customer to click an 'Apply Filters' button after they have finished typing.