Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    The second snippet should work both for main products and variations; it had a small bug that made the main products work. I’ve fixed that, so grab a copy of the updated snippet and you should be fine.

    Thread Starter andyt1980

    (@andyt1980)

    Thank you, working great now!

    Is there some way to make the search prioritise the product title.

    Currently if someone searches for ‘Pans’ its returning search results with products like ‘Induction Hob’ because it has the word ‘Pans’ in the product description. However, any actual pan product such as ‘Steel Induction Frying Pan’ is showing much further down the results list.

    Plugin Author Mikko Saari

    (@msaari)

    In the Relevanssi searching settings, you can increase the title weight, but it doesn’t help here as the word “pans” does not appear in the title.

    A couple of options:

    a) Use Relevanssi Premium and the Snowball Stemmer to stem the words to base forms to make “pans” match the “pan” in the title.

    b) Use synonyms. This requires the OR operator and can get wieldy if you have many terms.

    c) Use a custom field that has additional keywords with a high weight.

    Thread Starter andyt1980

    (@andyt1980)

    Thank you for this, I think the custom field option may be the way to go for us.

    Just one other query please. I’m using the following code to make sure out of stock items are shopwn at the end of any product listings/archives:

    add_filter( 'woocommerce_get_catalog_ordering_args', 'bbloomer_first_sort_by_stock_amount', 9999 );
     
    function bbloomer_first_sort_by_stock_amount( $args ) {
       $args['orderby'] = 'meta_value';
       $args['meta_key'] = '_stock_status';
       return $args;
    }

    However, this is not working for search results as I’m still seeing out of stock items first.

    Is there any way around this?

    Plugin Author Mikko Saari

    (@msaari)

    That hook has nothing to do with Relevanssi. Hook the function to something Relevanssi sees (like relevanssi_modify_wp_query), and it’ll work – but do add relevance to the orderby setting as a secondary order, otherwise you’ll get terrible results.

    Thread Starter andyt1980

    (@andyt1980)

    Thanks, I’ve tried the code below and it seems to be working, although I’m not sure how relevant the first results are:

    /* Order search results so in stock items first */

    add_filter( 'relevanssi_modify_wp_query', 'rlv_adjust_search' );
    function rlv_adjust_search( $query ) {
      $query->set( 'meta_key', '_stock_status' );
      $query->set( 'orderby', 'meta_value_num' );
      $query->set( 'order', 'ASC');
      return $query;
    }

    However, you mentioned relevance on the orderby. How would I add ‘meta_value_num’ and ‘relevance’ parameters to the same argument?

    Thanks,

    • This reply was modified 1 year, 11 months ago by andyt1980.
    Plugin Author Mikko Saari

    (@msaari)

    Instead of setting orderby and order separately, you can do it like this:

    $query->set( 'orderby', array( 'meta_value_num' => 'asc', 'relevance' => 'desc' ) );

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocommerce SKU Results’ is closed to new replies.