> ## Documentation Index
> Fetch the complete documentation index at: https://aiodapp.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Rule Builder

> Advanced Rules template for building flexible AIOD discounts with custom conditions and item targets.

Use **Custom Rule Builder** when a merchant needs more control than the standard AIOD template forms provide.

This template is inside the **Advanced Rules** parent template. In Shopify admin, open **Apps** > **AIOD Discount & Gift** > **Discount Templates**, click **Create** on **Advanced Rules**, then choose **Custom Rule Builder** on the **Select type** page.

The parent card says: "Create custom logic and complex promotions." The parent example shown in AIOD is "Get 20% off shirts, free gift and free shipping."

The inner template card says: "Build complex, flexible discounts with custom rules and 15+ triggers!"

## When to use this template

Use this template for:

* Custom discount logic that does not fit a simpler template.
* Discounts based on cart subtotal, order weight, cart quantity, products, collections, variants, metafields, purchase type, country, customer tags, past orders, login status, or customer email.
* Discounts that need AND or OR condition groups.
* Discounts that should apply to all items, eligible condition items, specific items, or all items except selected items.
* Product-level or order-level discount behavior.

Use **Reject Discount Codes** instead when the goal is to block specific discount codes when rules are met.

## Related Advanced Rules templates

The **Advanced Rules** parent opens two inner templates:

| Inner template            | Use it for                                                                     |
| ------------------------- | ------------------------------------------------------------------------------ |
| **Custom Rule Builder**   | Build a custom discount with flexible conditions, targets, values, and limits. |
| **Reject Discount Codes** | Reject specific discount codes when matching conditions are met.               |

## Top-level controls

The form includes:

* **Discount ID (For your reference)** with placeholder `eg: GET 20% OFF`.
* **Discount Method**.
* **When to apply discount**.
* **Select items to apply discount on**.
* **Where to apply the discount**.
* **Discount Rules & Limits**.
* **Sales channel**.
* **Customer Segment**.
* **This discount can be combined with**.
* **Active Dates**.
* **Advanced Settings (Optional)**.
* [**Show Discounted Price Crossout**](/docs/app/common-template-settings#show-discounted-price-crossout).

### Status mode

The top-right status dropdown controls who can use or see the discount.

| Status       | Meaning                                                                                |
| ------------ | -------------------------------------------------------------------------------------- |
| **Live**     | The discount is active for customers.                                                  |
| **Testing**  | The discount is visible to the merchant for testing, but it is not live for customers. |
| **Deactive** | The discount is turned off.                                                            |

## Discount method

The **Discount Method** section supports:

* **Automatic discount**
* **Discount code**

For automatic discounts, AIOD shows:

* **Title**
* **Keep same as identifier**

AIOD says customers will see the title in cart and checkout.

## When to apply discount

The **When to apply discount** section controls the trigger conditions. The default is **Always**.

Click the condition button to choose a trigger.

| Category           | Trigger                          | AIOD description                                                |
| ------------------ | -------------------------------- | --------------------------------------------------------------- |
| General            | **Always**                       | This discount is always applied.                                |
| Cart/Order Details | **Cart Subtotal Amount**         | Applied based on the subtotal value of products in the cart.    |
| Cart/Order Details | **Order Weight**                 | Applied based on the total weight of products in the cart.      |
| Cart/Order Details | **Cart Quantity**                | Applied based on the number of items in cart.                   |
| Product Details    | **Product**                      | Applied based on specific products added to the cart.           |
| Product Details    | **Collection**                   | Applied based on specific collection items added to the cart.   |
| Product Details    | **Variant**                      | Applied based on specific variants added to the cart.           |
| Product Details    | **Variant Whose Metafield**      | Applied based on all variants whose metafield matches the rule. |
| Product Details    | **Purchase Type**                | Applied based on subscription or one-time purchase items.       |
| Shipping Address   | **Country**                      | Applied based on the entered shipping destination country.      |
| Customer Details   | **Customer Tags**                | Applied based on specific tags assigned to the customer.        |
| Customer Details   | **Number of past orders**        | Applied based on number of past orders placed by customer.      |
| Customer Details   | **Customer Should Be Logged In** | Applied only if the customer is logged in.                      |
| Customer Details   | **Customer Email**               | Applied based on the customer's email.                          |

### Product condition example

When **Product** is selected, AIOD shows:

* Operator dropdown with **matches any of**, **matches all of**, and **does not match any of**.
* **Select products** picker.
* Empty state: **No products selected**.
* **Minimum Quantity of ANY above selected products in cart**. The default shown is `1`.
* **Advanced Settings** for the condition.
* **AND condition**.
* **OR condition**.

Use **AND condition** and **OR condition** to combine multiple rule blocks.

### Condition advanced settings

For product-style conditions, click **Advanced Settings** inside the condition block to reveal:

| Setting                                                   | Behavior                                                                        |
| --------------------------------------------------------- | ------------------------------------------------------------------------------- |
| **Quantity scope**                                        | Controls how selected item quantities are counted.                              |
| **Across all selected items**                             | Counts total quantity across all selected items. This was selected by default.  |
| **Same variant**                                          | Requires one variant to individually meet the quantity requirement.             |
| **Same product**                                          | Allows variants of the same product to combine toward the quantity requirement. |
| **Purchase Type of each above selected items in cart**    | Choose **Any**, **One Time**, or **Subscription**.                              |
| **Minimum Cart Subtotal of above selected items in cart** | Sets a minimum subtotal for qualifying items. `0` means no minimum subtotal.    |
| **Maximum Cart Subtotal of above selected items in cart** | Sets a maximum subtotal for qualifying items. `0` means no maximum limit.       |

## Select items to apply discount on

The **Select items to apply discount on** section controls which items receive the discount.

Target options:

| Target option                                          |
| ------------------------------------------------------ |
| **Apply Discount to All**                              |
| **Apply Discount to Eligible Items (from condition)**  |
| **Apply Discount to Specific Collection**              |
| **Apply Discount to Specific Product**                 |
| **Apply Discount to Specific Variant**                 |
| **Apply Discount to Specific Variant whose Metafield** |
| **Apply Discount Excluding Collection**                |
| **Apply Discount Excluding Product**                   |
| **Apply Discount Excluding Variant**                   |

The default observed target was **Apply Discount to All**.

## Discount value

The **Discount Type** dropdown controls how AIOD interprets **Discount Value**.

Options:

* **Percentage**
* **Fixed Discount**
* **Fixed Final Price**

## Where to apply the discount

The **Where to apply the discount** section controls discount scope.

| Option            | Behavior                                                                     |
| ----------------- | ---------------------------------------------------------------------------- |
| **Product Level** | Applies the discount to individual line items. This was selected by default. |
| **Order Level**   | Applies the discount to the whole order total once at the end.               |

## Discount rules and limits

The **Discount Rules & Limits** section includes:

| Setting                                         | Observed behavior                                                                          |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------ |
| **Maximum Discount Amount**                     | Adds a maximum total discount amount.                                                      |
| **Limit Quantity of Discounted Items**          | Limits the number of discounted items.                                                     |
| **Apply discount on the LEAST expensive items** | Disabled in the observed default state.                                                    |
| **Combo Discount**                              | Disabled in the observed default state.                                                    |
| **Multiply based on condition**                 | Disabled in the observed default state. AIOD gives this example: buy 2 get 1, buy 4 get 2. |

## Sales channel

The **Sales channel** section controls where the discount applies.

Available channels:

* **Online store**
* **POS**

Both were checked by default in the observed form. When **POS** is enabled, **All locations** opens the location selector.

## Customer segment

The **Customer Segment** section restricts the discount to selected Shopify customer segments.

AIOD describes this section as: "This discount will be only applicable for customers in the selected segments."

### How should this discount combine with other discounts?

Read [**This discount can be combined with**](/docs/app/common-template-settings#this-discount-can-be-combined-with) for information about this.

## Active dates

The **Active Dates** section controls when the discount starts and ends.

Default fields:

* Start **Date**
* Start **Time**

Enable **Set end date** to reveal end date and time fields.

## Advanced settings

Click **Show** in **Advanced Settings (Optional)** to reveal:

| Setting                                                                                     | Behavior                                                                                       |
| ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| **Exclude already discounted items from discount (whose compare at price > selling price)** | Excludes already discounted items based on compare-at price.                                   |
| **Purchase Type Eligibility**                                                               | Choose **One-time purchase**, **Subscription**, or **Both**. **Both** was selected by default. |
| **Limit the number of subscription cycles the discount will apply to**                      | Limits recurring subscription discount cycles.                                                 |

## Show discounted price crossout

Read [**Show Discounted Price Crossout**](/docs/app/common-template-settings#show-discounted-price-crossout) for the shared storefront strikethrough pricing controls and placement steps.
