Home › Forums › WoodMart support forum › Thumbnail in Ajax search result
Thumbnail in Ajax search result
- This topic has 9 replies, 3 voices, and was last updated 6 years, 6 months ago by
Elise Noromit.
-
AuthorPosts
-
January 7, 2019 at 3:53 am #100256
InterfictoParticipantHello, I have enabled the Ajax search. I can see that thumbnail result is big, it load the 600×600 image. Can I set to load the smallest image? for example 100×100
If it no is possible from Theme option, can you give me instructions to change the files please?
January 7, 2019 at 8:31 am #100279
Elise NoromitMemberHello,
Image sizes used in the search are stipulated by Woocommerce thumbnails size which is configured in Appearance > Customize > Woocommerce > Product Image https://prnt.sc/m3yt4l
Best Regards
January 7, 2019 at 7:25 pm #100486
InterfictoParticipantThank you for your answer. I know, how ever i want use other image size, when i upload an image it is cropped automatically a 100×100. I have setted it int WordPress > Settings > Media.
I want use it size. Is possible that I should modify PHP files, I can do it if you give me instruccions or some idea about how can do it
January 7, 2019 at 8:30 pm #100497
Elise NoromitMemberHello,
WordPress > Settings > Media is effective for thumbnails for blogs.
Appearance > Customize > Woocommerce > Product Image https://prnt.sc/m3yt4l also have cropping option and these thumbnails are for Product images.
Best Regards
January 10, 2019 at 3:54 pm #101177
InterfictoParticipantI’m sorry but I think he did not make me understand. I know how to change the size of the thumbnails for both Woocommerce and WordPress. My problem is that. In my current theme in the lists and on the archive page I must use a very large thumbnail size: 500px x 500 px.
For example, my store is two columns, so I must use the large model.
However in the search usingajax the thumbnails should be much smaller, to reduce the time it takes the search and load results. So I want to use a different thumbnail size than the one I use in the lists and in the archive pages.
January 10, 2019 at 5:40 pm #101198
Elise NoromitMemberHello,
Our theme does not have any special thumbnails options excepting those mentioned above. The lists and archive pages will take thumbnail size configured in the Media settings and Woocommerce settings.
Best Regards
January 10, 2019 at 7:32 pm #101222
InterfictoParticipantHello, sorry. My English is very bad. I know that makes communication difficult. I know that your theme does not have a special thumb. However I want to know that if somehow I can configure that search engine by ajax. A certain image size is displayed. If you can not through the options of the subject. maybe you can support me by telling me in which file .php or .js the size of the image of the search results is brought by ajax for me to modify it.
January 11, 2019 at 7:29 am #101280
Eric WatsonParticipantHello,
Try to add the following PHP code snippet to the child theme functions.php file to do 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_search_args', $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' => get_the_title(), 'permalink' => get_the_permalink(), 'price' => $product->get_price_html(), 'thumbnail' => $product->get_image( array( 100, 100 ) ), ); } else { $suggestions[] = array( 'value' => 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 );
Kind Regards
XTemos StudioJanuary 12, 2019 at 3:34 pm #101578
InterfictoParticipantGreat, it work perfectly. Thank you very much
January 12, 2019 at 5:06 pm #101587
Elise NoromitMemberYou are welcome! If you have any questions please feel free to contact us.
Best Regards
-
AuthorPosts
The topic ‘Thumbnail in Ajax search result’ is closed to new replies.
- You must be logged in to create new topics. Login / Register