We build Shopify apps at Zilancer. Our newest one, ZS Uniform Portal, sells school and workwear uniforms through a private shop per school, company or club. The hard requirement from uniform suppliers was simple to say and annoying to build:

Only verified members of a school may buy that school's crest items. A shared product link must not be enough.

Hiding products in the theme is easy. Stopping checkout is the part that matters, because anyone can open a product URL, add it to the cart with the AJAX Cart API, and pay. This post is how we enforce it at checkout with a Shopify Function, and the one rule that shaped the whole design.

The rule: never trust the cart

Our storefront adds line item properties such as _zs_member (which child or employee the item is for). It's tempting to let checkout read that property and approve the line. Don't. Line item properties and cart attributes are written by the browser, so a shopper can set any value with one fetch('/cart/add.js') call.

So the Function treats every cart attribute as a hint and re-checks it against data only the app can write:

Data Where it lives Who can write it
Which organisations a product belongs to Product metafield $app:uniform/orgs The app
Which members a customer has verified Customer metafield $app:uniform/members The app, after the access code / email domain / invite check
Ordering dates, limits, kit rules per organisation Shop metafields $app:uniform/config (sharded) The app
Which member a line is for Line property _zs_member The shopper (hint only)

$app: metafields are app-reserved, so the theme and other apps can't write them.

The input query

A Cart and Checkout Validation Function (cart.validations.generate.run) gets only what its GraphQL input query asks for. Ours, trimmed:

query CartValidationsGenerateRunInput { buyerJourney { step } shop { localTime { date } c1: metafield(namespace: "$app:uniform", key: "config") { jsonValue } c2: metafield(namespace: "$app:uniform", key: "config_2") { jsonValue } } cart { buyerIdentity { customer { members: metafield(namespace: "$app:uniform", key: "members") { jsonValue } } } lines { quantity member: attribute(key: "_zs_member") { value } merchandise { ... on ProductVariant { id product { id title orgs: metafield(namespace: "$app:uniform", key: "orgs") { jsonValue } } } } } } } 

Two details worth copying:

  1. Config is split across several shop metafields (config, config_2, ...). Function input has size limits, and a supplier with many schools, groups and kit lists outgrows one JSON value. The Function concatenates the shards back together.
  2. shop.localTime.date gives the shop's local date, which we use for "ordering open from / to" windows. No clocks in the browser, no time zone guessing.

The function body

export function cartValidationsGenerateRun(input) { const step = input.buyerJourney?.step; // Let people edit their cart freely; only block at checkout. if (!step || step === "CART_INTERACTION") return { operations: [] }; const config = readConfig([input.shop.c1?.jsonValue, input.shop.c2?.jsonValue]); const members = readMembers(input.cart.buyerIdentity?.customer?.members?.jsonValue); const lines = input.cart.lines .filter((l) => l.merchandise?.__typename === "ProductVariant") .map((l) => ({ quantity: l.quantity, memberHint: Number(l.member?.value) || 0, // hint, re-checked below productOrgs: readProductOrgs(l.merchandise.product.orgs?.jsonValue), title: l.merchandise.product.title, })); const errors = validateCart({ lines, members, config, today: input.shop.localTime?.date }); return { operations: errors.length ? [{ validationAdd: { errors: errors.map((message) => ({ message, target: "$.cart" })) } }] : [], }; } 

validateCart is plain JavaScript shared with the app server, so the admin preview and the Function apply exactly the same rules. For each uniform line it asks:

  • Does the logged-in customer have a verified member whose organisation is in the product's orgs list? (The _zs_member hint only picks which member; it can't add one.)
  • Is ordering open today for that organisation?
  • Is the per-member quantity limit respected?
  • If the organisation's kit rule is "block", are the required kit items in the cart?

Products without the orgs metafield are ordinary retail products and pass straight through, so the same store can keep selling to the public.

Why CART_INTERACTION returns nothing

Validation Functions run while the shopper edits the cart too. If you return errors there, people can't even change a quantity to fix the problem. We only add errors at checkout steps, with a message that names the item and says what to do, not a generic failure.

Discounts and delivery follow the same pattern

The same "metafield is truth, attribute is a hint" idea runs through the other two Functions in the app:

  • Discount Function (cart.lines.discounts.generate.run): organisation prices and the sibling discount are applied only when the customer's verified members qualify.
  • Delivery customization (cart.delivery-options.transform.run): the "deliver to school" rate is hidden from everyone who isn't a verified member of that school.

Takeaways

  • Theme-level hiding is UX. Checkout enforcement needs a Function.
  • Anything the browser writes (attributes, properties, cart notes) is a hint. Re-check it against app-owned metafields.
  • Share the rule code between server and Function so the two never drift.
  • Don't block CART_INTERACTION.

If you sell uniforms, team kit or staff workwear on Shopify, the merchant-side guides are here:

The app itself is ZS Uniform Portal on the Shopify App Store.