• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Woocommerece Product Search Bar

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Woocommerece Product Search Bar

This topic is: not resolved

Tagged: bar, search, WooCommerce

  • This topic has 4 replies, 4 voices, and was last updated 6 years, 11 months ago by moma0503.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • January 21, 2015 at 8:07 pm #138233
    jfarr
    Member

    How can I put a Woocommerce Product Search Bar in my primary navigation?

    I currently have these hooks to add a general search bar in my navigation.

    // Add search bar
    add_filter( 'wp_nav_menu_items', 'genesis_search_primary_nav_menu', 10, 2 );
    function genesis_search_primary_nav_menu( $menu, stdClass $args ){
            
           
            if ( 'primary' != $args->theme_location )
            	return $menu;
            
                   if( genesis_get_option( 'nav_extras' ) )
                    return $menu;
            
            $menu .= sprintf( '<li class="custom-search">%s</li>', __( genesis_search_form( $echo ) ) );
            return $menu;
    }
    
    // Customize search bar text
    add_filter( 'genesis_search_text', 'sp_search_text' );
    function sp_search_text( $text ) {
    	return esc_attr( 'Search...' );
    }
    
    // Customize search bar button
    add_filter( 'genesis_search_button_text', 'sp_search_button_text' );
    function sp_search_button_text( $text ) {
    	return esc_attr( '' );
    }
    http://www.trade-tools.com/demo
    January 23, 2015 at 3:24 am #138396
    nickjco
    Member

    First we need to modify the search form and add the hidden input field:

    
    <input type="hidden" name="post_type" value="product">
    

    This will tell search that we are searching for a specific post type. Here is the function I created with the hidden input field.

    
    function custom_products_search( $form, $search_text, $button_text, $label ) {
    
    	$form  = sprintf( '<form method="get" class="search-form" action="%s" role="search">%s<input type="search" name="s" placeholder="%s" /><input type="submit" value="%s" /><input type="hidden" name="post_type" value="product"></form>', home_url( '/' ), $label, $search_text, esc_attr( $button_text ) );
    
    	return $form;
    }
    

    and then I modified your function above to with the add_filter and remove_filter lines:

    
    function genesis_search_primary_nav_menu( $menu, stdClass $args ){
            
           
            if ( 'primary' != $args->theme_location )
            	return $menu;
            
                   if( genesis_get_option( 'nav_extras' ) )
                    return $menu;
    
            add_filter( 'genesis_search_form', 'custom_products_search', 10, 4 );
            
            $menu .= sprintf( '<li class="custom-search">%s</li>', __( genesis_search_form( $echo ) ) );
    
            remove_filter( 'genesis_search_form', 'custom_products_search', 10 );
            
            return $menu;
    }
    

    I added the filter in this function so that it will only affect that form you are adding. Hope this helps!

    January 24, 2015 at 8:37 am #138505
    jfarr
    Member

    @nickjco thank you for your response! Where do I put <input type="hidden" name="post_type" value="product"> ? Do I have to put it in index.php? Is there any way I can put it in through my menu or by a hook? Also this will not affect my 404 search bar correct. Thank you again.

    January 30, 2015 at 12:24 am #139016
    Wooassist
    Member

    Hey @jfarr, the hidden input field is already added in the function custom_products_search. You'll just have to add this to your functions.php and replace your original function of genesis_search_primary_nav_menu with the function I posted above.

    April 14, 2016 at 12:25 pm #183615
    moma0503
    Member

    This has helped me out tremendously. Thank you both.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble