Searching product-level attributes in WooCommerce
-
WooCommerce allows two types of product attributes: global attributes and product-level attributes. Global attributes are a taxonomy, and product-level attributes are post meta. I’ve set up Relevanssi to search global attributes, but can’t get it to search product-level attributes. I think this is because product-level attributes aren’t post meta belonging to posts of type “product.” They belong to posts of type “product_variation,” which aren’t public.
Lots of shops use product-level attributes and it would be fantastic to be able to search them — I would suggest returning the parent product when a particular product_variation is found to contain the search term. More details below:
Product-level attributes get saved in a post meta field called attribute_[attribute name], for example, attribute_color. When these attributes are used to create product variations, this post meta field belongs to a CPT of type product_variation. Relevanssi can index this field and I can see the values in the Relevanssi table in the database (with a 1 in the customfield column), but no results get returned when I search for a word that appears only in a product-level attribute. For example, I have a color called ‘aquamarine’ and I can see it in the Relevanssi table, but no products get returned when I search using that word.
product_variation is registered as follows:
register_post_type( "product_variation", apply_filters( 'woocommerce_register_post_type_product_variation', array( 'label' => __( 'Variations', 'woocommerce' ), 'public' => false, 'hierarchical' => false, 'supports' => false ) ) );
I’ve hooked into the filter to make public = true and explicitly set exclude_from_search = false, but it doesn’t help.
Is there any hope of Relevanssi returning products that have variations that match the search term?
- The topic ‘Searching product-level attributes in WooCommerce’ is closed to new replies.