Last active
November 5, 2020 00:10
-
-
Save gokaybiz/e7bcb6751dd3967a2b61b8ec83144409 to your computer and use it in GitHub Desktop.
[Woocommerce Gallery] Disable pretty photo plugin and update main thumbnail with mini thumbnails on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thumbnail_list = jQuery('.woocommerce-product-gallery__image') | |
if (thumbnail_list.length > 0) { | |
var main_thumb = thumbnail_list.slice(0, 1) | |
thumbnail_list.slice(1).each(function() { | |
jQuery(this).children('a').contents().unwrap() | |
jQuery(this).on('click', function(e) { | |
e.preventDefault(); | |
var thumb = jQuery(this).children() | |
var max_res = (thumb.attr('srcset').split(',') | |
.map(item => { | |
item = item.trim().split(' ') | |
item[1] = item[1].slice(0, -1) | |
return item | |
}) | |
.sort((b, a) => { | |
return a[1] - b[1] | |
}))[0][0] | |
var src_set = thumb.attr('srcset') | |
console.log(src_set, max_res) | |
main_thumb.attr('src', max_res) | |
main_thumb.children('a').children('img').attr('data-thumb', max_res) | |
main_thumb.children('a').children('img').attr('src', max_res) | |
main_thumb.children('img').attr('src', max_res) | |
main_thumb.children('a').attr('href', max_res) | |
main_thumb.children('a').children('img').attr('srcset', thumb.attr('srcset')) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment