Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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,
    Nick

    #941436

    Hey 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,
    Ismael

    #941570

    Hi 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,
    Nick

    #942439

    Hi,

    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,
    Ismael

    #943600

    Hi 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/j6uvrk

    I am looking forward to your answer.

    Thank you in advance.

    Best regards,
    Nick

    #943899

    Hi Nick,

    I think that is caused by the image you are using, could you try an image with the same dimensions as the rest of the product images to see if that helps please?

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.