Solution: Display Alternate Product Image on Hover

Highlighted

Hey guys, I've noticed this seems to be a big issue in the community. I know Shopify has put out a tutorial for this but it just doesn't work for a lot of people, myself included.

Here's the solution that worked for me. I was able to find these solutions from a couple of different people within this thread. I just wanted to post the full, cleaned-up versions here to hopefully make it easier for folks to find and implement.

I use the Debut theme but I've seen others say it worked for them using other themes as well. I don't know anything about code so I won't be able to help you troubleshoot things but hopefully others will. 

*Please be sure to duplicate your theme and try this code out on a copy of your theme before you implement it on your live theme just so you can see that everything works as it should.

Step 1

Copy and paste this at the end of your theme.css.liquid (or .scss.liquid) file: 

/* ===============================================
// Reveal module
// =============================================== */
.has-secondary.grid-view-item__link img.secondary{
 display:none;
}

.has-secondary.grid-view-item__link:hover img.secondary{
 display:block;
}

.has-secondary.grid-view-item__link:hover img.grid-view-item__image{
 display:none;
}

@media screen and (min-width:767px){
.has-secondary.grid-view-item__link img.secondary{
 display:none;
}

.has-secondary.grid-view-item__link:hover img.secondary{
 display:block;
}

.has-secondary.grid-view-item__link:hover img.grid-view-item__image{
 display:none;
}
}

@media screen and (max-width:767px){
.has-secondary.grid-view-item__link img.secondary{
 display:none;
}
}
.grid-view-item__title {
margin-top: 10px;
}

Step 2 

Next, replace all the code in product-card-grid.liquid file with this:

{% unless grid_image_width %}
  {%- assign grid_image_width = '600x600' -%}
{% endunless %}
<div class="grid-view-item{% unless product.available %} product-price--sold-out grid-view-item--sold-out{% endunless %}">
  <a class="grid-view-item__link {% if product.images.size > 1 %} has-secondary{% endif %}" href="{{ product.url | within: collection }}">
    <img class="grid-view-item__image" src="{{ product.featured_image.src | img_url: grid_image_width }}" alt="{{ product.featured_image.alt }}">
    {% if product.images.size > 1 %}
     <img class="secondary" src="{{ product.images.last | img_url: grid_image_width }}" alt="{{ product.images.last.alt | escape }}">
    {% endif %}
    <div class="h4 grid-view-item__title">{{ product.title }}</div>
    {% if section.settings.show_vendor %}
      <div class="grid-view-item__vendor">{{ product.vendor }}</div>
    {% endif %}
    <div class="grid-view-item__meta">
      {% include 'product-price', variant: product %}
    </div>
  </a>
</div>

 This will display your last image on hover, you can replace product.images.last with product.images[1] if you want the second photo to display instead.

Thanks guys! 

Brittany Witt
0 Likes
Highlighted
New Member
4 0 0

Hi,

 

I don't find product-card-grid.liquid ? My theme is Venture.

 

Thanks,

Sam

 

0 Likes
Highlighted

@Messa57fr , from the Shopify tutorial I linked to in my original post:

If your theme doesn't have a product-grid-item.liquid file, then look for one of the following:

  • product-card.liquid
  • product-card-grid.liquid
  • product-loop.liquid

Hopefully, this will help you out!

Brittany Witt
1 Like