Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter stavroch

    (@stavroch)

    I need the default result page as the wp has.

    Plugin Author wpdreams

    (@wpdreams)

    Hi!

    You will need a small custom script to do the redirection, when it detects 1 result only.

    Try putting this into the functions.php file in your active theme directory:

    add_action('wp_footer', 'asl_redirect_on_single'); 
                    
    function asl_redirect_on_single() {          
      ?>
      <script>
      jQuery(function($) {
        $( document ).ajaxComplete(function( event, xhr, settings ) {
            if ( 
              typeof settings.data === 'string' &&
              settings.data.indexOf('=ajaxsearchlite_search') > -1
            ) {
              var $xhr = $.parseHTML(xhr.responseText);
              if ( $('a.asl_res_url', $xhr).length == 1 ) {
                $('.wpdreams_asl_results').css('display', 'none');
                window.location = $('a.asl_res_url', $xhr).attr('href'); 
              }  
            }
        });
      });
      </script>
      <?php
    }

    Make sure to clear all the cache layers you have to make this code effective. I hope this helps!

    Thread Starter stavroch

    (@stavroch)

    It helps.

    Thank you.

    Thread Starter stavroch

    (@stavroch)

    The above script works when the user will not press enter to search. Wait for some seconds and display the product page.
    It doesn’t work when you click the search icon or you enter the enter.

    Thread Starter stavroch

    (@stavroch)

    Any news about that?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘display product page when one result come’ is closed to new replies.