Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WPDevHQ/564b0c15b2fb359351393dc4e50fc3fc to your computer and use it in GitHub Desktop.
Save WPDevHQ/564b0c15b2fb359351393dc4e50fc3fc to your computer and use it in GitHub Desktop.
// Add to a js file in your theme/child theme or create a new js file. If you create a new file, remember to enqueue from functions.php. See example below.
// Adds thumbnail hover to main product img
jQuery(document).ready(function($) {
// Get the main WC image as a variable
var wcih_main_imgage = $( 'a.woocommerce-main-image' ).attr( 'href' );
// This is what will happen when you hover a product thumb
$(".thumbnails a").hover(
// Swap out the main image with the thumb
function(){
var photo_fullsize = $('.thumbnails a').attr('href');
$('.woocommerce-main-image img').attr('src', photo_fullsize);
},
// Return the main image to the original
function(){
$('.woocommerce-main-image img').attr('src', wcih_main_imgage);
}
);
});
// If you dont need to enqueue from functions.php remove the below
function YourUniqueID_add_enqueue_scripts() {
wp_enqueue_script( 'theme_js', trailingslashit( get_stylesheet_directory_uri() ) . 'js/theme.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'YourUniqueID_add_enqueue_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment