Shopify

Mastering Dynamic Product Pages on Shopify: Custom Liquid for Enhanced Conversions

As a Shopify migration expert and community analyst at Shopping Cart Mover, I spend a lot of time delving into the Shopify forums, uncovering common challenges and innovative solutions. Recently, a fantastic discussion caught my eye – one that addresses a crucial aspect of e-commerce success: dynamic product pages. Many merchants running a Shopify store, especially those on Dawn-based themes like 'Smile', often seek to enhance their product pages beyond the standard layout.

The original query from a community member, saqlain1, showcased a clear vision: to integrate engaging feature pills, an eye-catching offer line with coupon and prepaid discounts, a real-time stock alert, and reassuring trust badges directly onto their product pages. This isn't just about aesthetics; it's about creating a more informative, persuasive, and conversion-focused shopping experience.

Shopify theme editor showing 'Add block' with 'Custom liquid' selected
Shopify theme editor showing 'Add block' with 'Custom liquid' selected

Why Dynamic Product Content is a Game Changer

In today's competitive e-commerce landscape, static product pages simply don't cut it. Dynamic content, which updates based on user interaction or product data, is vital for:

  • Boosting Engagement: Interactive elements keep shoppers interested and exploring.
  • Building Trust: Clear, real-time information (like stock levels) fosters transparency.
  • Driving Conversions: Personalized offers, urgency alerts, and compelling features directly influence purchasing decisions.
  • Enhancing User Experience: Providing all necessary information upfront reduces friction and questions.

The Challenge: Static Elements on Variant Change

A common hurdle with many modern Shopify themes, including Dawn and its derivatives like 'Smile', is how they handle variant changes. When a customer selects a different size or color, the theme typically refreshes only core elements like the price, SKU, and inventory count. This leaves custom-added blocks, such as offer lines or 'Only X left' messages, stuck displaying information for the initially loaded variant. This inconsistency can confuse customers and undermine your conversion efforts.

Unlocking Dynamics with Shopify's Custom Liquid Blocks

The brilliant solution, championed by community members like Ploqo and refined by jowel-66, lies in leveraging Shopify’s powerful Custom Liquid blocks. These blocks allow you to inject custom HTML, CSS, and Liquid code directly into your theme's sections, giving you unparalleled control over your store's appearance and functionality without needing to dive deep into theme files.

Step-by-Step Implementation Guide

Before making any changes, it's always best practice to duplicate your theme. This creates a safe backup, allowing you to experiment without affecting your live store.

Step 1: Accessing Your Theme Editor

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find your current theme (or the duplicate you're working on), click Actions, and then Edit code.
  3. At the top of the theme editor, switch the page view to Products > Default product. This ensures your changes apply to all product pages using this template.

Step 2: Adding Feature Pills

Feature pills are an excellent way to highlight key product benefits concisely. Here's how to add them:

  1. Under the Product information section in the theme editor, click Add block and select Custom liquid.
  2. Paste the following code into the Custom liquid box:
{%- assign points = '10,000+ microcapsules|8x Hyaluronic Acid|Green Antioxidant|Metacool Cooling|For sensitive skin' | split: '|' -%}
{%- for point in points -%} {{ point }} {%- endfor -%}

You can customize the `points` variable with your product's unique selling propositions. Drag this new Custom liquid block so it sits just above the Price block for optimal visibility.

Step 3: Crafting Dynamic Offer Lines & Stock Alerts

Next, let's add an enticing offer line and a real-time stock alert to create urgency and highlight value.

  1. Add a second Custom liquid block.
  2. Paste this code into the box:
{%- assign coup -%}
{%- assign coup -%}
{%- assign prepaid_percent = 5 -%}
{%- assign details_line = 'MRP incl. of all taxes · 50g · 30+ days per tube' -%}
{%- assign low_stock_under = 50 -%}

{%- assign v = product.selected_or_first_available_variant -%}
{%- assign keep1 = 100 | minus: coupon_percent -%}
{%- assign keep2 = 100 | minus: prepaid_percent -%}
{%- assign offer_price = v.price | times: keep1 | divided_by: 100 | times: keep2 | divided_by: 100 -%}

{%- if v.compare_at_price > v.price -%} {%- assign save = v.compare_at_price | minus: v.price | times: 100.0 | divided_by: v.compare_at_price | round -%} Save {{ save }}% {%- endif -%} {{ offer_price | money }} with {{ coupon_code }} + {{ prepaid_percent }}% prepaid

{{ details_line }}

{%- if v.inventory_management == 'shopify' and v.inventory_quantity > 0 and v.inventory_quantity < low_stock_under -%}

Only {{ v.inventory_quantity }} left in stock. Grab yours before it is gone.

{%- endif -%}

Modify the `coupon_code`, `coupon_percent`, `prepaid_percent`, `details_line`, and `low_stock_under` variables to match your store's promotions. Drag this block to sit just below the Price block.

Step 4: The Crucial JavaScript Fix for Variant Updates

This is where jowel-66's insight becomes invaluable. To ensure your offer line and stock alerts update dynamically when a shopper picks a different variant, you need to add a specific attribute and a JavaScript snippet.

  1. Modify the opening `div` tag of your second Custom liquid block (the one with the offer line and stock alert) to include `data-live-block="ao-offer"`:
  1. Then, paste this JavaScript at the very end of the same Custom liquid block:

This script listens for Shopify's `variantChange` event. When a variant is selected, it receives the updated HTML for the product section and then refreshes any elements marked with `data-live-block="ao-offer"` to reflect the new variant's data. This ensures your offer prices, 'Save %', and stock lines are always accurate.

Customization and Best Practices

  • Tailor the Content: Don't forget to adjust the Liquid variables and static text within the code snippets to perfectly match your products and promotions.
  • Styling: The `