Is there a way (maybe via functions.php) to change the product-image in woocommerce shops (archive page) on hover with the first attached gallery image of the product? I cannot find how to target both. I guess it must be sth like this:
add_action( 'woocommerce_shop_loop_item', 'change_image_on_hover', 10 );
function change_image_on_hover() {
$product->get_gallery_image_ids();
print 'woocommerce_gallery_image';
}
7
Answers
CSS can detect when the user is hovering over an image. Is it possible for you to load both images, and then just turn one off and one on when hover is detected?
The code for that would look like this:
HTML:
CSS:
If this doesn’t work, check out this thread for other solution using js/jquery
You can use the plugin if you have not removed the default action and filter of WooCommerce.
Here is the plugin link
Is this what you are looking for?
WooCommerce Product Image Flipper
It seems that it has not been tested with the latest 3 major WordPress releases though. You can still try it and see.
This thread also seems to explain what you need.
What I think you’ll want to do, assuming your installation is a somewhat standard WooC installation, is utilize the loop item action hook to add the desired on-hover image.
Preliminary CSS:
The above will get what you want for one type of shop archive display, to achieve a simple replacement, but there will be numerous particulars that you may need or want to customize for your site. 150x150px may not be the right size for your theme, for example. Or you may decide you need to replace the default image completely with a different set, and that to get a particular transition effect, or to get consistency with other effects in use on your site, you’ll need a different approach to CSS and possibly to javascript.
Use this code is working perfectly | Woocomerce Latest Version
Switch product image on hover on WooCommerce archive page
Use this you will get the full size image of the product
If you want to use this on
product-content.php
use globalproduct
instead ofwc_get_product
Then: