Tagged: placeholder image
-
AuthorPosts
-
April 12, 2018 at 12:48 am #940715
Hi Sirs,
With the following snippet, I changed the placeholder image to products with no featured image.
My issue is that the placeholder image appears normally in single product page, but not in the Shop page (product archives), or in product loop.I would really appreciate, if you could help me.
My snippet below:
/* Set placeholder image in product page to products with no featured image */
add_action( ‘init’, ‘custom_fix_thumbnail’ );function custom_fix_thumbnail() {
add_filter(‘woocommerce_placeholder_img_src’, ‘custom_woocommerce_placeholder_img_src’);function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir[‘baseurl’] );
$src = $uploads . ‘/2017/05/Z_logo.png’;return $src;
}
}I am looking forward to your precious support.
Best regards,
NickApril 13, 2018 at 12:06 pm #941436Hey nickgin,
Thank you for using Enfold.
Could you provide a screenshot of the issue? Providing links to the actual pages will help. Try to use the is_singular(‘product’) function.
Best regards,
IsmaelApril 13, 2018 at 4:01 pm #941570Hi Ismael,
Thank you for your support.
You will see that product in the second row. The first product in the second row.
https://zoomit.gr/wordpress_2/product-category/%CE%BA%CE%B1%CE%BB%CE%BF%CE%BA%CE%B1%CE%B9%CF%81%CE%AF%CE%BD%CE%B1/foyskota-den-epistrefontai/The product page that placeholder works:
Unfortunately, I don’t know how to use that function. Could you help me?
I would really appreciate your help.Best regards,
NickApril 16, 2018 at 7:04 am #942439Hi,
Thank you for the update.
The placeholder markup is missing from the theme’s thumbnail hook. Please use this code in the functions.php file.
add_action('init', 'after_theme_setup_placeholder_mod'); function after_theme_setup_placeholder_mod() { remove_action( 'woocommerce_before_shop_loop_item_title', 'avia_woocommerce_thumbnail', 10); remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10); add_action( 'woocommerce_before_shop_loop_item_title', 'avia_woocommerce_thumbnail_mod', 10); } function avia_woocommerce_thumbnail_mod($asdf) { global $product, $avia_config; if(function_exists('wc_get_rating_html')) { $rating = wc_get_rating_html( $product->get_average_rating() ); } else { $rating = $product->get_rating_html(); //get rating } $id = get_the_ID(); $size = 'shop_catalog'; $thumbnail = get_the_post_thumbnail( $id , $size ); echo "<div class='thumbnail_container'>"; echo avia_woocommerce_gallery_first_thumbnail( $id , $size); if($thumbnail) { echo $thumbnail; } else { $placeholder = wc_placeholder_img_src(); echo '<img src="' . esc_url( $placeholder ) . '" />'; } if(!empty($rating)) echo "<span class='rating_container'>".$rating."</span>"; if($product->get_type() == 'simple') echo "<span class='cart-loading'></span>"; echo "</div>"; }
Best regards,
IsmaelApril 18, 2018 at 1:50 pm #943600Hi Ismael,
Thank you so much for the snippet, you provided to me.
It really worked!!!Just a little detail: the thumbnail image container is shorter than the rest of the thumbnails.
Screenshot: https://prnt.sc/j6uvrkI am looking forward to your answer.
Thank you in advance.
Best regards,
NickApril 19, 2018 at 5:59 am #943899 -
AuthorPosts
- You must be logged in to reply to this topic.