| @@ -117,11 +117,17 @@ | ||
| 117 | 117 | * @SuppressWarnings(PHPMD.NPathComplexity) |
| 118 | 118 | * @param array $conditions Conditions data. |
| 119 | 119 | */ |
| 120 | 120 | function sellkit_conditions_validation( $conditions ) { |
| 121 | - $is_valid = true; | |
| 122 | - $condition_type = ! empty( $conditions[1]['type'] ) ? $conditions[1]['type'] : 'and'; | |
| 121 | + $is_valid = true; | |
| 123 | 122 | |
| 123 | + if ( empty( $conditions ) ) { | |
| 124 | + return true; | |
| 125 | + } | |
| 126 | + | |
| 127 | + $first_condition = reset( $conditions ); | |
| 128 | + $condition_type = ! empty( $first_condition['type'] ) ? $first_condition['type'] : 'and'; | |
| 129 | + | |
| 124 | 130 | if ( 'or' === $condition_type ) { |
| 125 | 131 | $is_valid = false; |
| 126 | 132 | } |
| 127 | 133 | |
| @@ -150,5 +156,21 @@ | ||
| 150 | 156 | return true; |
| 151 | 157 | } |
| 152 | 158 | |
| 153 | 159 | return false; |
| 160 | +} | |
| 161 | + | |
| 162 | +if ( ! function_exists( 'array_key_last' ) ) { | |
| 163 | + /** | |
| 164 | + * Adds support for array_key_last function for lower php than 7.3.0 & WP lower than 5.9.0. | |
| 165 | + * | |
| 166 | + * @param array $array array. | |
| 167 | + */ | |
| 168 | + function array_key_last( $array ) { | |
| 169 | + if ( empty( $array ) ) { | |
| 170 | + return null; | |
| 171 | + } | |
| 172 | + | |
| 173 | + end( $array ); | |
| 174 | + return key( $array ); | |
| 175 | + } | |
| 154 | 176 | } |