Tagged: x
-
AuthorPosts
-
August 11, 2016 at 3:36 pm #1127691
Hi, I’m looking to edit the search in such a way that it only searches through woo-commerce product information. What files do i need to edit. I see in previous questions that you point users to search.php, but that was back in 2014 and I currently only see searchforms.php and that doesn’t seem to be what I’m looking for. Can you point me in the right direction please.
August 11, 2016 at 5:25 pm #1127809Hello There,
Thanks for writing in!
Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.
Then add following code in child theme function.php file.
add_filter( 'pre_get_posts', 'custom_search' ); function custom_search( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'product' ) ); } return $query; }
Let us know how it goes.
Thanks.
August 11, 2016 at 6:59 pm #1127904does this search the sku also?
August 12, 2016 at 12:01 am #1128327Hi there,
Yes it should. Let’s try and let us know.
Cheers!
August 12, 2016 at 2:09 pm #1129073It doesn’t seem to
August 12, 2016 at 9:04 pm #1129522Hello There,
Thanks for the updates! I am another staff checking on this thread. By default, sku is not searchable. To be able to display it on search you will need to have a 3rd party plugin to handle that. Please check out these following links:
https://wordpress.org/plugins/search-by-sku-for-woocommerce/
https://wordpress.org/support/topic/plugin-woocommerce-excelling-ecommerce-no-option-to-search-by-skuHope this helps.
August 15, 2016 at 2:30 pm #1132386Hi, I’m adding on to this thread as I’ve been spending a lot of time trying to solve this and an additional problem. I’m using Integrity/dark with woocommerce and grouped products. The search function is picking up my hidden sub-products and I don’t want that:
1. When using my menu bar search function, how do I eliminate the sub-products from the search. These sub-products are just size variants of the main product. (I wanted to show them on the product page as two lines instead of a drop down so I chose this route instead of the variable product.) the Woocommerce search widget does not pick up these sub-products.
2. How do I eliminate all the description, etc and make the resulting search look like the shop page, eg., product picture, title and my custom field ‘product_subtitle’.
3. Lastly, how do I add the woocommerce shortcode [woocommerce_product_search] to a page? I’m attemtping to dedicate a page to searching for products. I have widgets in the sidebar, but I would like move the woocommerce product search into the main page section to search for a product.
http://www.purecalculus.com
Happy to provide the login info again if necessary…we’ve been here before :)! If it’s appropriate to open up a new thread, I can do that.August 15, 2016 at 8:00 pm #1132787Hey Richard, do your products show that way by default? If not, how did you get them to display this way?
August 15, 2016 at 10:20 pm #1132912Hi Bezambar, it’s been a long work in progress…still is! Far from the default. Are you speaking of the shop page?
August 16, 2016 at 2:18 am #1133097Hi Richard,
1. Search functionality only works standard entries, sub products are woocommerce specific which means it doesn’t have a direct relation to WordPress’s default search functionality. What you need is advanced search functionality trhat filters top level products. I don’t know any particular plugin that could do that, but should be doable with custom development. You may wish to consult to a developer for proper time estimate and possibility.
2. That would again require custom development. WordPress’s search functionality is for WordPress’s standard post, page, and custom post type only. The search page is an archive page for search result and not designed for product pages. Hence, you’ll need help from a Woocommerce developer.
3. That something I can help with 🙂
a. Copy this file wp-content\themes\x\framework\views\global\_index.php to your child theme (eg. wp-content\themes\x-child\framework\views\global\_index.php )
b. Edit your child theme’s framework\views\global\_index.php and add this line of code,
<?php if ( is_search() ) { echo do_shortcode(' [woocommerce_product_search]'); } ?>
above this existing line,
<?php if ( $condition ) : ?>
c. Save and upload.
Again, search template isn’t made for woocommerce, hence, it still requires further customization. This will only add the search functionality on search page.
Thanks!
August 16, 2016 at 6:29 am #1133353Hi Rad, Thanks, but
for #1, I guess I have to remove all the content in the sub-product pages. Was hoping not to have to do that, but it’s a solution.
for #3, I’m not sure what we did with the code added from above. I have the shortcode – [x_search] on a simple page called “Notes Search. I’m actually searching product tags, but the text in the product descriptions is also searched. If this search were to only search product tags, that would be fine too.
The search results after the php code addition are the same except in the third column, above the results there is now the text “[woocommerce_product_search]”. What was it the code above was to do? Was it to replace all instances of the [x_search] function/shortcode with the [woocommerce_product_search] search function/shortcode? I assumed it would pick up an x search in progress and send it to the woocommerce shortcode function to finish the search and echo results. I guess I didn’t see any functionality added to the search page.
Sorry for the stream of consciousness typing. I think I see that the code sent the search value to the woocommerce widget search box in my sidebar. I guess, in short I’m looking for a way to take that woocommerce product search widget and put it on the main page instead of in a side bar.
If this is too deep into customization, a general idea of what needs to be done would be very helpful. Thanks.
August 16, 2016 at 11:38 am #1133800Hi Richard,
It will not replace the default search functionality of WordPress. It will only embed another search functionality within it. How about this https://docs.woocommerce.com/document/woocommerce-product-search/api/ ?
Instead of this ( this is just a sample [woocommerce_product_search] )
<?php if ( is_search() ) { echo do_shortcode('[woocommerce_product_search]'); } ?>
We can change it to this,
<?php if ( is_search() && function_exists( 'woocommerce_product_search' ) ) { echo woocommerce_product_search( array( 'limit' => 20 ) ); } ?>
Woocommerce has its own search feature because WordPress’s default search feature is not 100% applicable for product searches.
Hope this helps.
August 16, 2016 at 6:51 pm #1134333Hi Rad, I’m not sure I’m communicating this properly. The Woocommerce documentation says all I need to do is open a new page in WordPress, type in the shortcode: [woocommerce_product_search] and voila, I have a fully functioning Woocommerce product search page. If it were only that easy. the [x-search] shortcode works ok on the wordpress page, but I can’t seem to call the [woocommerce_product_search] shortcode/function into play.
The above code doesn’t seem to make any difference either.
August 16, 2016 at 9:22 pm #1134591Hi, i use just started using https://wordpress.org/plugins/search-everything/ to add some advance properties to the default search. Its working well for me so far.
Richard, I was talking about your search results page.
Xthemes/Richard. I was thinking of having the search results, if a product show the title and sku, and if a post the title and meta description. Is there anyway to do this
August 17, 2016 at 2:50 am #1134838@Richard, I see, I just thought you’re trying to replace the WordPress’s default search functionality with woocommerce search. In that case, just add that shortcode to any page you prefer. The [woocommerce_product_search] is from extension, it’s not working since you didn’t have this installed.
https://woocommerce.com/products/woocommerce-product-search/
Products search is not a simple feature, hence custom development or 3rd party plugin such as this is required.
@bezambar Yes, you’ll have to customized search templates and display Woocommerce data. Woocommerce has its own set of API and function compared to standard post. X theme’s search result uses the same templates as used for posts (post format templates), hence if you don’t wish your standard post to be affected, you should create your own product templates.
Use is_single() && get_post_type() == ‘product’ condition to check and switch template, for example on this file \wp-content\themes\x-child\framework\views\global\_index.php
We can change this line
<?php x_get_view( $stack, 'content', get_post_format() ); ?>
to this,
<?php if ( is_single() && get_post_type() == 'product' ) { x_get_view( $stack, 'content', 'product' ); } else { x_get_view( $stack, 'content', get_post_format() ); } ?>
Then create your product template as \wp-content\themes\x-child\framework\views\{YOUR CURRENT STACK}\content-product.php, and within that will be your product search result single template, and you can display sku, product, title, description. Please use Woocommerce’s API on displaying these data.
Thanks!
-
AuthorPosts