Computes a unit price from price divided by a size metafield and writes it to custom.price_per_unit so the storefront can show e.g. '$0.40 / 100ml'.
async def run(ctx): for variant in await ctx.shopify.query(VARIANTS_WITH_MEASURE): if not variant.measure:
How do you show price per unit on Shopify?
To show price per unit on Shopify, this template divides each variant's price by a size metafield and writes the result to custom.price_per_unit, ready for the theme to render as something like "$0.40 / 100ml". Variants without a size are skipped rather than guessed, and the size unit is whatever your catalog uses: milliliters, grams, meters, pieces. EU consumer rules expect unit pricing on many categories, and marketplaces increasingly ask for the same field.
Typed-in unit prices go stale on the first repricing, and nobody recomputes hundreds of them by hand. Computed on a schedule, the metafield follows every price change on the next run, correct across the whole catalog. The run report shows each value it would write, which doubles as a quick way to spot products whose size data is wrong before a shopper does.
Last updated August 24, 2026
If you run a sharper version of this template, or something it inspired, send it in. We review every application and publish the good ones, credited to you or your agency.
AI writes real Python or TypeScript, a dry run rehearses it, you approve, it deploys.
Free plan · no card · 🇪🇺 EU data residency