Create ‘large’ product preview image by condition
-
Hi,
I’m searching for a way to use a preview image when magnifying the image on the single product page. This image should also be displayed when the lightbox is activated.
I managed to create a custom thumbnail size by this code in my functions.php
add_image_size( 'preview', $width = 3072, $height =3072, $crop = false );
and set the default thumbnail size to preview in product image.php:
$thumbnail_size = apply_filters( 'woocommerce_product_thumbnails_large_size', 'preview' );// changed 'large' to 'preview' by me
Next I try to make the selection of this ‘preview image’ conditional with this code:
$filemeta = wp_get_attachment_metadata( $post_thumbnail_id, FALSE ); $image_width = $filemeta['width']; $image_height = $filemeta['height']; if ($image_width < 3072 || $image_height < 3072){ $thumbnail_size = apply_filters( 'woocommerce_product_thumbnails_large_size', 'large' ); } else { $thumbnail_size = apply_filters( 'woocommerce_product_thumbnails_large_size', 'preview' ); }
Sadly it does not work. Te code you see is in my functions.php without an add_action or add_filter statement (I don’t understand those properly but i’m learning every day).
Can somebody help me out here?
- The topic ‘Create ‘large’ product preview image by condition’ is closed to new replies.