The search attributes feature allows users to search all attributes. In some cases, you should exclude attributes that make no sense for the search process.
How to add the code?
- Open the
functions.php
file in your child theme and add the code at the end - Or install the Code Snippets plugin and apply this code as a snippet.
Where can you find the attribute names?
In WooCommerce an attribute is a custom taxonomy. To exclude attributes we use the taxonomy name. WooCommerce adds the prefix “pa_
” for each attribute slug to create custom taxonomies. If an attribute has the slug “height
”, the taxonomy will be “pa_height
”. If you don’t know how to check the taxonomy for an attribute, take a look at the following screen.
Go to WooCommerce
→ Attributes
→ Edit
→ check the URL
Custom snippet
/** * Attributes to exclude * * @return array */ function wcas_get_attributes_to_exclude() { return array( 'pa_calipers', //Replace with yours!!! 'pa_case-size' //Replace with yours!!! ); } /** * Exclude attribute every time when the product is updated * * @return array */ add_filter( 'dgwt/wcas/product/attributes', function ( $attributes ) { foreach ( wcas_get_attributes_to_exclude() as $taxonomy ) { if ( array_key_exists( $taxonomy, $attributes ) ) { unset( $attributes[ $taxonomy ] ); } } return $attributes; } ); /** * Exclude attribute every time when the whole index process is running * * @return array */ add_filter( 'dgwt/wcas/attribute_taxonomies', function ( $taxonomies ) { foreach ( wcas_get_attributes_to_exclude() as $taxonomy ) { if ( ( $key = array_search( $taxonomy, $taxonomies ) ) !== false ) { unset( $taxonomies[ $key ] ); } } return $taxonomies; } );
After adding the code, remember to rebuild the search index.
Go to WooCommerce
→ FiboSearch
→ Indexer (tab) and rebuild the search index
. Wait for this process to finish.