Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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!

    #785157

    Hey 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.
    postimage

    Best regards,
    Mike

    #785224

    Thanks, 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.
    #785295

    Hi,
    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,
    Mike

    #786436

    Hi, 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;
    	
    } 
    #787339

    Hi,

    It actually seems to work fine as a result.
    Can u let us know why it is dirty? :)

    Best regards,
    Basilis

    #788080

    I 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?

    #788235

    Hi,

    I can’t see anything obviously wrong with your code, so if it works then I would say go for it :-)

    Best regards,
    Rikard

    #797093

    This is clearly a bug. Now the big question is… will you be implementing a fix for this problem?

    #797467

    Hi,

    Im sorry, but I cant see anything wrong with your code..

    Best regards,
    John Torvik

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.