0

I have one Product Category that needs to have 300 x 300px uncropped thumbnail images. All of the other products have 300 x 300px, cropped thumbnails. This would be on the Shop page and the Category Pages. The category is for Books and the cropped image cuts off the top and bottom of the book cover. All of the other product categories look best with a square cropped image.

I added this code to my functions.php file, but it has no effect. Since the default WP medium image is already 300 x 300px, uncropped on the site I used "medium" as $size. I searched for more than an hour and can't find much else that is helpful. Am I on the right track with this code, or not? Any advice? Thank you!

/* SetImage Sizes on Category Pages for Books */
if ( is_product_category( '2295' )) {
// different size for one category

remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'custom_loop_product_thumbnail', 10 );
   function custom_loop_product_thumbnail() {
   global $product;
   $size = 'medium';

    $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );

return $product ? $product->get_image( $image_size ) : '';
}
} 

1 Answer 1

0

you could use the filter woocommerce_gallery_thumbnail_size, and inside that function, is when you would use the if ( is_product_category(2295) ) something like:

    add_filter( 'woocommerce_gallery_thumbnail_size', function( $size ) {
    if ( is_product_category(2295) ){
        return 'thumbnail';
        }
    return $size;
    } );

you can check the WooCommerce docs here

1
  • Thank You! That didn't work, but I changed the filter to single_product_archive_thumbnail_size and that works on the product category page, but not on the main shop page or in Related Products. I'm using the Woo Nested Category Layout plugin for the Shop page, but I looked at the code and I'm not sure, but, I think it uses the standard WooCommerce functions to call the thumbnail. So, still need to get the images on the main Shop page changed for that category. Also, for products in this category in Related Products. Jan 29, 2019 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.