Created
December 30, 2016 01:42
-
-
Save WPDevHQ/564b0c15b2fb359351393dc4e50fc3fc to your computer and use it in GitHub Desktop.
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
// 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