• Hey is there any snippet to just search for lets say the first 3 characters of a SKU?
    SKU example 30/2849302718 and 20/2949374303818

    When searching for “30” it finds the second one too. But i want it to just find the first one.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    Please use following code snippet

    add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
    function my_aws_search_query_array( $query ) {
        global $wpdb;
        $regex = "/term_source = 'sku' AND term LIKE '%(.*?)%'/is";
        $query['relevance'] = preg_replace( $regex, "term_source = 'sku' AND term LIKE '$1%'", $query['relevance'] );
        $regex = "/term_source = 'sku' AND term LIKE '{.*?}(.*?){.*?}'/is";
        $query['relevance'] = preg_replace( $regex, "term_source = 'sku' AND term LIKE '$1%'", $query['relevance'] );
        return $query;
    }

    You need to add it somewhere outside plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also after adding this code you will need to go to the plugin settings page and click ‘Clear cache’ button.

    Regards

    Thread Starter realhopedied

    (@realhopedied)

    How can i limit the SKU search to only lets say the first 3 characters?

    Plugin Author ILLID

    (@mihail-barinov)

    So, if user type inside search form, for example, 74303818, you want to search only for 743?

    Thread Starter realhopedied

    (@realhopedied)

    No ?? lets say there are the following products 70/284821, 12/027028, 20/703810 (all of them have 70) and the user types 70 inside the search form, then i want that only 70/284821 is shown instead of all of them. So for SKUs i want that only the first 3 characters are relevant.

    Plugin Author ILLID

    (@mihail-barinov)

    Well code snippet that I write previously will works exactly the same way – will show only 70/284821 when searching for ’70’.

    Thread Starter realhopedied

    (@realhopedied)

    Here is an image of what i mean https://ibb.co/0X4p2w3
    I added the snippet and clicked on ‘Clear cache’ button

    Plugin Author ILLID

    (@mihail-barinov)

    You enable only search for product SKU?
    Are you sure than other search sources are disabled?

    Thread Starter realhopedied

    (@realhopedied)

    Title Yes
    Content No
    SKU Yes
    Excerpt No
    Category No
    Tag Yes
    Attributes No
    Taxonomies No
    Custom Fields No

    Plugin Author ILLID

    (@mihail-barinov)

    Can you give me the link where I can test this search form?

    Thread Starter realhopedied

    (@realhopedied)

    Plugin Author ILLID

    (@mihail-barinov)

    As I see code snippet changes doesn’t applyed to your search form.
    Looks like you have old plugin version and this snippet just doesn’t works for you.
    If you use pro version – please email to [email protected] for instruction how to get latest plugin version.

    Thread Starter realhopedied

    (@realhopedied)

    Okay that helped. I already had PRO but a old version. Updated to the latest version and now it works. Great!!! Thank you very much for helping me out for so long. Greetings from hamburg germany

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘SKU search only first characters’ is closed to new replies.