Shopify guide

Online Store 2.0 · Custom Liquid

A quantity calculator on your Shopify product pages

A customer looking at a box of tiles wants to know how many boxes the bathroom takes. A Custom Liquid section puts the answer next to the Add to cart button: the calculator works out the quantity with waste, in metric and imperial, and nothing is added to your checkout or your apps.

  • Custom LiquidTheme element
  • AllowedFitting script
  • Under 3 KBCode size
  • NoneApp to install

Before you start

  • An Online Store 2.0 theme such as Dawn. Most current themes offer a Custom Liquid section; if yours does not, its own documentation says where custom code goes.
  • Permission to edit themes in your Shopify admin.
  • For the product-page code: product types spelled the same way on every product (for example Tile, Paint, Flooring).

Step by step

  1. Open the theme editor

    In your Shopify admin go to Online Store, then Themes, and click Customize on the theme you want to change. Working on a duplicate first lets you check everything before customers see it.

  2. Choose the page

    Use the drop-down at the top of the editor: Products, then Default product for every product page, or a page or the home page for a single calculator.

  3. Add a Custom Liquid section

    In the sidebar's Template area click Add section and pick Custom Liquid. On a product page you can instead add a Custom Liquid block inside the product information section, so it sits beside the price and the buy buttons.

  4. Paste the code

    Click the new section, paste the code below into its Liquid box, and the editor's preview shows the calculator in place.

  5. Place it

    Drag the section or block by its handle: under the description, or just below the quantity selector, is where shoppers look while deciding how many to buy.

  6. Save and check a product

    Click Save, open a product of each type in a private window, and change a measurement to see the result update.

Your code

Custom Liquid: one calculator
<iframe src="https://craftquantities.com/embed/?calc=floor-tile-calculator&ev=1&fmt=compact" width="100%" height="460" loading="lazy" style="border:1px solid #e4e4e7;border-radius:12px;max-width:100%" title="Floor &amp; Wall Tile Calculator — Craft Quantities"></iframe>
<p style="margin:4px 0 0;font:12px/1.4 system-ui,sans-serif">Calculator by <a href="https://craftquantities.com/calculators/renovation-construction/floor-tile-calculator/">Craft Quantities</a></p>
<script>(function(){if(window.cqEmbedFit)return;window.cqEmbedFit=1;window.addEventListener("message",function(e){var d=e.data;if(!d||d.source!=="craft-quantities"||d.type!=="size"||typeof d.height!=="number"||!isFinite(d.height))return;var f=document.getElementsByTagName("iframe");for(var i=0;i<f.length;i++){if(f[i].contentWindow!==e.source)continue;var a=document.createElement("a");a.href=f[i].src;if(a.protocol+"//"+a.host!==e.origin)return;f[i].style.height=Math.min(6000,Math.max(200,Math.ceil(d.height)))+"px";return}})})();</script>

The calculator you pick above, the visible credit line, and a short script that fits the frame's height to its content.

Custom Liquid: the calculator that matches the product
{%- liquid
  assign cq_calc = blank
  if product.type contains 'Tile'
    assign cq_calc = 'floor-tile-calculator'
    assign cq_page = 'https://craftquantities.com/calculators/renovation-construction/floor-tile-calculator/'
  elsif product.type contains 'Paint'
    assign cq_calc = 'paint-calculator'
    assign cq_page = 'https://craftquantities.com/calculators/renovation-construction/paint-calculator/'
  elsif product.type contains 'Flooring'
    assign cq_calc = 'flooring-calculator'
    assign cq_page = 'https://craftquantities.com/calculators/renovation-construction/flooring-calculator/'
  endif
-%}
{%- if cq_calc != blank -%}
<iframe src="https://craftquantities.com/embed/?calc={{ cq_calc }}&ev=1&fmt=compact" width="100%" height="460" loading="lazy" style="border:1px solid #e4e4e7;border-radius:12px;max-width:100%" title="{{ product.type | escape }} calculator — Craft Quantities"></iframe>
<p style="margin:4px 0 0;font:12px/1.4 system-ui,sans-serif">Calculator by <a href="{{ cq_page }}">Craft Quantities</a></p>
<script>(function(){if(window.cqEmbedFit)return;window.cqEmbedFit=1;window.addEventListener("message",function(e){var d=e.data;if(!d||d.source!=="craft-quantities"||d.type!=="size"||typeof d.height!=="number"||!isFinite(d.height))return;var f=document.getElementsByTagName("iframe");for(var i=0;i<f.length;i++){if(f[i].contentWindow!==e.source)continue;var a=document.createElement("a");a.href=f[i].src;if(a.protocol+"//"+a.host!==e.origin)return;f[i].style.height=Math.min(6000,Math.max(200,Math.ceil(d.height)))+"px";return}})})();</script>
{%- endif -%}

For the default product template. It reads product.type: a tile product shows the tile calculator, paint the paint calculator, flooring the flooring calculator, and every other product shows nothing. Edit the words in quotes to match your own product types.

Every other option is in the full builder.

What visitors see

Your product page · Description · Add to cart

Calculator by Craft Quantities

On product pages: tile, paint and flooring

The product-page code is one block for the whole catalogue. Liquid runs on Shopify's side before the page is sent, so a product whose type does not match draws no frame at all, and the shopper downloads nothing extra.

Shopify's contains is case-sensitive: Tile does not match tile. Check the types in Products and copy their spelling into the code.

If only some products should have a calculator, make a template for them instead: in the theme editor open Products, choose Create template, base it on the default product, add the Custom Liquid block there, then assign the template under Products, the product, Theme template. Bulk edit has a template column for many products at once.

Compact is the format for a product page: the inputs, the answer in both unit systems, and a link to the full calculator for anyone who wants the breakdown. Shopify limits a Liquid setting to 50 KB, and this code is a few percent of that.

Troubleshooting

There is no Custom Liquid in Add section
Your theme is not an Online Store 2.0 theme, or it leaves the section out. Check the theme's documentation for where custom code goes, or move to a current theme such as Dawn.
The calculator shows on every product
It was added to the default product template without the product-type code. Use the second snippet, or a separate template assigned to the products that need it.
A tile product shows nothing
Its product type does not contain the word in the code, letter for letter. Open the product in Products and compare the spelling, capitals included.
The frame is cut off at the bottom
Something removed the fitting script. Leave the script line in, or raise the height value in the iframe tag until the whole calculator shows.
It works in the editor but not on the store
The changes were not saved, or you edited a theme that is not the published one. Save, then publish the theme or make the same change on the live theme.

Why it helps

  • The question "how many boxes do I need?" is answered on the product page, at the moment the shopper chooses a quantity, instead of in an email to your support inbox.
  • Each result includes a waste allowance and is shown in metric and imperial, so a shopper measuring in feet and a pack sold by the square metre still agree.
  • No app subscription and nothing added to checkout: the code is a frame and a link, and it sets no cookies and runs no tracking of its own.
  • The maths and its sources sit on one public page per calculator, which the credit line links to, so a shopper who doubts a figure can check how it was worked out.

Sources

Checked against these help pages on 26 November 2026.

  1. Shopify Help Center: Customizing sections and blocks
  2. Shopify Help Center: Templates (creating and assigning)
  3. Shopify Help Center: Dawn page types
  4. Shopify Developer docs: Input settings (the liquid setting type)