I would like the thumbnails underneath the main image on the single product page to replace the main image when they are either clicked or on hover, I prefer hover. Right now the thumbnails just open in their own fancybox. This is a very common feature on most big ecommerce sites and it’s weird that it’s not an option in woocommerce. Any help will be greatly appreciated.
Leave a Reply
You must be logged in to post a comment.
I have just achieved the effect by my own. I will post it here in case others find this thread:
.replace(‘-100×132’) eliminates the size from url of the image to return the full image and not the thumbnail. Replace it with your own thumbnails sizes.
My solution is based on:
JavaScript solution
As the original answer already work with string replace, but has to get altered for each and every use case, here’s a solution using a fast Regex
.test()
wrapped up in a self invoking function that uses the default method to prevent events (like following links) from happening.This plugin will delete the first occurrence of any 2-4 digits separated by an
x
and followed by another 2-4 digits. Some examplesHere’s the actual plugin. You’ll just have to fill in a single bit: The actual selector.
To Do: The only thing that you’ll have to do is providing your actual selector (instead of
.class-of-the-thumbnail-image
) for the image. Best would be to (a) fill in some class and then add a filter to the thumbnail to add this class to every image that you want to target.One possible point where your plugin could hook in, would be to combine this with a filter on
post_thumbnail_html
. This filter has some arguments:$html, $post_id, $post_thumbnail_id, $size, $attr
that you can use to alter the HTML.Another, maybe even better would be the
wp_get_attachment_image_attributes
-filter insidewp_get_attachment_image()
, which is called byget_the_post_thumbnail()
, which itself is wrapped bythe_post_thumbnail()
.Simply add something like the following to the plugin above:
Server side solution: PHP
Much easier than anything else is to use the following filter – in case it meets your use case.
You can add just call the full size for every post thumbnail and you’re fine. Then downsize the image via CSS.
After WordPress implemented responsive images in WordPress 4.4, these other scripts tend to be buggy/not working because of the added
srcset
attributes.Here is the snippet I use to fix issues with this:
I found this http://www.magictoolbox.com/magiczoomplus/ and it handles what I needed. I just set the zoom to inner so it doesn’t open a zoom window and it has thumbnail hover that replaces the main image. Maybe this could help someone with a similar issue.
I had problems using the example from the accepted answer, so re-wrote it a bit, jJust in case anyone should need a working example, not dependant on thumbnail size replacement, which also disables the default PrettyPhoto action.