• Resolved Adri Oosterwijk

    (@adri-oosterwijk)


    Hi,
    I’ve picked up a project for which I could not find the time in the past period. I have problems with the images on the single product page and therefor on the magnifier also.

    Case is this:
    The site I’m developing is a stockphoto site and as you can imagine I want to protect the images from theft as much as I can. That’s why I use a watermark plugin. In WooCommerce versions prior to 3.3 I was able to present the visitor with a large thumb on the single product page and in the magnifier / lightbox.

    To achieve this I added a custom thumbnail size by this code:

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

    Next I had some logic to select the ‘preview’ or the default ‘large’ image size. That worked well.

    After updating this is not working anymore and I can’t figure out how to get it working again. Woocommerce picks the full size image (without a watermark) and then it is easily stolen. I’m on it for a long time and almost all of the topics are about the not being square of the thumbs in the catalog.

    I’m on the end of my rope here. Please help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Adri Oosterwijk

    (@adri-oosterwijk)

    Addition to make it more clear hopefully: In short I want to set a custom image size in the magnifier and lightbox.

    Thread Starter Adri Oosterwijk

    (@adri-oosterwijk)

    I found out that it is controlled by line 1399 in wc-template functions:

    $full_size = apply_filters( 'woocommerce_gallery_full_size', apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' ) );

    I tried to create a function in my child themes functions.php to change the sizes but it looks like the function is not executing. See code below:

    function change_magnifier_lightbox_image_size(){
    echo "De post" , $post;
    
    $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo "De ID ", $post_thumbnail_id;
    $filemeta = wp_get_attachment_metadata( $post_thumbnail_id, FALSE );
    echo "De filemeta ", $filemeta;
    
    if ($filemeta['width']>3071 || $filemeta['height']>3071){
      $full_size         = apply_filters( 'woocommerce_gallery_full_size', apply_filters( 'woocommerce_product_thumbnails_large_size', 'preview' ) );
    }else{
      $full_size         = apply_filters( 'woocommerce_gallery_full_size', apply_filters( 'woocommerce_product_thumbnails_large_size', 'large' ) );
    };
    };
    apply_filters( 'woocommerce_product_thumbnails_large_size', 'change_magnifier_lightbox_image_size' );
    

    What am I missing here? Any help is much appreciated.

    Thread Starter Adri Oosterwijk

    (@adri-oosterwijk)

    It is solved.

    LoicTheAztec has provided me with the following code over at StackOverflow:

    add_filter( 'woocommerce_gallery_full_size', 'change_magnifier_lightbox_image_size', 20, 1 );
    function change_magnifier_lightbox_image_size( $size ){
        $thumbnail_id = get_post_thumbnail_id( get_the_id() );
        $attachment   = wp_get_attachment_metadata( $thumbnail_id, FALSE );
    
        // Always return a value in a filter hook
        return ( $attachment['width'] > 3071 || $attachment['height'] > 3071 ) ? 'preview' : 'large';
    }

    Just in case anyone has a similar issue.

    It’s a bit of a downer that I did not got any response from this support page. The happinez engineers are, as it looks like, to busy being happy.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Product image on single product page. A special case…’ is closed to new replies.