• Resolved ClikIT

    (@bww)


    Hi,

    Is it possible to be able to press the search icon and have it come up with all results for the store? The workflow I want is: User searches for product > user doesn’t find the product, removes the the search query and presses the search icon to reveal all products.

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

    (@mihail-barinov)

    Hello,

    Looks like I found the solution for you. Please use following code snippet:

    add_action( 'wp_head', 'my_aws_head' );
    function my_aws_head() { ?>
        <script>
            window.addEventListener('load', function() {
                jQuery('.aws-search-btn').on( 'click', function (e) {
                    var form = jQuery(this).closest('.aws-search-form');
                    var searchField = form.find('.aws-search-field');
                    if ( searchField.val() === '' ) {
                        searchField.val('all');
                        searchField.closest('form').submit();
                    }
                });
            }, false);
        </script>
    <?php }
    add_filter('aws_search_query_array', 'my_aws_search_query_array');
    function my_aws_search_query_array( $query ) {
        if ( strpos( $query['search'], 'all' ) !== false ) {
            $query['search'] = '';
            $query['relevance'] = '1';
        }
        return $query;
    }

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

    Regards

    Thread Starter ClikIT

    (@bww)

    That is awesome! Thank you so very much! Is there a way to just have it be blank or a space or “” instead of the word all?

    Additionally, I have no use for the Pro version, but is there a way I can donate to you?

    Plugin Author ILLID

    (@mihail-barinov)

    You can try to use this code instead:

    add_action( 'wp_head', 'my_aws_head' );
    function my_aws_head() { ?>
        <script>
            window.addEventListener('load', function() {
                jQuery('.aws-search-btn').on( 'click', function (e) {
                    var form = jQuery(this).closest('.aws-search-form');
                    var searchField = form.find('.aws-search-field');
                    if ( searchField.val() === '' ) {
                        searchField.val(' ');
                        searchField.closest('form').submit();
                    }
                });
            }, false);
        </script>
    <?php }
    add_filter('aws_search_query_array', 'my_aws_search_query_array');
    function my_aws_search_query_array( $query ) {
        if ( strpos( $query['search'], ' ' ) !== false || strpos( $query['search'], '032' ) !== false ) {
            $query['search'] = '';
            $query['relevance'] = '1';
        }
        return $query;
    }

    About donation – thanks for that. You can use this link.

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Searching an empty search bar’ is closed to new replies.