HomePage › Forums › Themeforest › Petpuzzy – Pet Shop WooCommerce Theme › Fix AJAX search results showing results in multiple languages w/ WPML installed
- This topic has 12 replies, 2 voices, and was last updated 11 months, 3 weeks ago by Supporter.
-
AuthorPosts
-
October 18, 2023 at 3:29 am #10947anto80Support Expired
Hello,
My website is running WPML with 2 languages. The issue I have is related to the AJAX search results that appear once you type a few letters in the search field, which are showing results for both languages.
For example, if you type “fridge” into the search field, it will begin showing results once “fri” is typed, and those results will show products in 2 languages because the letters “fri” appear in the product titles of both languages.
Can you modify the JavaScript code responsible for making the AJAX requests so that it includes the current language information and passes it to the server when requesting search results?
Hope this is an easy fix, thanks in advance for your support!
AnthonyOctober 18, 2023 at 11:13 pm #10955Please add this custom code to the file functions.php:
function petpuzzy_ajax_search_products() { global $woocommerce; $search_keyword = $_REQUEST['query']; $ordering_args = $woocommerce->query->get_catalog_ordering_args('date', 'desc'); $suggestions = array(); $args = array( 's' => apply_filters('petpuzzy_ajax_search_products_search_query', $search_keyword), 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $ordering_args['orderby'], 'order' => $ordering_args['order'], 'posts_per_page' => apply_filters('petpuzzy_ajax_search_products_posts_per_page', 8), 'supress_filters' => true ); $args['tax_query']['relation'] = 'AND'; if (!empty($_REQUEST['product_cat'])) { $args['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => strip_tags($_REQUEST['product_cat']), 'operator' => 'IN' ); } $products = get_posts($args); if (!empty($products)) { foreach ($products as $post) { $product = wc_get_product($post); $product_image = wp_get_attachment_image_src(get_post_thumbnail_id($product->get_id())); $suggestions[] = apply_filters('petpuzzy_suggestion', array( 'id' => $product->get_id(), 'value' => strip_tags($product->get_title()), 'url' => $product->get_permalink(), 'img' => esc_url($product_image[0]), 'price' => sprintf('<span class="price">%s</span>', $product->get_price_html()), ), $product); } } else { $suggestions[] = array( 'id' => -1, 'value' => esc_html__('No results', 'petpuzzy'), 'url' => '', ); } wp_reset_postdata(); echo json_encode($suggestions); die(); }
October 18, 2023 at 11:40 pm #10957anto80Support ExpiredThank you for the quick reply, but unfortunately that code did not work.
The code is in my functions.php file, but when I type “fri” in the search field on the English website, the suggestions also include French results.
Is there another snippet of code I can try?
October 19, 2023 at 12:05 am #10959Please send the WordPress admin web account for me, I will check and try to help you.
October 19, 2023 at 1:06 am #10964anto80Support ExpiredThis reply has been marked as private.October 21, 2023 at 8:44 am #10978I can’t login to the admin dashboard, please recheck your account: https://prnt.sc/ArXB4cOGB7jx
October 21, 2023 at 10:13 am #10984anto80Support ExpiredThis reply has been marked as private.October 22, 2023 at 10:49 pm #10990I fixed this issue, please recheck your site.
October 23, 2023 at 4:11 am #10992anto80Support ExpiredGreat news!
Can you explain what you did so that I understand the fix?October 23, 2023 at 9:33 am #10993anto80Support ExpiredThis reply has been marked as private.October 23, 2023 at 11:14 pm #109991. The previous code had an error so I fixed it: https://prnt.sc/-1Rzz3RcGNrD
2. It is possible but you will have to pay a fee for this request
October 23, 2023 at 11:26 pm #11000anto80Support ExpiredThis reply has been marked as private.October 25, 2023 at 12:56 am #11007Ok, let me know if you need to help.
-
AuthorPosts
You must be logged in to reply to this topic.