Some products don't show up in the search results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Some products don't show up in the search results

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18678
    Donovanray
    Donovanray
    Participant

    Hello WPDreams,

    We use your Ajax Search Pro for WordPress plugin on our web shop. But lately the plugin is acting funny. We use the plugin to search our products alone. So no blog post or pages. Normally this works perfect, but of lately some products do not show up in the search results.

    I use the Product visibility in WooCommerce to tell the system witch products he is allowed to show in the results. We sell cartridges, both the OEM and home brand ones. So for every product we have a “general” product which shows up in the search result and the OEM and home brand one. The OEM and home brand products are connected to the “general” product. So customers search for a product, the search results shows the “general” product of the one they were looking for. When the costumer clicks on the “genereal” product the customer is send the a page where the costumer can order both OEM and home brand cartridge.

    For example search for: 85A
    The search result will show the: HP 85A Toner CE285a
    When you click on this product you will go the product page where you can see two other products:
    1. HP 85A Toner CE285A (Huismerk)
    2. HP 85A Toner CE285A (Origineel)

    The 85A OEM and home brand are not searchable. Only the “general” product show up in the search results. So far so good!
    The problem is that some products “general” products doesn’t show up in the search result. I Deleted the products and added them again in the hope this would fix the problem. I copied a product that was showing up in the search results but even than it will not show up. I changed the setting on the OEM and home brand products to allow them to be found by the search engine. But no results. Example the: OKI 46507508 Zwart should show up in the search results but it doesn’t. The strange thing is that it will show alternative keywords witch include the exact same words as was search for.

    Because I don’t want the OEM and home brand to show up in the search results I added the following code to our functions.php:

    //Zoekresultaten filteren
    add_filter( 'asp_results', 'filter_asp_results', 1, 1 );
    
    function filter_asp_results($results){
    
      /* If the results are grouped */
      if (isset($results['grouped'])) {
        foreach ($results['items'] as $i_k=>$data) {
            if ($i_k == 'name') continue;
            
            // $result['data'] holds the results here                
            foreach($results['items'][$i_k]['data'] as $r_k => &$result) {
    
              if (asp_unset_if_hidden($result))
                unset($results['items'][$i_k]['data'][$r_k]);
              
            }      
        }
        /**
         *  You need to return the $results variable here,
         *  since the changes are made directly  
         **/     
        return $results;
      
      /* Non-grouped */  
      } else {
          foreach($results as $k => &$result) {
    
            if (asp_unset_if_hidden($result))
              unset($results[$k]); 
              
          }
    
          return $results;
      }
    }
    
    function asp_unset_if_hidden( $v ) {
      // Visibility key in WooCommerce
      $key = '_visibility';
      
      if (!isset($v->post_type) || $v->post_type != 'product') return false;
      $visibility = get_post_meta( $v->id, $key, true );
      if ($visibility != 'visible') 
        return true;
      
      return false;
    }

    Hope you can help me out.

    Thank you for your time and effort.

    Kind regards,

    Erwin

    #18738
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Erwin,

    Some time ago, WooCommerce has changed the way of how the product visibility works. This method should no longer work on the most recent WooCommerce installations.

    Instead of that code, can you please try the updated solution: https://wp-dreams.com/knowledge-base/woocommerce-excluding-hidden-products/

    I feel that will very likely solve the problem.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #18742
    Donovanray
    Donovanray
    Participant

    Hello Ernest,

    Yes, that was the problem.

    Thanks for the fix.

    Kind regards,

    Erwin

    #18746
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.