Woocommerce Single Product Thumb Image Click Replace Main Image

I just got some client ask me to make so that on woocommerce single product page, when user click on the thumbnail image, then the main image of the product changed to the thumbnail image. I completed it using jquery as follow:

jQuery('body').on('click','.woocommerce-product-gallery__image a', function(e){
        var thumb_fullsize = jQuery(this).attr('href').replace('-350x460','');
            thumb_srcset = jQuery(this).find('img').data('src').replace('.jpg', '-350x460.jpg');
        var tmpImg = new Image();
        window.orgWidth = '';
        window.orgHeight = '';
        tmpImg.src=thumb_fullsize; //or  document.images[i].src;
          orgWidth = tmpImg.width;
          orgHeight = tmpImg.height;
            jQuery('.zoomImg').load(function() {
            jQuery('.zoomImg').prev().attr('href', thumb_fullsize);
            jQuery('.zoomImg').prev().find('img').attr('src', thumb_srcset).data('src', thumb_fullsize).data('large_image', thumb_fullsize).data('large_image_width', orgWidth).data('large_image_height',orgHeight);
        return false;

Hope it help if you need it.

One Comment

  1. Kamil-Reply
    June 7, 2018 at 7:20 pm


    in what file I can do this?

    Thanks, Kamil

Leave A Comment

%d bloggers like this: