> For the complete documentation index, see [llms.txt](https://help.dollarlabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/discount-engine-v1/flags/if-x-then-do-y.md).

# 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.
