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
- A store. E-commerce appears under global once your project has a store. See How to activate your online store.
- Stock tracking, for stock labels. The
stockfield is kept up to date while Stock Management is on. See How to track stock and get low-stock alerts. - Role. You need a role that can edit the project, for example Designer.
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
- On the cart page, select the banner, for example a text reading "Spend more for free delivery".
- In the right panel → Visual tab, turn on the Conditional Rendering switch.
- Click Bind, then Dynamic Properties Assignment Panel.
- In the Select Dynamic Property panel, open global, then E-commerce, then Cart. Click
shippingIsFree, then click Bind property. - Keep
=in the Operand list. In the value list, pickfalse.
2. Show the amount that is missing
- Select the text inside the banner and click the plug icon next to its content.
- 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:
| Field | What it holds | Typical rule |
|---|---|---|
itemCount | How many units are in the cart | = 0 shows "Your cart is empty"; > 0 shows the Checkout button |
total, totalWithShipping | The goods total, with the currency symbol, with and without delivery | shown in a text, not in a rule |
shippingIsFree | true while delivery costs nothing | = false shows the free-delivery banner |
freeDeliveryRemaining, freeDeliveryProgress | What is still missing for free delivery, and the progress as a percentage | bound to a text or a progress bar |
voucherApplied, voucherCode | true once a voucher is applied, and its code | voucherApplied = true shows the discount row |
giftCardApplied, giftCardLast4 | true once a gift card is applied, and its last four digits | = true shows the gift card row |
shippingStatus | ok, pending, unavailable or no-rate for the chosen address | = unavailable shows "We don't deliver there yet" |
codAvailable | true while payment on delivery is allowed for the cart | = false hides the cash option |
isDigitalOnly, hasRecurringLines | true for a cart of downloads only, or with a subscription | isDigitalOnly = true hides the address fields |
items | The lines in the cart, as a list | is_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.
- Select the label inside the product card.
- Turn on Conditional Rendering, click Bind → Dynamic Properties Assignment Panel, and pick the product's
stockfield, listed under the list's item (for example product → stock). - Choose
<=in the Operand list and type3in the value box. - Click + condition, keep and, and on the new row choose
>and type0.
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.
totalcarries the currency symbol. For a numeric comparison userawTotal,rawSubtotalorrawShipping, 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.