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
  • Rules breakdown
  • Resource payload analysis
  • Result check
  • Conclusion
  1. Use cases
  2. Promotions

Discount all the SKU in an order based on the customer email domain

Rule breakdown, resource payload analysis, and outcomes explanation

This rule applies a discount to all the products present in an order if the customer's email belongs to one of two provided domains. The email address of the customer who's placing the order is checked and a percentage discount is applied to all the line items associated with an SKU if the conditions are met.

The example below is based on the following reference JSONs. Once the rules are evaluated against the resource payload, the outcomes show if and how the conditions are matched and the related actions applied.

{
  "rules": [
    {
      "name": "Customer email domain mybrand.com / example.com",
      "conditions_logic": "or",
      "conditions": [
        {
          "field": "order.customer_email",
          "matcher": "matches",
          "value": ".*@mybrand.com"
        },
        {
          "field": "order.customer_email",
          "matcher": "matches",
          "value": ".*@example.com"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items.sku",
          "value": 0.15
        }
      ]
    }
  ]
} 
{
  "order": {
    "customer_email": "john.doe@mybrand.com",
    "id": "oKkhYLlzgE",
    "line_items": [
      {
        "quantity": 1,
        "id": "gnYtPpKLeG"
      },
      {
        "quantity": 7,
        "id": "wLGtgmdLjJ",
        "sku": {
          "id": "ZXxPSkbpNP"
        }
      },
      {
        "quantity": 1,
        "id": "zbZtmarXKR1",
        "sku": {
          "id": "WVyPSgRwxd"
        }
      },
      {
        "quantity": 1,
        "id": "zbZtmarXKR2",
        "sku": {
          "id": "WVyPSgRwxZ"
        }
      },
      {
        "quantity": 1,
        "id": "aoMtJlQlxD",
        "sku": {
          "id": "WKjRSMmlxe"
        }
      }
    ]
  }
}
[
  {
    "id": "2a56c419-7877-419a-8890-84cd634ccb8b",
    "name": "Customer email domain mybrand.com / example.com",
    "priority": 0,
    "match": true,
    "conditions_logic": "or",
    "conditions": [
      {
        "field": "order.customer_email",
        "matcher": "matches",
        "value": ".*@mybrand.com",
        "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
        "match": true,
        "matches": [
          {
            "order": "oKkhYLlzgE",
            "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f"
          }
        ],
        "scope": "any"
      },
      {
        "field": "order.customer_email",
        "matcher": "matches",
        "value": ".*@example.com",
        "scope": "any",
        "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
        "match": false,
        "matches": [

        ]
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "action_type": "percentage",
            "resource_type": "line_items",
            "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
            "quantity": 7,
            "id": "wLGtgmdLjJ",
            "value": 0.15
          },
          {
            "action_type": "percentage",
            "resource_type": "line_items",
            "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
            "quantity": 1,
            "id": "zbZtmarXKR1",
            "value": 0.15
          },
          {
            "action_type": "percentage",
            "resource_type": "line_items",
            "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
            "quantity": 1,
            "id": "zbZtmarXKR2",
            "value": 0.15
          },
          {
            "action_type": "percentage",
            "resource_type": "line_items",
            "group": "79b64b07-e8ec-4a2a-b49a-92c7cda1249f",
            "quantity": 1,
            "id": "aoMtJlQlxD",
            "value": 0.15
          }
        ]
      }
    ]
  }
]

Rules breakdown

The desired results can be achieved with a single rule.

Conditions

The rule contains two conditions:

  1. The first condition checks if the email address associated with the order ends with @mybrand.com.

  2. The second condition checks if the email address associated with the order ends with @example.com.

The conditions_logic is set to or, meaning that if either condition is met, the rule will be applied.

Actions

The only action in the rule is triggered if any of the conditions are met and applies a 15% discount to all the line items associated with an SKU.

Resource payload analysis

The payload contains an order placed by a customer whose email address is john.doe@mybrand.com. This matches the first condition specified in the rule, confirming that the order qualifies for the discount. The order contains 5 line items, 4 of which (wLGtgmdLjJ, zbZtmarXKR1, zbZtmarXKR2, and aoMtJlQlxD) are associated with an SKU (ZXxPSkbpNP, WVyPSgRwxd, WVyPSgRwxZ, and WKjRSMmlxe respectively).

Result check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order's customer email satisfies one of the two conditions the order ID is listed within the related matches array. This doesn't happen for the second condition, but being the conditions evaluated according to an or logic the rule matches successfully anyway (match is true). The action is applied to the line items associated with an SKU with the decimal value of 0.15 corresponding to the specified percentage discount.

Conclusion

Once checked that the order's customer email address belongs to the desired domain, the rule successfully identifies the line items eligible for the discount and applies a 15% discount to each qualifying line item.

PreviousDiscount all the SKU in an order based on the shipping countryNextPrice lists

Last updated 2 months ago