Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Product Variations Searchable but Show only Parent Products as Results
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 11 months, 1 week ago.
- AuthorPosts
- April 18, 2022 at 1:26 pm #37550
We have a woocommerce site and we need to have the Product Variations searchable on our site, however without showing the in the search results page and show only the Parent Product instead.
Do you know if there is a way to do this implementation? We have developers available and if need be we can hook with filters and hooks in order to modify the default’s plugin logic.
Attachments:
You must be logged in to view attached files.April 19, 2022 at 12:56 pm #37562Hi!
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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 19, 2022 at 2:11 pm #37568Thank you Ernest. In the meantime our developers tried with the below and it seems they got the desired result. I will keep a note of your suggestion in case they notice any issues with our approach. Thank you!
add_filter( 'asp_pagepost_results', __CLASS__ . '::remove_variants_products', 1, 1 );
public static function remove_variants_products( $pageposts ) { foreach ( $pageposts as $post_key => $pagepost ) { if( $pagepost->post_type == 'product_variation' ) { unset( $pageposts[$post_key] ); } } return $pageposts; }
April 20, 2022 at 3:08 pm #37583Great! Let me know if you need any more help 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.