Enable Product Search by GTIN in WooCommerce

This topic has 6 replies, 3 voices, and was last updated 9 months, 4 weeks ago ago by Luca Rossi

  • Avatar: Alpha111
    Alpha111
    Participant
    August 1, 2024 at 12:43

    Hello,

    Could you please help me configure the search functionality to include the GTIN meta field so that products can be searched by their GTIN?

    Thank you!

    Please, contact administrator
    for this information.
    5 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    August 1, 2024 at 13:09

    Hello Alpha111,

    Thank you for reaching out to us with your request.

    Unfortunately, we are unable to fulfill your request at this time. However, we encourage you to submit your feature request on our task board at https://www.8theme.com/taskboard/. This will allow our development team to review it directly.

    Best Regards,
    8Theme’s Team

    Avatar: Alpha111
    Alpha111
    Participant
    August 1, 2024 at 13:28

    can you help me takle it with custom code ?

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    August 1, 2024 at 13:33

    Hello Alpha111,

    Additional customization is outside the scope of our basic support.

    Should you require personalized customization services, we invite you to submit a request through our customization panel at the following link: https://www.8theme.com/account/#etheme_customization_panel. This will allow you to engage directly with our technical team.
    Please note that customization services are subject to additional charges. The exact amount will be determined after a detailed review of your request.

    Best Regards,
    8Theme’s Team

    Avatar: Alpha111
    Alpha111
    Participant
    August 1, 2024 at 13:35

    i tried this

    
    function custom_product_search($search_results, $term, $query_args) {
        if (!empty($term)) {
            global $wpdb;
            
            $gtin_results = $wpdb->get_col($wpdb->prepare("
                SELECT DISTINCT p.ID FROM {$wpdb->posts} p
                JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
                WHERE p.post_type = 'product'
                AND p.post_status = 'publish'
                AND pm.meta_key = '_et_gtin'
                AND pm.meta_value LIKE %s
            ", '%' . $wpdb->esc_like($term) . '%'));
    
            if (!empty($gtin_results)) {
                $search_results = array_unique(array_merge($search_results, $gtin_results));
            }
        }
        return $search_results;
    }
    add_filter('woocommerce_product_search_results', 'custom_product_search', 10, 3);
    
    Avatar: Justin
    Luca Rossi
    Support staff
    August 2, 2024 at 04:59

    Hi @Alpha111,

    Please try with this code instead: https://wordpress.stackexchange.com/a/309900/22807.

    Any issues related to this custom codes must be directed to the author.

    Hope it helps!

  • Viewing 6 results - 1 through 6 (of 6 total)

The issue related to '‘Enable Product Search by GTIN in WooCommerce’' has been successfully resolved, and the topic is now closed for further responses

Helpful Topics

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.