# If X, then do Y

With the `When-Then` flag, you can create more complex rules by separating the discount logic into two parts:

* **Customer Buys (When):** This part defines the criteria that must be met in the customer's cart for the discount to be eligible, and start checking the \`then\` conditions. It's the evaluation criteria.
* **Customer Gets (Then):** This part defines which items in cart receive the discount based on the rules setup in "Customer Buys" section. It's the application criteria.

{% hint style="info" %}
**Example:** Let's say you want to offer a 100% discount on Product A when a customer buys 5 of Product B.
{% endhint %}

***

### Video walkthrough

{% embed url="<https://drive.google.com/file/d/1hn5CULAj9nSkSn_0-kVWuqTGbVFIrZYg/view?usp=sharing>" %}

***

### Set up a When-Then discount in the Rule builder UI

1. Find the `Settings` icon next to your discount&#x20;
2. In the popup window that opens, select When-Then and click done

<figure><img src="/files/9EqSfx6k7YOjhS11FvhV" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/YUQk2x9aprRCv0ADw69f" alt=""><figcaption><p>Here's how the example mentioned below is configured using the When-Then logic</p></figcaption></figure>

***

### Let's understand with an example

* **Customer Buys (When):**
  * Condition 1: The customer must buy more than 5 units of Product B (Line Quantity of Product B > 5).
* **Customer Gets (Then):**
  * Condition 1: The customer gets a 100% discount on Product A (Product IDs = Product A & When Quantity = 1).

### **Let's Test Our Logic on a User's Cart:**

A customer adds the following items to their cart:

* Item 1: Product A, Price = $20, Quantity = 1
* Item 2: Product B, Price = $10, Quantity = 6
* Item 3: Product C, Price = $15, Quantity = 2

**Logic behind the discount application:**

1. Product B is present in cart (Item 2) and has a qty of 6, thereby satisfying when condition.
2. Then \`then\` condition is checked for all items, but only (Item 1) meet this criteria and hence gets the 100% discount applied on it.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.dollarlabs.io/dollarlabs-ultimate-discounts/discount-engine-v1/flags/if-x-then-do-y.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
