Product Card — Sale
Product card with sale badge and compare-at price.
About this module
A Shopify product card that highlights discounts with a sale badge and strikethrough compare-at price.
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-sale, 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-sale` under Sections and paste the source.
{{ 'styles.css' | asset_url | stylesheet_tag }} <div class="mh-sale"> <div class="mh-sale-media"> <a href="{{ product.url }}"> {% if product.featured_image %} <img src="{{ product.featured_image | image_url: width: 700 }}" alt="{{ product.featured_image.alt | escape }}" width="700" height="700" loading="lazy" /> {% else %} {{ 'product-2' | placeholder_svg_tag: 'mh-sale-ph' }} {% endif %} </a> {% if product.compare_at_price > product.price %} <span class="mh-sale-badge">{{ section.settings.sale_badge_label }}</span> {% endif %} </div> <div class="mh-sale-body"> {% if section.settings.show_vendor and product.vendor != blank %} <span class="mh-sale-vendor">{{ product.vendor }}</span> {% endif %} <a href="{{ product.url }}" class="mh-sale-title">{{ product.title }}</a> <div class="mh-sale-prices"> <span class="mh-sale-price">{{ product.price | money }}</span> {% if section.settings.show_compare_at and product.compare_at_price > product.price %} <span class="mh-sale-compare">{{ product.compare_at_price | money }}</span> {% endif %} </div> </div> </div> {% schema %} { "name": "MH Product Card Sale", "tag": "div", "settings": [ { "type": "text", "id": "sale_badge_label", "label": "Sale badge label", "default": "Sale" }, { "type": "checkbox", "id": "show_compare_at", "label": "Show compare-at price", "default": true }, { "type": "checkbox", "id": "show_vendor", "label": "Show vendor", "default": false } ], "presets": [{ "name": "MH Product Card Sale", "category": "ModuleHarbor" }] } {% endschema %} - 2
Configure in the customizer
Adjust the settings that ship with the section schema.