| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Contact_Segmentation\Conditions; |
| 4 |
|
| 5 |
use Sellkit\Contact_Segmentation\Conditions\Condition_Base; |
| 6 |
use Sellkit\Contact_Segmentation\Operators; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || die(); |
| 9 |
|
| 10 |
/** |
| 11 |
* Class Billing City. |
| 12 |
* |
| 13 |
* @package Sellkit\Contact_Segmentation\Conditions |
| 14 |
* @since 1.1.0 |
| 15 |
*/ |
| 16 |
class Billing_City extends Condition_Base { |
| 17 |
|
| 18 |
/** |
| 19 |
* Condition name. |
| 20 |
* |
| 21 |
* @since 1.1.0 |
| 22 |
*/ |
| 23 |
public function get_name() { |
| 24 |
return 'billing-city'; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Condition title. |
| 29 |
* |
| 30 |
* @since 1.1.0 |
| 31 |
*/ |
| 32 |
public function get_title() { |
| 33 |
return esc_html__( 'Past Order Billing City', 'sellkit' ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Condition type. |
| 38 |
* |
| 39 |
* @since 1.1.0 |
| 40 |
*/ |
| 41 |
public function get_type() { |
| 42 |
return self::SELLKIT_TEXT_CONDITION_VALUE; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* It is pro feature or not. |
| 47 |
* |
| 48 |
* @since 1.1.0 |
| 49 |
*/ |
| 50 |
public function is_pro() { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* If it's valid or not. |
| 56 |
* |
| 57 |
* @since 1.1.0 |
| 58 |
* @param array $condition_value Condition value. |
| 59 |
* @param string $operator_name Operator name. |
| 60 |
* @return bool |
| 61 |
*/ |
| 62 |
public function is_valid( $condition_value, $operator_name ) { |
| 63 |
$operator = Operators::$operators[ $operator_name ]; |
| 64 |
$is_not_validation = []; |
| 65 |
|
| 66 |
foreach ( $this->data['billing_city'] as $city ) { |
| 67 |
$is_valid = $operator->is_valid( $city, $condition_value ); |
| 68 |
|
| 69 |
if ( 'is-not' === $operator_name ) { |
| 70 |
$is_not_validation[] = $is_valid; |
| 71 |
} |
| 72 |
|
| 73 |
if ( $is_valid && 'is-not' !== $operator_name ) { |
| 74 |
return true; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if ( |
| 79 |
'is-not' === $operator_name && |
| 80 |
1 === count( array_unique( $is_not_validation ) ) && |
| 81 |
true === $is_not_validation[0] |
| 82 |
) { |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
return false; |
| 87 |
} |
| 88 |
} |
| 89 |
|