• Resolved Jaswinder0091

    (@jaswinder0091)


    Is it possible to restrict the search in SKU to be exact same term, without showing other similar SKU numbers suggestions?

    Example – If I search for SKU 1800, right now it showing all the SKU products which have this 1800 in it like – 1800, 485418002, 31800600, etc.

    I like to search for exact 1 product with exact matching SKU

    • This topic was modified 3 years, 3 months ago by Jaswinder0091.
Viewing 1 replies (of 1 total)
  • Plugin Author Damian Góra

    (@damian-gora)

    Hi,

    It’s possible, but it requires simple custom code:

    
    add_filter( 'posts_search', function ( $search ) {
    
      if ( defined( 'DGWT_WCAS_AJAX' ) && DGWT_WCAS_AJAX ) {
        $search = str_replace( "dgwt_wcasmsku.meta_value LIKE '%", "dgwt_wcasmsku.meta_value LIKE '", $search );
      }
    
      return $search;
    }, 510 );
    

    You have two ways to add this code to your theme:

    1. Open the functions.php in your Child Theme and add the code at the end
    2. or install the Code Snippets plugin and apply this code as a snippet.

    This code replaces SQL LIKE Operator from LIKE '%your-sku%' to LIKE 'your-sku%'. It means that SKUs 485418002, 31800600 will no longer be searched after typing 1800.

Viewing 1 replies (of 1 total)
  • The topic ‘Limit search results’ is closed to new replies.