Home Forums WoodMart support forum incorrect result name when hitting on result product

incorrect result name when hitting on result product

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #92753

    Jeriss Cloud Center
    Participant

    1) Go on my website
    2) Type “graisse”
    3) Click on the first product shown
    4) You’ll see a code &#38 appearing in the middle of the product name

    #92822

    newsprince
    Participant

    It’s the code representation of the & character in html format

    https://www.degraeve.com/reference/specialcharacters.php

    ampersand & #38; & amp; &

    #92847

    Jeriss Cloud Center
    Participant

    And 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.

    #92856

    Artem Temos
    Keymaster

    Hi,

    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

    #95534

    Jeriss Cloud Center
    Participant

    I tried it and it made fatal error. See attachment

    Attachments:
    You must be logged in to view attached files.
    #95558

    Artem Temos
    Keymaster

    You need to use FTP client and put it to the functions.php file in the child theme.

    #95825

    Jeriss Cloud Center
    Participant

    I 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.
    #95868

    Artem Temos
    Keymaster

    We 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.

    #121207

    Jeriss Cloud Center
    Participant

    It works great, thanks.

    Will this code be implemented into the theme code in the next update?

    #121387

    Artem Temos
    Keymaster

    We suggest you to keep this code in the child theme.

    #121411

    Jeriss Cloud Center
    Participant

    Ok thanks, you can close this point

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

The topic ‘incorrect result name when hitting on result product’ is closed to new replies.