Archived topic
Hard Crop Woocommerce Single Product Image?
3 replies · Started by Aaron on July 29, 2022
Hello,
I see settings to set the image size, but it says the images will remain uncropped. Is there a way to hard crop them to be square?
Unfortunately it won't work to ask the store manager to manually crop images before uploading.
Thanks
Hi there,
Woocommerce provides some Hooks to filter the sizes of the images it displays - see here:
https://woocommerce.com/document/image-sizes-theme-developers/#section-3
A working example would be something like this:
add_filter( 'woocommerce_get_image_size_single', function( $size ) {
return array(
'width' => 600,
'height' => 600,
'crop' => 1,
);
} );
You may need to run the Regenerate Thumbnails plugin afterwards to regenerate the new size, and clear any caches.
But.... if i may say, its not a good method especially if you have many images of various aspect ratios, theres no logic or smart algorithms that define where or how to crop an image, so the end results may not be great. The best method is to crop the images before uploading.....
Hi,
Great thanks! I'd love to have them upload cropped images, but this will be a good fall back.
You're welcome