• Resolved miguelitolaparra

    (@miguelitolaparra)


    I need to create an internal search engine on the web to find the products in the catalog by their ingredients, and not by categories, SKU, labels, etc…
    I was looking for the option to find how to customize without using a Plugin
    The handicap is that I need to search the products by ingredients that certain products do not contain. I mean, there are people who are allergic to some products and cannot eat various ingredients, and the serious need is to give them the opportunity to look for products that do not have the ingredients that they are allergic to.
    For example, enter the word “sugar” in the search engine, and all products that do not have sugar among their ingredients appear
    Surely someone has already had this idea.
    In the case that I show, the search is filtered by categories and tags

    <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
    
    <label>
    
    <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span>
    
    <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
    
    </label>
    
    <select id="category_name" name="category_name">
    
    <option value="">Todas</option>
    
    <?php $categories = get_categories();
    
    foreach ($categories as $key => $category) {?>
    
    <option value="<?php echo $category->slug;?>"><?php echo $category->name;?></option>
    
    <?php }?>
    
    </select>
    
    <select id="tag" name="tag">
    
    <option value="">Todas</option>
    
    <?php $tags = get_tags();
    
    foreach ($tags as $key => $tag) {?>
    
    <option value="<?php echo $tag->slug;?>"><?php echo $tag->name;?></option>
    
    <?php }?>
    
    </select>
    
    <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
    
    </form>
    
    <?php

    I know that you can limit the search content, for example with "post_type"

    <input type="hidden" name="post_type" value="post" />

    function my_custom_searchengine($query) {
      if ($query->is_search && !is_admin()) {
        $query->set('post_type', array('post'));
      }
      return $query;
    }
    add_filter( 'pre_get_posts', 'my_custom_searchengine' );

    But I don’t know which are the “posts” that I should add, I don’t know how to perform this search for the product description field, I don’t know how to make it work, and find products that do not contain the search ingredients
    Everything would be in modifying the "select" fields, in the search engine, but I don’t understand what would be the Query that should be added in the "values" of the "select", taking into account that the ingredients are only in the product description.
    Since WordPress allows you to extend the search to custom fields, this could be done with “mata_query” .
    How could I get this?
    Should I create an “array” with the ingredients of all the products?

    Any ideas ?
    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @miguelitolaparra

    Thanks for reaching out!

    These forums are meant for general support with the core functionality of WooCommerce itself. What you want to achieve is a bit complex and would require customization to do it. Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    Hope this helps!

    Thread Starter miguelitolaparra

    (@miguelitolaparra)

    Thank you for your kind words @xue28

    I’m sorry that my question has not been liked by the community, it was never my intention to abuse or ask them to do a job for me, I just came looking for inspiration.
    Feel free to close the discussion if you see fit, I apologize for asking the question, I’ll keep looking for ideas.
    I understand that this is a general questions site, and I have received help on other occasions, I only come here looking for advice, surely someone else has already thought about the functionality that I am talking about before me, and can guide me on the path to continue.

    I will look for ideas in the links that you have recommended, and if the debate is still open, I will share my achievements if they allow me.
    Thanks for your continued support.

    Hi there @miguelitolaparra

    I need to create an internal search engine on the web to find the products in the catalog by their ingredients, and not by categories, SKU, labels, etc…

    Just to add that, to my understanding, there appears to be a different approach to this, by utilizing tags and adjusting the site’s navigation accordingly.

    The result would be an easy to navigate site, where the user would be able to find their way around, whereas, building a search engine from scratch still leaves that aspect untouched.

    I hope that helps!

    Thread Starter miguelitolaparra

    (@miguelitolaparra)

    Hello , thanks for your collaboration @anastas10s .
    I don’t quite understand what you mean with your words, you have to use the translator and sometimes it doesn’t show very well.
    Maybe I don’t express the details very well.
    Now in the default wordpress or woocommerce search engine, when I enter an ingredient, it shows me all the products that are in the catalog and have that ingredient, since it detects them by the ingredients because they are in the product description.

    But my intention is when we enter an ingredient in the search engine, it shows the products that do not have that ingredient, instead of those that do have this ingredient.
    I want to facilitate the search for users who are allergic to certain products, and in this way, easily find the products that they could eat, and avoid them searching and reading all the ingredients of all the products in the store.
    As the colleague @xue28 rightly said, this is not a place for you to do my work, I only came here looking for advice and guidance.

    I’m looking for information and maybe I can get what I want to do, but I need to learn, if not impossible.
    I have read something about creating a taxonomy with the ingredients, and working with this, I don’t know, I am reading and studying things to continue learning and fully understand how to build that product search engine.
    When I manage to finish this, I will bring the solution here.
    Thank you

    Saif

    (@babylon1999)

    Hello @miguelitolaparra,

    I’m sorry that my question has not been liked by the community, it was never my intention to abuse or ask them to do a job for me, I just came looking for inspiration.

    First, I would like to note you’re more than welcome to post anything related to WooCommerce here, it’s just that we “WooCommerce staff” have a support policy we need to follow when it comes to custom solutions. ??

    That said, from your last reply I understand you want a way to limit the search for certain ingredients, etc.

    You can give these products attributes or organise them in categories and use our Product Filters for WooCommerce extension as a method to easily filter through them.

    You can also use the Products Visibility by User Roles extension to hide products from customers who have an allergy to a certain ingredient.

    If you have any questions about the extensions above, you can reach out to us via email from WooCommerce.com > MY profile > Support.

    Cheers!



Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to create an internal search engine that looks for product ingredients?’ is closed to new replies.