Woocommerce – remove the default image placeholder? [closed]

How can I show images for just some of the items but not for others?

I’m working on a restaurant menu with online ordering, displaying the food menu (woocommerce products) with shortcodes – eg. [product_category category=”starters” orderby=”date” order=”asc”] etc.

A lot of the items do not require an image, but I’ve found that if a product does not have an image assosciated with it then woocommerce automatically adds an ugly placeholder to the listings.

I can turn off all the thumbnails, but I still need thumbnail support for any products that do require an image.

If I delete the default placeholder image it gets replaced with text “placeholder”!

If I replace their placeholder with a small transparent .png then that gets upscaled to whatever size the thumbs are, creating an undesirable “missing image” gap.

No idea what else to try?
Thanks

3 Answers
3

woocommerce_template_loop_product_thumbnail is pluggable so you can override it with your own code. Any time you see a function anywhere in a WordPress setting that looks like this:

if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {

/**
 * Get the product thumbnail for the loop.
 *
 * @access public
 * @subpackage  Loop
 * @return void
 */
function woocommerce_template_loop_product_thumbnail() {
    echo woocommerce_get_product_thumbnail();
}
}

the if ( ! function_exists('something' ) ) check indicates a pluggable function that you can override by creating a function of the same name in you theme or child theme.

Woo’s function essentially shows the thumbnail if it exists and the placeholder if it does not, so you’d just need to eliminate that part in your own version, like so:

function woocommerce_template_loop_product_thumbnail() {
    global $post;
    if ( has_post_thumbnail() )
          echo get_the_post_thumbnail( $post->ID, 'shop_catalog' );
}

Leave a Comment