Last active
May 22, 2019 13:43
-
-
Save gthayer/943ae70f833004e22f26 to your computer and use it in GitHub Desktop.
WooCommerce Popup Gallery - Magnific
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
//woocommerce gallery - main header | |
$('.woocommerce-main-image').click(function() { | |
var $main_image = $('a.woocommerce-main-image').attr('href'); | |
var $items = new Array(); | |
var link = $('a.woocommerce-main-image').attr('href'); | |
var alt = $('a.woocommerce-main-image').find('img').attr('alt'); | |
var mainitem = { src: link, title: alt }; | |
$items.push(mainitem); | |
$('.thumbnails a').each(function() { | |
var link = $(this).attr('href'); | |
var alt = $(this).find('img').attr('alt'); | |
var item = { src: link, title: alt }; | |
if ($.inArray(item, $items) == -1) { | |
$items.push(item); | |
} | |
}); | |
$.magnificPopup.open({ | |
items: $items, | |
gallery: { | |
enabled: true | |
}, | |
type: 'image' | |
}); | |
return false; | |
}); | |
//Changes product thumbnails so they replace the featured image on the product page when clicked. | |
$(document).on('click','.attachment-shop_thumbnail', function(){ | |
var old_featured_image = $('.attachment-shop_single').attr('src').replace('-600x600','-300x300'); | |
var new_featured_image = $(this).attr('src').replace('-300x300','-600x600'); | |
$('.woocommerce-main-image img').attr('src', new_featured_image); | |
$('.woocommerce-main-image').attr('href', new_featured_image); | |
$(this).attr('src', old_featured_image); | |
$(this).parent().attr('href', old_featured_image); | |
console.log(old_featured_image); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment