This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Product Variations Searchable but Show only Parent Products as Results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Product Variations Searchable but Show only Parent Products as Results Reply To: Product Variations Searchable but Show only Parent Products as Results

#37562
Ernest MarcinkoErnest Marcinko
Keymaster

Hi!

I believe it is possible, and the only way is to use the index table engine, along with a custom code snippet.

First, make sure to configure the index table engine, only to index the product post type (and everything else you may want to search, except the product variations).
Then using this custom code, to append the variation information to the actual product:

add_filter( 'asp_post_content_before_tokenize_clear', 'asp_tokenize_sku_variation', 10, 2 );
function asp_tokenize_sku_variation($content, $post) {
  if ( $post->post_type == 'product' && ($variations = $_product->get_children()) ) {
	foreach ( $variations as $variation ) {
		$content .= ' ' . $variation->get_description();
		$content .= ' ' .  $variation->get_sku();
	}
  }

  return $content;
}

I have not been able to test this code for now. It should get all the variations for each product during indexing, and then append their SKU and descriptions to the main product. So searching variation data should yield the parent product as the result.