Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  • Examples
  • Direct dynamic value
  • Dynamic value with operator
  1. Conditions

Dynamic values

How to leverage dynamic values for a rule's conditions.

PreviousNestedNextActions

Last updated 2 months ago

The value key of a condition can be dynamic. This is extremely useful when the value to be compared with the field value isn't known in advance or is based on the value of another field.

To leverage dynamic values for a rule's conditions you need to use the double curly brackets notation {{<reference_field>}} where <reference_field> is the resource's field (expressed in dot notation) that will be used as a variable to calculate the value. Some basic operators that can be applied to the reference field are also provided (as shown in the examples below):

Operator
Field type
Description
Example value

min

Number

The smallest of the reference field values is used as the condition's value.

"{{min(order.line_items.shipment.available_shipping_methods.price_amount_cents)}}"

max

Number

The biggest of the reference field values is used as the condition's value.

"{{max(order.line_items.compare_at_amount_cents)}}"

avg

Number

The average of the reference field values is used as the condition's value.

"{{avg(order.line_items.sku.inventory.levels.quantity))}}"

The reference field type must be consistent with the used against the field and value. Given the currently available functions, if you want to add one of the operators above, the reference field type must be numeric.

Examples

Direct dynamic value

The following condition uses a dynamic value to check if an order's line items have the same unit amount and compare-at amount (i.e. the actual selling price is equal to the full price displayed to the customer with a strikethrough — that is to say, the items is not in sale):

"conditions": [
  {
    "field": "order.line_items.unit_amount_cents",
    "matcher": "eq",
    "value": "{{order.line_items.compare_at_amount_cents}}"
  }
]

Dynamic value with operator

The following condition uses a dynamic value with the min operator to target the shipment line items associated with the cheapest shipping method among the ones available for an order's shipments:

"conditions": [
  {
    "field": "order.line_items.shipment.cost_amount_cents",
    "matcher": "eq",
    "value": "{{min(order.line_items.shipment.available_shipping_methods.price_amount_cents)}}"
  }
]
matcher