New Conditional Logic Class
Create a new class extend from:
YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic
<?php
namespace YayMailAddonConditionalLogic\ConditionalLogics;
use YayMailAddonConditionalLogic\SingletonTrait;
use YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic;
/**
* New Conditional Logic
*/
class NewConditionalLogic extends YayMailAddonConditionalLogic\Abstracts\BaseConditionalLogic {
private static $instance;
public static function instance() {
if ( null === static::$instance ) {
static::$instance = new static();
}
return static::$instance;
}
protected function __construct() {
parent::__construct(
'new_logic', // Key of conditional logic.
__( 'Conditional logic title', 'yaymail' ),
'single_select', // Type of conditional logic.
);
}
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'];
// use value check and return value
... TODO
return true || false;
}
}
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
number | text | single_select | multiple_select
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.
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
.
Last updated
Was this helpful?