• The product search widget differs by the search widget, the button jumps below the text field and there is no magnifying glass icon, can you redo the CSS to be the same?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Leo

    (@leohsiang)

    Hi there,

    Not sure if I fully understand.

    Can you link us to the page in question so we can see the issue?

    Thread Starter oyo84

    (@oyo84)

    https://ibb.co/XWhc4LN

    The product search engine differs in the standard one, the button pops up below and there is no icon, can it be modified or replaced with the standard URL to search for products?

    Leo

    (@leohsiang)

    Can you provide the site URL so I can see the issue?

    The product search isn’t coming from GeneratePress theme.

    Thanks ??

    Thread Starter oyo84

    (@oyo84)

    This is a widget built into WooCommerce, basic, apparently GP is not adapted to WooCommerce and hence the differences in the appearance of both elements.

    Thread Starter oyo84

    (@oyo84)

    How do I replace a regular search engine URL with a product search URL?

    Theme Author Tom

    (@edge22)

    Hi there,

    WooCommerce uses its own search template: https://github.com/woocommerce/woocommerce/blob/master/templates/product-searchform.php

    There are a couple of options:

    a) overwrite their template in your child theme to match the GP search form style.
    b) overwrite the theme search form template to search for products
    c) hook into the search query to search for products

    c) is likely the easiest route if you’re ok with all search queries looking for products. It would look something like this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( is_admin() && $query->is_main_query() ) {
            if ( $query->is_search() ) {
                $query->set( 'post_type', 'product' );
            }
        }
    } );

    Hope this helps ??

    Thread Starter oyo84

    (@oyo84)

    Unfortunately, it didn’t help me. I added the above code to the functions.php of the theme and the search widget works the same, ie it does not search for products but a standard query.

    Thread Starter oyo84

    (@oyo84)

    /**
    * Change search page slug.
    */
    
    function wp_change_search_url() {
        if ( is_search() && ! empty( $_GET['s'] ) ) {
            wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
            exit();
        }  
    }
    add_action( 'template_redirect', 'wp_change_search_url' );

    I have this code, but I do not know how to modify it to search for products from Woo …

    Theme Author Tom

    (@edge22)

    That’s probably not the best way forward.

    Instead, download this file as searchform.php: https://gist.github.com/tomusborne/e31af0f7cbc335a96c74553b86e95e18

    Then add it to your child theme: https://docs.generatepress.com/article/using-child-theme/

    That will make it so the GP search widget searches products.

    Thread Starter oyo84

    (@oyo84)

    How can I change the text of the placeholder and button?

    Hi,

    To clarify: You’re pertaining to the search form and button of woocommerce?

    If so, you can try following this article: https://wpbeaches.com/customize-woocommerce-product-search-field/

    This article’s The New Markup code should work.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Product search widget’ is closed to new replies.