Archived topic
Image Size - Use WooCommerce generated size?
3 replies · Started by Antoine on June 24, 2021
Hi,
When adding an image in the Wordpress editor (classic or Gutenberg), the standard image sizes are: Thumbnail, Medium, Large, Full.
Now, WooCommerce also create different image sizes per Customize > WooCommerce > Product Images.
The question is: is it possible to add these WooCommerce image sizes into the Wordpress editor? (e.g. Thumbnail, Medium, Large, Full, WooCommerce Thumbnail, WooCommerce Main Image)
I am aware it's possible to add custom size(s) (per https://generatepress.com/forums/topic/gallery-grid-perfectly-square-same-size-images/#post-600638), but the idea here is to prevent creating more copies of the images in the database.
Thanks!
Hi there,
not sure if this will work but you have the image_size_names_choose filter that allows you to add custom image sizes to the image size select box. Example here:
https://developer.wordpress.org/reference/hooks/image_size_names_choose/#comment-4631
And a list of the woo attachment sizes can be found here:
https://docs.woocommerce.com/document/image-sizes-theme-developers/#section-4
Although i am not sure that is 100% up to date.
This snippet worked perfectly:
// Make custom sizes selectable from WordPress admin.
function custom_image_sizes( $size_names ) {
$new_sizes = array(
'woocommerce_thumbnail' => __( 'WooCommerce Thumbnail (300x300 cropped)'),
);
return array_merge( $size_names, $new_sizes );
}
add_filter( 'image_size_names_choose', 'custom_image_sizes' );
Thanks for your EXCELLENT support! :)
Awesome - glad to be of help :)