change magnifier and lightbox image woocommerce

2019-08-16 03:19发布

as I'm developing a stock photo site I don't want image theft. I have a watermark solution installed and all product images are watermarked except for the full size. This is the one for download after a purchase.

The default WooCommerce behavior is now that when I hover over the displayed image on the single product page the magnifier is launched. Ok, but the full size image is displayed without my watermark. Even so when the image is clicked the lightbox open displaying the full size image.

When a user want he kan inspect the element, copy the url and download the full size image without buying. That's an unwanted situation.

Does someone knows how to show a watermarked (larger) preview in the magnifier and lightbox? I was not able to find it myself.

Best wishes

1条回答
地球回转人心会变
2楼-- · 2019-08-16 03:55

Found it. Just add another thumbnail size called preview. So I added this line of code in my functions.php file:

add_image_size( 'preview', $width = 3072, $height =3072, $crop = false );

and changed

$thumbnail_size    = apply_filters( 'woocommerce_product_thumbnails_large_size', 'large' );

in the product-image.php file to:

$thumbnail_size    = apply_filters( 'woocommerce_product_thumbnails_large_size', 'preview' );

Don't forget to copy the product-image.php template file to your child theme.

查看更多
登录 后发表回答