Bug: When selecting facet with one product

  • mcl7
    Participant
    3 years ago #25776

    I initially thought that this was unique to one of the custom taxonomies that I created but after testing I can confirm that there is an issue with at least all custom taxonomies when selecting a facet with only one product.

    Behavior, after doing a search (this issue is not seen at all when filtering category pages) when selecting a facet with only one product it displays more than one product. The additional products displayed are attributed to that same facet you are selecting (yet far less relevant) to your actual search.

    When going into Algolia to see if the same results are shown in the admin I see that the results are not the same and the results behave as expected.

    This last part is what is puzzling because I figured it was some sort of relevancy filter in Algolia but it doesn’t feel that way not that I have compared the results in the Algolia admin with what’s on the site.

    Any ideas on what could be happening here? Anything I can look at on the WPSolr settings or in Algolia settings that you are aware of?

    wpsolr
    Keymaster
    3 years ago #25777

    Your issue comes from the WooCommerce single search result redirecting to the product details page.

    You can deactivate it with this filter:
    add_filter( ‘woocommerce_redirect_single_search_result’, function () {
    return false;
    }, 10 );

    mcl7
    Participant
    3 years ago #25779

    I don’t think this is the issue. I thought I had to enable this redirect you are mentioning. Is this is a feature in WooCommerce core?
    Here is the code I used to do that previously to redirect result pages with one result to the product. page (however, it was causing issues so I’m not using it):

    /* Redirect if there is only one product in the category or tag, or anywhere... */
    function redirect_to_single_post(){
    global $wp_query;
    if( (is_product_category() || is_product_tag()) && $wp_query->post_count == 1 )//Woo single only
    //if( is_archive() && $wp_query->post_count == 1 )//redirect all single posts 
    {
        the_post();
        $post_url = get_permalink();
        wp_safe_redirect($post_url , 302 );
    exit;
    }
    } 
    add_action('template_redirect', 'redirect_to_single_post');

    However, that code snippet wasn’t even activated. I deleted it just in case and I still see the problem (even when using the code snippet you most recently shared).

    Also, I just noticed that, in these cases where there is only one result in a facet, if I uncheck the filter and select it again it actually shows me different results each time.

    Note that this only happens on search results (not category pages). Seems also to be a pattern that it always shows four products instead of the actual amount of products (in this case 1).

    Note also that after you have selected a facet with only one product, if you select another facet it will either not work or it will go to the no results found message.

    wpsolr
    Keymaster
    3 years ago #25780

    I integrated add_filter( ‘woocommerce_redirect_single_search_result’, ‘__return_false’ ) to WPSOLR, to prevent single result breaking Ajax filters.

    You can download the fix: https://trello.com/c/yc0DE9Eh/149-fix-woocommerce-single-result-ajax

    mcl7
    Participant
    2 years, 12 months ago #25781

    This works perfectly! No problems at all.

    Thank you!

    wpsolr
    Keymaster
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.