Skip to content

Instantly share code, notes, and snippets.

@PechenkiUA
Last active February 10, 2021 21:10
Show Gist options
  • Save PechenkiUA/b1c9a8f7536a2abc7764aeb8ed0deb4b to your computer and use it in GitHub Desktop.
Save PechenkiUA/b1c9a8f7536a2abc7764aeb8ed0deb4b to your computer and use it in GitHub Desktop.
add to image is galery product
<?php
add_action( 'woocommerce_before_shop_loop_item_title', function(){
if (is_user_logged_in()) {
global $product;
$attachment_ids = $product->get_gallery_image_ids();
$attr = ['class'=>'to-image'];
echo wp_get_attachment_image(reset($attachment_ids), 'shop_catalog',false, $attr);
}
}, 10 );
/* css
.woocommerce-LoopProduct-link {
position: relative;
}
.to-image {
position: absolute;
top: 0;
opacity: 0;
transition: .5s;
}
.woocommerce-LoopProduct-link:hover .to-image{
opacity: 1;
transition: .5s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment