Conditions

How to show or hide elements by cart and store values

How to show or hide elements by cart and store values

In a TeleportHQ store, a condition can read the visitor's cart and the store's settings. The Select Dynamic Property panel lists them under global → E-commerce: Cart holds itemCount, total, shippingIsFree, freeDeliveryRemaining, voucherApplied and more, Settings holds the store's own settings, and hasPaymentProviders says whether a payment method is connected. A free-delivery banner gets the rule shippingIsFree = false, an empty-cart message gets itemCount = 0, and a "Only 3 left" label reads the product's own stock field.

Before you start

Steps

The example adds a banner to the cart page that shows while delivery isn't free yet.

1. Put the rule on the banner

  1. On the cart page, select the banner, for example a text reading "Spend more for free delivery".
  2. In the right panel → Visual tab, turn on the Conditional Rendering switch.
  3. Click Bind, then Dynamic Properties Assignment Panel.
  4. In the Select Dynamic Property panel, open global, then E-commerce, then Cart. Click shippingIsFree, then click Bind property.
  5. Keep = in the Operand list. In the value list, pick false.

2. Show the amount that is missing

  1. Select the text inside the banner and click the plug icon next to its content.
  2. Choose Bind value, then Dynamic Properties Assignment Panel, and pick global → E-commerce → Cart → freeDeliveryRemaining.

The banner now reads, for example, "Spend 12.50 more for free delivery", and is gone once the cart reaches the threshold set under Free delivery in your store settings. See How to set delivery fees.

3. See it with items in the cart

The canvas reads the cart simulator, a cart that exists only in the editor. Click the Cart button above the canvas: a panel opens with Your cart is empty, an Add Products list, a Ship to choice and Clear All. Add a product from the list, and every condition on the cart updates on the canvas. With the simulator empty, itemCount reads 0, the money fields read 0.00, and shippingIsFree reads true only when free delivery is on with a threshold of 0 or delivery is off.

Values you can read

Under global → E-commerce → Cart:

FieldWhat it holdsTypical rule
itemCountHow many units are in the cart= 0 shows "Your cart is empty"; > 0 shows the Checkout button
total, totalWithShippingThe goods total, with the currency symbol, with and without deliveryshown in a text, not in a rule
shippingIsFreetrue while delivery costs nothing= false shows the free-delivery banner
freeDeliveryRemaining, freeDeliveryProgressWhat is still missing for free delivery, and the progress as a percentagebound to a text or a progress bar
voucherApplied, voucherCodetrue once a voucher is applied, and its codevoucherApplied = true shows the discount row
giftCardApplied, giftCardLast4true once a gift card is applied, and its last four digits= true shows the gift card row
shippingStatusok, pending, unavailable or no-rate for the chosen address= unavailable shows "We don't deliver there yet"
codAvailabletrue while payment on delivery is allowed for the cart= false hides the cash option
isDigitalOnly, hasRecurringLinestrue for a cart of downloads only, or with a subscriptionisDigitalOnly = true hides the address fields
itemsThe lines in the cart, as a listis_empty or is_not_empty

voucherApplied, giftCardApplied, codAvailable, isDigitalOnly and hasRecurringLines are kept as the words true and false: type them in the value box as text.

Under global → E-commerce → Settings, the store's settings, for example freeDeliveryEnabled, storePickupEnabled, guestCheckout and stockManagement. For these, the value box offers true and false. hasPaymentProviders = false shows a "Checkout opens soon" note while no payment method is connected.

A "Only 3 left" label on a product

A product's stock is not a cart value: it comes from the product itself, in a product card or on the product page.

  1. Select the label inside the product card.
  2. Turn on Conditional Rendering, click Bind → Dynamic Properties Assignment Panel, and pick the product's stock field, listed under the list's item (for example product → stock).
  3. Choose <= in the Operand list and type 3 in the value box.
  4. Click + condition, keep and, and on the new row choose > and type 0.

The label shows while the stock is between 1 and 3. TeleportHQ can also add this for you: Social proof badges in Growth Settings shows "Only 3 left" and "12 bought this week" on product pages. See How to set up Growth Settings.

Check that it worked

Open the cart simulator and add or remove products: the banner, the empty-cart message and the checkout button follow. Then publish, add a product to the cart on your live store and watch the same elements.

Troubleshooting

E-commerce isn't under global The project has no store. Turn it on first.

The banner shows on the canvas with a wrong amount The cart simulator is empty or holds other products. Open it with the Cart button and change its contents. It never changes a real visitor's cart.

A rule on voucherApplied never matches The field holds the word true or false. Type true in the value box, as text, with no quotes.

The stock label shows on every product The rule reads a cart value or a fixed number instead of the product's stock field. Click the bound value in the Conditional Rendering section and pick stock under the list's item.

Good to know

  • The checkout pages TeleportHQ builds use these rules. The voucher row, the gift card row, the delivery options and the "Choose your discount" list are shown and hidden with conditions on the same cart fields. Select them to see how they're built.
  • Money fields are text. total carries the currency symbol. For a numeric comparison use rawTotal, rawSubtotal or rawShipping, two-decimal numbers without a symbol.
  • Downloaded code. Cart conditions need the Next.js download, which runs the store. See How to download your site as code.
Share

Related Articles

What are conditions?

In TeleportHQ, a condition is a rule on one element, such as "show this badge while stock equals 0" or "show this menu while isMenuOpen is true"; you set it in the Conditional Rendering section of the right panel, it can read a state, a component setting, a list item, the signed-in visitor, the cart or a URL parameter, and on the published site the element is left out of the page while the rule is false.

How to show or hide elements based on a condition

In TeleportHQ, you show an element only when a condition is true, such as "stock equals 0" or "the menu is open", by selecting it, turning on the Conditional Rendering switch near the top of the right panel and building the condition from a value, an operator and a comparison value; it works in every project, website or web app.

How to show or hide elements by state

In TeleportHQ, create a state in Page settings → State (for example isMenuOpen, true or false), give the element a Conditional Rendering rule such as isMenuOpen = true, and change the state from a button's Events tab with Change State; it works on websites and web apps and needs no web app features.

How to show or hide elements for signed-in visitors

In TeleportHQ, a web app with sign-up and login offers two built-in values under global in the Select Dynamic Property panel, User is logged in (true or false) and Current User (name, email, role and more); a condition such as User is logged in = true shows a Sign out button, = false a Sign in link, and Current User → role = admin a button for one role only.

How to show or hide elements by URL parameter

In TeleportHQ, declare the parameter on the page under Page Params in Page settings (a Key name such as category and a Default value), then give the element a Conditional Rendering rule on the URL Param, such as category = cakes; a visitor who opens /products?category=cakes sees that element, and the page without the parameter uses the default.

How to use conditions in components and variants

In TeleportHQ, a condition inside a component can read one of the component's settings (props): click Bind in the Conditional Rendering section and choose Create Conditional Prop, and every copy of the component then turns that part on or off, or picks a look, under Component Properties → Conditional; one card component gets several looks without being duplicated.

Condition recipes

Six ready-to-copy TeleportHQ conditions, each with the state or value to create and the rule to set: an accordion and tabs built from a state (or the Accordion and Tabs elements that do it for you), an image slider with a slide state, a "no results" message with is_empty, a language-specific block on Current Language → short, and a fallback for a missing field.