skip to Main Content

I have added a search bar for my woocommerce products page. Some searches go to archive-product.php and some go to single-product.php. I want to disable the single-product shortcut. I have tried searching my problem on stackoverflow and google but all I get is search filter plugins.

How do I stop my search from going to single products and automatically search on my inventory list page?

To simplify my problem here is how it looks:

When haven’t search anything:
enter image description here

When I search "wheel" :

enter image description here

When I search "air filter":

enter image description here

This is my search bar code:

<div class="search-wrap">
            <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                <div class="search">
                    <label class="screen-reader-text " for="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>"><?php esc_html_e( 'Search for:', 'woocommerce' ); ?></label>
                    <input type="search" id="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>" class="search-field searchTerm" placeholder="<?php echo esc_attr__( 'Search products&hellip;', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
                    <button type="submit" class="searchButton" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>"><i class="fa fa-search"></i>
                    </button>
                    <input type="hidden" name="post_type" value="product" />
                </div>
            </form>
        </div>

2

Answers


  1. Chosen as BEST ANSWER

    Fixed by adding this into my functions.php

    add_filter( 'woocommerce_redirect_single_search_result', 'my_remove_search_redirect', 10 );
    function my_remove_search_redirect() {
        return false;        
    }
    

    Answer found here: https://removewcfeatures.com/disable-woocommerce-single-search-result-redirect/


  2. Add the following to functions.php

    add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
    

    Tested on fresh install and works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search