Shopify Product Card
A product card with quick add to cart.
About this module
A Shopify product card for collection grids with image, title, price and a quick 'Add to cart' button.
Source code
Installation
- 1
Open Shopify Admin
Go to Online Store → Themes.
- 2
Edit code
Click the ellipsis (⋯) next to your theme and choose Edit Code.
- 3
Create the section
In the Sections folder, click Add a new section, name it mh-product-card, and replace the contents with the Liquid source below.
- 4
Save
Save the file. The section now appears in the Theme Customizer.
- 5
Add it to the page
Open the Theme Customizer, click Add section, search for it and add it where you like.
Usage
- 1
Paste the section
Create `mh-product-card` under Sections and paste the source.
{{ 'styles.css' | asset_url | stylesheet_tag }} <div class="mh-product-card"> <a href="{{ product.url }}" class="mh-pc-media"> {% if product.featured_image %} <img src="{{ product.featured_image | image_url: width: 600 }}" alt="{{ product.featured_image.alt | escape }}" width="600" height="600" loading="lazy" /> {% else %} {{ 'product-1' | placeholder_svg_tag: 'mh-pc-placeholder' }} {% endif %} </a> <div class="mh-pc-body"> {% if section.settings.show_vendor and product.vendor != blank %} <span class="mh-pc-vendor">{{ product.vendor }}</span> {% endif %} <a href="{{ product.url }}" class="mh-pc-title">{{ product.title }}</a> {% if section.settings.show_price %} <span class="mh-pc-price">{{ product.price | money }}</span> {% endif %} {% if section.settings.enable_quick_add %} <form method="post" action="/cart/add" class="mh-pc-form"> <input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}" /> <input type="hidden" name="quantity" value="1" /> <button type="submit" class="mh-pc-add">{{ section.settings.button_label }}</button> </form> {% endif %} </div> </div> {% schema %} { "name": "MH Product Card", "tag": "div", "settings": [ { "type": "checkbox", "id": "show_vendor", "label": "Show vendor", "default": true }, { "type": "checkbox", "id": "show_price", "label": "Show price", "default": true }, { "type": "checkbox", "id": "enable_quick_add", "label": "Enable quick add", "default": true }, { "type": "text", "id": "button_label", "label": "Button label", "default": "Add to cart" } ], "presets": [{ "name": "MH Product Card", "category": "ModuleHarbor" }] } {% endschema %} - 2
Configure in the customizer
Adjust the settings that ship with the section schema.