-
AuthorPosts
-
April 30, 2017 at 2:17 am #785149
Hi, when enabling add_theme_support( ‘avia_custom_shop_page’ ) and customizing the shop page. The widget provided by woocommerce for search breaks the search results. Or in better words it always return 0 results.
The woocommerce search widget adds this parameter in the url: post_type=product, it seems that the pre_get_posts filter in config.php(1470) also uses this var for filtering. Please advice.
Thanks!
April 30, 2017 at 2:41 am #785157Hey ithagen,
Do you mean the page that is set as the default WooCommerce Shop Overview? Because The Advanced Editor should not be used on the shop page, nor the debugging theme support box.
Best regards,
MikeApril 30, 2017 at 12:17 pm #785224Thanks, but whether you should or should not, Kriesi has added a feature for this to be overridden.. Ref from woocommerce/config.php:
/* Function that is able to overwrite the default "shop" page used by woocommerce so the template builder can be used Will only be executed if the user has switched the "shop" page to advanced layout builder. Default products are no longer displayed and the user needs to add a product grid element Can be activated by adding add_theme_support( 'avia_custom_shop_page' ); to your functions.php file */
But that is not what im asking advice for. I want to know how i can fix the issue of the code that breaks the woocommerce search results, when using the woocomerce search widget. This happens when add_theme_support( ‘avia_custom_shop_page’ ) is activated.
As i stated i my initial request it seems something happens when the search query contains post_type=product as an additional parameter. Search works fine without this url parameter.
WORKS: /?s=searchstring
DOESENT WORK: /?s=searchstring&post_type=product- This reply was modified 7 years, 7 months ago by ithagen.
April 30, 2017 at 4:50 pm #785295Hi,
I’m sorry but I can’t find the cause of this issue. I’ll ask the rest of the support team to check this thread.Best regards,
MikeMay 2, 2017 at 3:34 pm #786436Hi, any luck on this?
Below is is at least my temporary dirty fix. Hopefully you guys have an another more sustainable solution, now that you know this framework a bit better than i. :)
/* * OVERRIDE A FUNCTION IN enfold/woocommerce/config.php * This fixes an error in the search results when searched from the woocommerce search widget * Support ticket: https://kriesi.at/support/topic/avia-custom-woo-page-incompatible-with-woocommerce-search-widget/ */ add_filter( 'pre_get_posts', 'avia_woocommerce_default_page', 100 ); function avia_woocommerce_default_page($query) { if(current_theme_supports('avia_custom_shop_page')) { if(!$query->is_admin && $query->is_main_query() && !$query->is_tax && $query->is_archive && $query->is_post_type_archive) { $vars = $query->query_vars; if(isset($vars['post_type']) && 'product' == $vars['post_type'] ) { $shop_page_id = wc_get_page_id( 'shop' ); $builder_active = AviaHelper::builder_status($shop_page_id); if($builder_active == "active" && !$query->is_search) { $query->set( 'post_type', 'page' ); $query->set( 'p', $shop_page_id ); $query->set( 'meta_query', array() ); $query->is_singular = true; $query->is_page = true; $query->is_archive = false; $query->is_post_type_archive = false; $query->query = array('p'=>$shop_page_id, 'post_type' => 'page'); }elseif ($query->is_search){ $query->is_singular = false; $query->is_page = false; $query->is_archive = false; $query->is_shop = false; $query->is_post_type_archive = false; add_filter( 'template_include', function() { return locate_template( 'search.php' ); }, 100 ); } } } } return $query; }
May 3, 2017 at 7:37 pm #787339Hi,
It actually seems to work fine as a result.
Can u let us know why it is dirty? :)Best regards,
BasilisMay 4, 2017 at 10:06 pm #788080I guess i call it dirty because i havent studied all the options and posibilities of the code to maybe find the optimal solution. Do you think this is a good solution?
May 5, 2017 at 7:40 am #788235Hi,
I can’t see anything obviously wrong with your code, so if it works then I would say go for it :-)
Best regards,
RikardMay 20, 2017 at 8:06 pm #797093This is clearly a bug. Now the big question is… will you be implementing a fix for this problem?
May 22, 2017 at 8:57 am #797467Hi,
I
m sorry, but I can
t see anything wrong with your code..Best regards,
John Torvik -
AuthorPosts
- You must be logged in to reply to this topic.