Skip to content

Instantly share code, notes, and snippets.

@vosters
vosters / product-grid-item.liquid
Created January 3, 2018 03:40
Display 2nd product image on hover within Shopify collection loop
<a href="{{ product.url | within: collection }}" class="grid__image" {% if template == 'product' %}onclick="ga('send', 'event', 'Related Products', 'Clicked Related Product - {{ product.type }}', '{{ product.title }}');"{% elsif template == 'index' %}onclick="ga('send', 'event', 'Homepage Products', 'Clicked Best Sellers - {{ product.title }}');"{% endif %}>
{% if product.images.size > 1 %}
<img src="{{ product.images[0] | product_img_url: 'large' }}" alt="{{ product.title | escape }}" />
<img src="{{ product.images[1] | product_img_url: 'large' }}" alt="{{ product.title | escape }}" style="display:none" />
{% else %}
<img src="{{ product.featured_image.src | img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}">
{% endif %}
</a>
@vosters
vosters / product-grid-item.liquid
Created January 3, 2018 03:27
Display Quick Add To Cart in Shopify Collection On Hover (w/ single option dropdown)
{% comment %}
QUICK ADD TO CART
https://ecommerce.shopify.com/c/ecommerce-design/t/quick-add-to-cart-254790
Copy and paste this code within your div for your product display within a collection
{% endcomment %}
<form action="/cart/add" method="post" enctype="multipart/form-data" id="AddToCartForm" class="quick-add-to-cart small--hide clearfix">
{% if product.variants.size > 1 %}
<select id="product-select-{{ product.id }}" name='id' class="text-center">
@vosters
vosters / parameter-display-adjust-liquid
Last active January 3, 2018 03:05
Show/hide html based on URL parameter using js-cookie
{% comment %}
USES JS-COOKIE
https://github.com/js-cookie/js-cookie/blob/master/README.md
{% endcomment %}
// Make sure 'js-cookie.js' is uploaded to your Shopify Theme's assets folder
{{ 'js-cookie.js' | asset_url | script_tag }}
{% comment %}
Adjust display based on URL parameters