• Resolved lourencolemos

    (@lourencolemos)


    Hey lads, loving the plugin, a real life saver.

    Would it be possible to be able to search by REF-SKU? Instead ot typing Product 1 I would type 150033 And get the result.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I know the plugin has all sorts of filters around in its codebase, and I’m pretty sure at least some of them are for adding extra things to index, but which filters exactly is escaping me at the moment.

    includes/class-algolia-plugin.php looks like it has some promising filters, for what it’s worth and worth exploring.

    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.php

    2) 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 object

    3) 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.

    • This reply was modified 4 years, 6 months ago by ryantaber.
    • This reply was modified 4 years, 6 months ago by ryantaber.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Indexing SKUs?’ is closed to new replies.