• Resolved gabrielefortunato

    (@gabrielefortunato)


    Good morning,

    your plugin works really well.

    I would like to disable the search when less than 3 letters are entered in the search field.

    Is there a simple method to achieve it ?

    Thank you !
    Kind regards
    Gabriele

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • In plugin options you have it. Click “search bar” in options and change “minimal characters” to 3.

    Thread Starter gabrielefortunato

    (@gabrielefortunato)

    Thank you @rafix777 , but this option is “Min characters to SHOW AUTOCOMPLETE”.

    In fact, if I set minimum 3:

    1) when enter “Sa” (for Samsung) it doesn’t start autocomplete, but
    2) if I press enter or search, it gives the results of “Sa”

    I would like to stop the research/query.

    Any advice ?

    Thank you

    Plugin Author Damian Góra

    (@damian-gora)

    Hello,

    It require custom snippet. I prepared one:

    
    add_action( 'template_redirect', function () {
      if ( \DgoraWcas\Helpers::isProductSearchPage() ) {
    
        $keyword = get_search_query();
    
          if ( empty( $keyword ) || mb_strlen( $keyword ) < 3 ) {
            wp_redirect( home_url() );
            exit();
          }
    
      }
    });
    
    add_action( 'wp_footer', function () {
    ?>
    <script>
      (function ($) {
        $('.dgwt-wcas-search-form').on('submit', function (e) {
          if ($(this).find('.dgwt-wcas-search-input').val().length < 3) {
            e.preventDefault();
            return false;
          }
        });
      })(jQuery);
    </script>
    <?php
    }, 100 );
    

    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

    Best
    Damian

    Thread Starter gabrielefortunato

    (@gabrielefortunato)

    Beautiful ! Thank you @damian-gora

    If you fix also the flickering on scroll for the desktop I will vote WCAS for the Nobel of the plugin !

    Thank you
    Kind regards
    Gabriele

    Plugin Author Damian Góra

    (@damian-gora)

    Thanks. We will work on flickering scroll on the sticky menu in 2021.

    Best
    Damian

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Block Search With Minimum Letters’ is closed to new replies.