Home › Forums › WoodMart support forum › incorrect result name when hitting on result product
incorrect result name when hitting on result product
- This topic has 10 replies, 3 voices, and was last updated 5 years, 10 months ago by
Jeriss Cloud Center.
-
AuthorPosts
-
November 30, 2018 at 12:49 pm #92753
Jeriss Cloud CenterParticipant1) Go on my website
2) Type “graisse”
3) Click on the first product shown
4) You’ll see a code & appearing in the middle of the product nameNovember 30, 2018 at 2:24 pm #92822
newsprinceParticipantIt’s the code representation of the & character in html format
https://www.degraeve.com/reference/specialcharacters.php
ampersand & #38; & amp; &
November 30, 2018 at 2:52 pm #92847
Jeriss Cloud CenterParticipantAnd so..? My visitors don’t ask to see html code, they ask to see a product name well shown. It means your search bar is not supporting & value, please fix it.
November 30, 2018 at 2:59 pm #92856
Artem TemosKeymasterHi,
Try to add the following PHP code snippet to the child theme functions.php file to fix this
function woodmart_ajax_suggestions() { $allowed_types = array( 'post', 'product', 'portfolio' ); $post_type = 'product'; if ( apply_filters( 'woodmart_search_by_sku', woodmart_get_opt( 'search_by_sku' ) ) && woodmart_woocommerce_installed() ) { add_filter( 'posts_search', 'woodmart_product_ajax_search_sku', 10 ); } $query_args = array( 'posts_per_page' => 5, 'post_status' => 'publish', 'post_type' => $post_type, 'no_found_rows' => 1, ); if ( ! empty( $_REQUEST['post_type'] ) && in_array( $_REQUEST['post_type'], $allowed_types ) ) { $post_type = strip_tags( $_REQUEST['post_type'] ); $query_args['post_type'] = $post_type; } if ( $post_type == 'product' && woodmart_woocommerce_installed() ) { $product_visibility_term_ids = wc_get_product_visibility_term_ids(); $query_args['tax_query'][] = array( 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $product_visibility_term_ids['exclude-from-search'], 'operator' => 'NOT IN', ); if ( ! empty( $_REQUEST['product_cat'] ) ) { $query_args['product_cat'] = strip_tags( $_REQUEST['product_cat'] ); } } if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $query_args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN' ); } if ( ! empty( $_REQUEST['query'] ) ) { $query_args['s'] = sanitize_text_field( $_REQUEST['query'] ); } if ( ! empty( $_REQUEST['number'] ) ) { $query_args['posts_per_page'] = (int) $_REQUEST['number']; } $results = new WP_Query( apply_filters( 'woodmart_ajax_get_results', $query_args ) ); $suggestions = array(); if ( $results->have_posts() ) { if ( $post_type == 'product' && woodmart_woocommerce_installed() ) { $factory = new WC_Product_Factory(); } while ( $results->have_posts() ) { $results->the_post(); if ( $post_type == 'product' && woodmart_woocommerce_installed() ) { $product = $factory->get_product( get_the_ID() ); $suggestions[] = array( 'value' => html_entity_decode( get_the_title() ), 'permalink' => get_the_permalink(), 'price' => $product->get_price_html(), 'thumbnail' => $product->get_image(), ); } else { $suggestions[] = array( 'value' => html_entity_decode( get_the_title() ), 'permalink' => get_the_permalink(), 'thumbnail' => get_the_post_thumbnail( null, 'medium', '' ), ); } } wp_reset_postdata(); } else { $suggestions[] = array( 'value' => ( $post_type == 'product' ) ? esc_html__( 'No products found', 'woodmart' ) : esc_html__( 'No posts found', 'woodmart' ), 'no_found' => true, 'permalink' => '' ); } echo json_encode( array( 'suggestions' => $suggestions ) ); die(); } add_action( 'wp_ajax_woodmart_ajax_search', 'woodmart_ajax_suggestions', 10 ); add_action( 'wp_ajax_nopriv_woodmart_ajax_search', 'woodmart_ajax_suggestions', 10 );
Regards
December 11, 2018 at 9:58 pm #95534
Jeriss Cloud CenterParticipantI tried it and it made fatal error. See attachment
Attachments:
You must be logged in to view attached files.December 12, 2018 at 7:16 am #95558
Artem TemosKeymasterYou need to use FTP client and put it to the functions.php file in the child theme.
December 13, 2018 at 10:59 am #95825
Jeriss Cloud CenterParticipantI did via this plugin. If the code is correct, it should work.
You didn’t even check the error… it’s written there is error on line 94..Attachments:
You must be logged in to view attached files.December 13, 2018 at 1:26 pm #95868
Artem TemosKeymasterWe don’t know how the plugin works so please, do this in a safe way editing the child theme via FTP. The code works correctly on our side.
April 27, 2019 at 4:09 pm #121207
Jeriss Cloud CenterParticipantIt works great, thanks.
Will this code be implemented into the theme code in the next update?
April 29, 2019 at 9:43 am #121387
Artem TemosKeymasterWe suggest you to keep this code in the child theme.
April 29, 2019 at 11:13 am #121411
Jeriss Cloud CenterParticipantOk thanks, you can close this point
-
AuthorPosts
The topic ‘incorrect result name when hitting on result product’ is closed to new replies.
- You must be logged in to create new topics. Login / Register