Support » Plugin: WooCommerce » Placeholder image for a specific category

  • Hi,

    My client wants a different placeholder image for one specific category. Is this possible? I search the internet, but I can’t find it anywhere.

    Now I have this code to set the default placeholder image:

    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 . '/2013/07/default-tire.jpg';
    		return $src;

    I hope someone has an answer.

    Kind reg.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Roy Ho


    A little confused. Why would you want to do that? If there is a specific image you want to use, why not just upload that for the category instead of waiting for it to fallback to a placeholder?

    Sorry, I was not clear enough. It’s about the product images. All products have a placeholder image. What I want is to change the placeholder image of the products in one specific category.

    Hope you can help

    Roy Ho


    Perhaps I am not understanding the reason for doing this…If you want a specific image for a set of products within a certain category, why not just upload the image you want instead of using placeholder fallback?

    Because it has about more than hundred products. And also because it is more user friendly for my client this way

    Roy Ho


    You would need to modify product-image.php file template. Copy it to your themes woocommerce/single-product/ folder.

    On line 37 is where you want to start editing. Replace the entire line on 37 with something like this (un-tested).

    // do this if product is in specific category
    if ( has_term( 'my_cat', 'product_cat', $post->ID ) ) {
         echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', get_template_directory_uri() . '/images/my_product_placeholder.jpg' ), $post->ID );
    } else {
         echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );

    You can change “my_cat” to the slug name of the category you want OR even the cat ID. Also change the image path to your liking above.


    This worked for the single product page, many thanks!
    What template can I edit to change this for the category page?


Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Placeholder image for a specific category’ is closed to new replies.