WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Placeholder image for a specific category (7 posts)

  1. Cicero83
    Member
    Posted 7 months ago #

    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.

    http://wordpress.org/plugins/woocommerce/

  2. Roy
    Member
    Posted 7 months ago #

    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?

  3. Cicero83
    Member
    Posted 7 months ago #

    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

  4. Roy
    Member
    Posted 7 months ago #

    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?

  5. Cicero83
    Member
    Posted 6 months ago #

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

  6. Roy
    Member
    Posted 6 months ago #

    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.

  7. Cicero83
    Member
    Posted 6 months ago #

    Hello,

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

    Reg.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.