Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › For Variable Products display parent image if there is no specific image
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 4 years, 6 months ago.
- AuthorPosts
- May 15, 2019 at 9:23 am #22656
We have variable products in the Woocommerce shop. Some variations don’t have images. We need to display the parent product image for those variations.
Please let me know if this is possible.
May 15, 2019 at 10:00 am #22662Hi!
It might be possible via using a small custom code snippet. Try add this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter( 'asp_results', 'asp_get_main_prod_img', 10, 1 ); function asp_get_main_prod_img($results) { foreach ( $results as $k => &$r ) { if ( isset($r->post_type) && $r->post_type == 'product_variation' ) { $wc_prod_var_o = wc_get_product( $r->id ); $img = wp_get_attachment_image_src( get_post_thumbnail_id($wc_prod_var_o->get_parent_id()), 'single-post-thumbnail' ); if (isset($img, $img[0]) && !is_wp_error($img)) $r->image = $img[0]; } } return $results; }
This should hopefully resolve the issue.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 15, 2019 at 10:19 am #22663Thank you Ernest. The issue is resolved.
Best regards,
-SonyMay 15, 2019 at 12:11 pm #22664You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.