# New Conditional Logic Class

1. **Create a new class extend from:** `YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic`

```php
<?php

use YayMailAddonConditionalLogic\SingletonTrait;
use YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic;

/**
 * New Conditional Logic
 */
class NewConditionalLogic extends YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic {
    use SingletonTrait;

    protected function __construct() {
        parent::__construct(
            'new_logic', // Unique key.
            __( 'Conditional logic title', 'yaymail' ), // Title in UI
            'single_select'
        );
    }

    public function get_options() {
        $options = [
            [
                'label' => 'Option 1',
                'value' => 'option_1',
            ],
            [
                'label' => 'Option 2',
                'value' => 'option_2',
            ]
        ];
        return $options;
    }
    
    public function check_logic( $args ) {
        // If this function return true -> Conditional logic is true then the element containing this logic will be displayed when sending mail.
        $condition                 = $args['condition'];
        $order                     = $args['order'];
        $condition_value           = $condition['value'];

        return true;
    }
}

```

2. **Construct function**

You need to get params for the parent construct ($logic\_key, $title,  $value\_type)

* **Logic key (string):** This is a unique identifier for the conditional logic
* **Title (string):** Short text describing the meaning of the conditional logic
* **Value type:** This variable will contain one of the following values&#x20;

  ```
  number | text | single_select | multiple_select
  ```

3. **Get Options function**

This function retrieves the options value for the conditional logic. It returns an array where each item has a label and a value.\
\
If the value type is text or number, you don’t need to write this function.

4. **Check logic function**

This function runs when the email is rendered. The template will be displayed if this function returns `true`. You can retrieve some input values to process, including: `order`, `condition`.


---

# 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://docs.yaycommerce.com/yaymail/addons/conditional-logic/new-conditional-logic-class.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.
