For the complete documentation index, see llms.txt. This page is also available as Markdown.

Custom liquid

Write your own Liquid snippet to decide access, with customer, cart, product, and storefront variables.

The Custom liquid rule lets you write your own Liquid code snippet to decide whether a visitor gets access. It's the most flexible rule in the app — anything you can express as a Liquid condition against the customer, their cart, the current product or collection, or the storefront itself, you can use to gate content — but it's also the one rule where a mistake in the snippet has real consequences, covered below.

How it works

Custom liquid is an action-based rule, so it doesn't have an If/Unless toggle. Instead, the app runs your snippet for each visitor and reads its final result. The result must be exactly true or false (surrounding whitespace is ignored): true passes the rule and false fails it. Other output, such as true - customer is eligible, is not a valid result. Your snippet has access to the same kind of data a Shopify theme would have about the current visitor and page.

Adding the rule

Open the lock, click the Unlock rules tab, and choose Custom liquid from the Condition type dropdown.

The Condition type dropdown with Custom liquid selected
Select Custom liquid from the Condition type dropdown on the Unlock rules tab.

The code editor

The rule's condition type opens a dedicated Liquid code editor with syntax highlighting, autocomplete, and real-time syntax validation — errors in your Liquid are flagged directly in the editor as you type, before you even save.

Custom liquid code editor with a snippet and a syntax validation indicator
Writing and validating a Liquid snippet in the code editor.

Available variables

The editor exposes a library of variables you can insert, grouped by what they describe:

Group
Variables

Customer

customer, customer.tags, customer.orders_count, customer.total_spent, customer.b2b?

Cart

cart.item_count, cart.total_price, cart.items

Product & collection

product.tags, product.vendor, product.metafields, collection.handle

Storefront

request.path, request.page_type, localization.country.iso_code, localization.language.iso_code

Variables and templates panel showing the available Liquid variables grouped by category
Browsing the available variables from the Variables and templates panel.

Starter templates

If you'd rather start from something working than an empty editor, the same panel includes ready-made templates you can drop in and adjust, including a logged-in customer check, a customer-tag check, a cart quantity or cart total minimum, a product-tag check, a visitor-country check, a URL-path check, and a ready-made Shopify B2B customer template that checks customer.b2b? directly.

Example templates panel with a list of ready-made Liquid snippets to use as a starting point
Choosing a starter template, including the ready-made Shopify B2B template.

Steps to manage

  1. Open the lock you want to protect and click the Unlock rules tab.

  2. Add an access rule and set the condition type to Custom liquid.

  3. Write your snippet directly in the editor, or open Variables and templates to copy a variable or start from one of the ready-made templates.

  4. Make sure your snippet's final output is exactly true for visitors who should pass and exactly false for everyone else. Do not add explanatory text, HTML, or other output around the value. The editor flags basic syntax problems, but you still need to confirm the logic matches what you intend.

  5. Optionally set a per-rule Redirect URL, used only if this specific rule denies the visitor.

  6. Save the lock.

Fail-open behavior

Example: Allow signed-in customers with a VIP tag

Suppose a private page should only be available to signed-in customers whose account has the vip tag.

  1. Select the VIP collection preview page as the content to protect.

The Lock setup tab with Specific Page as the content type and the VIP collection preview page listed under Restricted pages.
Pick the page you want to keep for VIP customers.
  1. Add Custom liquid and replace the starter snippet with:

The editor confirms Liquid syntax is valid underneath as you type.

The Custom liquid condition with the VIP tag snippet in the Liquid condition editor and the Liquid syntax is valid confirmation below it.
The editor highlights the Liquid and validates the syntax before you save.
  1. Leave the rule's Redirect URL empty.

  2. Set the Access denied message to:

This page is available to VIP customers only.

The Messages card with the Access denied message set to the VIP-customers-only wording, and the Preview panel rendering it.
Custom liquid has a single message field, shown to everyone the snippet rejects.
  1. Click Save.

Result on the storefront

The snippet outputs exactly true for a signed-in customer with the vip tag, so the page opens normally. It outputs exactly false for guests and customers without that tag, so they see the message above. Do not add text before or after true or false in the snippet output.

The VIP collection preview page displaying the configured VIP-customers-only message.
When the Liquid snippet returns false, the visitor sees the Access denied message from this example.

Last updated

Was this helpful?