Home Forums WoodMart support forum Ampersand character

Ampersand character

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #169283

    flasharooo
    Participant

    Hi we have a few products within the store however when we users search for products with ampersand character “&” it will return as following”

    Let say products is called M&M: When typed in the search it will auto complete to M&ampM
    Should the user proceed to type the full product name as sush M&M Tshirt it will return as NO PRODUCT Found.

    Can you kindly help?

    #169284

    flasharooo
    Participant

    I found a temp solution to the issue by adding the code you suggest on similar post, sorry my bad i didn’t look it up before as i was tired of trying to get to the bottom of it;

    However the issue only fixes the part when the product name appears as such ” M&ampM ”
    it however does not fix the issue when you type the following letter and the search results returns with “NO PRODUCTS FOUND”

    Thank you.

    #169340

    Hello,

    First of all thanks for choosing our Theme, we are glad to be you in WoodMart WordPress family :-).

    Please share some relevant screenshots by pointing out the specific search and the URL of the
    website. Also provide the code you added in your site , So I can check it out and help you accordingly.

    Best Regards.

    #169343

    flasharooo
    Participant

    <blockquote

    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 );

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

    flasharooo
    Participant

    When you enter the full query in this case N&M it returns with the below screenshot.

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

    Hello,

    I saw that code which you shared. What if you do not add that code? Have it display the result for N&D if that code excluded. Exclude that code and check the results for “N&D” once.

    Best Regards.

    #169451

    flasharooo
    Participant

    As i said if i do not add that code when i type N& without the D it shows up as Namp& but as soon as i type the following letter in this case D it get “NO PRODUCT FOUND”

    I guess you didn’t even read my first message, any way i will attach a screenshot for you so you can see what happens when i remove that code.

    Any ways screen shots attached.

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

    Hello,

    I have already read your first message, I thought when you did not include that code then it might works but as you said it add the “amp” before the “&”, kindly deactivate all of your third party plugins and then check back after clearing your site and browser cache.

    In case if it is still not fixed then remain the plugins as disable and provide me admin login details.

    Best Regards.

    #169691

    flasharooo
    Participant

    I never said it add it before see the original message read it again if you have to !

    Let say products is called M&M: When typed in the search it will auto complete to M&ampM
    Should the user proceed to type the full product name as sush M&M Tshirt it will return as NO PRODUCT Found.

    #169736

    Hello,

    Could you please deactivate all the third party plugins and clear the cache then check back.
    In case if it is still not fixed then remain the plugins as disable and provide me admin login details so I can check and help you out accordingly.

    Best Regards.

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