ryantaber
Forum Replies Created
-
Forum: Plugins
In reply to: [WP Search with Algolia] Indexing SKUs?If you’re still looking for a solution i came up with a pretty simple way to index skus.
Unfortunately i have not figured out how to use any of the plugins filters yet, so i went ahead and directly edited the plugin files.
1) Open the posts index file
wp-search-with-algolia\includes\indices\class-algolia-index.php2) Add this to the get_post_shared_attributes() function under line 209.
$product = wc_get_product( $post->ID ); //Get product from $post object $shared_attributes['sku'] = $product->get_sku(); //Get sku from $product object3) Next in the plugin settings re-index your products. In the Algolia dashboard you’ll see that skus are now a part of your indices. However they will not be searchable. To make them searchable, go to configuration > add searchable attribute > search and click sku. And that’s it!
Now you’ll be able to search by sku. If you want to display the sku in the results with a highlight. You must copy the autocomplete.php template file to /yourtheme/algolia/autocomplete.php and add…
<# if ( data.sku ) { #>
<span>Sku:data.sku</span>
<# } #>to where you see fit.