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
  • Outcomes check
  • Conclusion
  1. Use cases
  2. Promotions

Offer a specific shipping method for free in a specific country

Rule breakdown, resource payload analysis, and outcomes explanation

This rule discounts a shipping method for all the orders in a given country. The country code of the order is checked and, if it matches the desired country, a 100% percentage discount is applied to the shipment line items (if any) whose shipment has a shipping method that matches the provided ID.

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": "Free express shipment for US orders",
      "conditions": [
        {
          "field": "order.country_code",
          "matcher": "eq",
          "value": "US"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items.shipment.shipping_method.id",
          "value": 1.0,
          "identifier": "bEegQFyxNw"
        }
      ]
    }
  ]
} 
{
  "order": {
    "id": "wJZYhBXaWL",
    "country_code": "US",
    "line_items": [
      {
        "id": "fdgXdRsaKo",
        "quantity": 1,
        "unit_amount_cents": 14500
      },
      {
        "id": "vRrYtpaaKv",
        "quantity": 1,
        "unit_amount_cents": 1200,
        "shipment": {
          "id": "eNdLCKWxly",
          "shipping_method": {
            "id": "bEegQFyxNw"
          }
        }
      },
      {
        "id": "vgnYtBqqJk",
        "quantity": 2,
        "unit_amount_cents": 9500
      },
      {
        "id": "ybmetWzzYN",
        "quantity": 1,
        "unit_amount_cents": 4000,
        "shipment": {
          "id": "YVNXCjjWdY",
          "shipping_method": {
            "id": "DEqjzFGqOn"
          }
        }
      }
    ]
  }
}
[
  {
    "id": "4417633c-8759-438d-823b-a6708ac47192",
    "name": "Free express shipment for US orders",
    "priority": 0,
    "match": true,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.country_code",
        "matcher": "eq",
        "value": "US",
        "group": "1d731a42-864b-459b-ac01-f6a4b293e1a4",
        "match": true,
        "matches": [
          {
            "order": "wJZYhBXaWL",
            "group": "1d731a42-864b-459b-ac01-f6a4b293e1a4"
          }
        ],
        "scope": "any"
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "resource_type": "shipping_methods",
            "id": "bEegQFyxNw",
            "group": null,
            "quantity": 1,
            "value": 1.0,
            "action_type": "percentage"
          }
        ]
      }
    ]
  }
]

Rules breakdown

The desired results can be achieved with a single rule.

Conditions

The only condition in the rule checks if the order's country_code is equal to US. This means the rule will only apply if the order is placed from the United States.

Actions

The only action in the rule applies a 100% percentage discount to the order's shipment line items that are associated with the shipping method that should be free of charge. The shipment line item eligible for the discount is detected via a selector on the ID of the shipping method (bEegQFyxNw).

Resource payload analysis

The provided payload contains an order placed from the US that has 4 line items: 2 products whose delivery is split into 2 shipments. For one of the shipments (eNdLCKWxly, associated with the line item vRrYtpaaKv) the shipping method that should be discounted has been selected.

Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order is placed from the US, the rule matches successfully (match is true) and the order ID is listed in the matches array. The action is applied to the identified resource (i.e. the shipping method with ID bEegQFyxNw) with the decimal value of 1.0 corresponding to a full percentage discount.

Conclusion

The rule matches the provided payload. Consequently, the shipment identified as eligible for the discount will have its shipping cost zeroed.

PreviousDiscount an order based on promo item and total number of itemsNextDiscount items with large stock availability

Last updated 2 months ago