Add Product Search to WooCommerce Catelog
-
Trying to add a product search bar to my WooCommerce store product catelog.
The page I need help with: [log in to see the link]
-
Hi there,
Where are you trying to add it?
Top right above the products below the navigation bars.
Best way I can think of is to:
1. Install this plugin: https://wordpress.org/plugins/shortcode-widget/
2. Add the product search widget to that widget area, and note the shortcode.
3. Use a hook to insert the shortcode into that area:
add_action( 'generate_before_main_content', function() { if ( function_exists( 'is_shop' ) && is_shop() ) { echo '<div class="shop-search">'; echo do_shortcode( '[your-shortcode'] ); echo '</div>'; } } );
Adding PHP: https://docs.generatepress.com/article/adding-php/
Then you’ll need some CSS to place it – feel free to report back once the above is done and I can help with the CSS.
There is no widget placement for that area.
- This reply was modified 4 years, 2 months ago by Doug Demagistris.
There should be a couple: https://docs.woocommerce.com/document/woocommerce-product-search/widgets/
Product Filter – Search
Product Search FieldYes, but there’s no widget area where I want the search bar to be.
That’s where you need the plugin I mentioned: https://wordpress.org/plugins/shortcode-widget/
That plugin adds a new widget area, which then provides a shortcode that you can use to display the widget anyway (outside of a standard widget area).
Then you can use the code I mentioned above (with your shortcode you aquired above): https://wordpress.org/support/topic/add-product-search-to-woocommerce-catelog/#post-12415031
I installed the plugin, but there’s no new widget area outside the standard widget areas.
See here: https://ibb.co/NFF0rsFAh, I’m sorry! I linked to the wrong plugin.
Try this one instead: https://wordpress.org/plugins/amr-shortcode-any-widget/
Ok, great! All set for the CSS.
This is the CSS:
.shop-search { float: right; } .shop-search .woocommerce-product-search { display: flex; }
Right now the search is only on your shop page. You may need to update the function to show on categories:
add_action( 'generate_before_main_content', function() { if ( function_exists( 'is_shop' ) && is_shop() && is_product_category() ) { echo '<div class="shop-search">'; echo do_shortcode( '[your-shortcode'] ); echo '</div>'; } } );
Ok. It’s working on the shop page (not on the categories).
This is what I have.add_action( 'generate_before_main_content', function() { if ( function_exists( 'is_shop' ) && is_shop() && is_product_category() ) { echo '<div class="shop-search">'; echo do_shortcode( '[do_widget id=woocommerce_product_search-2]' ); echo '</div>'; } } ); AND CSS
.shop-search {
float: right;
}.shop-search .woocommerce-product-search {
display: flex;
}That’s strange. What if you replace:
is_product_category()
With:
is_product_category( 'all-deals' )
Let me know π
nope π
Let’s try this:
add_action( 'generate_before_main_content', function() { echo '<div class="shop-search">'; echo do_shortcode( '[do_widget id=woocommerce_product_search-2]' ); echo '</div>'; } );
Then this CSS:
.shop-search { display: none; } .woocommerce.archive .shop-search { display: block; }
- The topic ‘Add Product Search to WooCommerce Catelog’ is closed to new replies.