Skip to content

Instantly share code, notes, and snippets.

@odessy
Last active June 12, 2020 21:48
Show Gist options
  • Save odessy/a27b84a39991815048dda18ef886fc96 to your computer and use it in GitHub Desktop.
Save odessy/a27b84a39991815048dda18ef886fc96 to your computer and use it in GitHub Desktop.
Pipeline change product option for modification of https://gist.github.com/drabbytux/a49215c6d0ba16c4d096a56212bbc4ce
$(document).ready(function() {
thumbnails = $('#ProductThumbs-product img[src*="/products/"]');
if (thumbnails.length) {
thumbnails.on('click', function() {
var arrImage = $(this).attr('src').split('?')[0].split('.');
var strExtention = arrImage.pop();
var strRemaining = arrImage.pop()
.replace(/_(pico|icon|thumb|small|compact|medium|large|grande)/gi, '')
.replace(/_[a-zA-Z0-9@]+$/,'');
var strNewImage = arrImage.join('.')+"."+strRemaining+"."+strExtention;
if (typeof variantImages[strNewImage] !== 'undefined') {
productOptions.forEach(function (value, i) {
optionValue = variantImages[strNewImage]['option-'+i];
if (optionValue !== null && optionValue !== 'undefined' && $('.single-option-selector:eq('+i+') option').filter(function() {
var text = $(this).text();
if(theme !== null && theme.strings !== 'undefined' ){
text = text.replace(" - "+theme.strings.Unavailable, "").replace(" - "+theme.strings.soldOut, "")
}
return text === optionValue }).length) {
$('.single-option-selector:eq('+i+')').val(optionValue).trigger('change');
}
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment