PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.11.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.11.1
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / classes / class-wpfnl-condition-checker.php

class-wpfnl-condition-checker.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.11.1, at includes/core/classes/class-wpfnl-condition-checker.php

295 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Condition checker
4 *
5 * @package
6 */
7 namespace WPFunnels\Conditions;
8
9 use WPFunnels\Traits\SingletonTrait;
10 use WPFunnels\Wpfnl_functions;
11 class Wpfnl_Condition_Checker {
12
13 use SingletonTrait;
14
15
16 /**
17 * Conditional node logic check
18 *
19 * @param $funnel_id
20 * @param $order
21 * @param $step_id
22 * @param $current_page_id
23 * @param $checker
24 *
25 * @return bool
26 *
27 * @since 2.0.2
28 */
29 public function check_condition( $funnel_id, $order = '', $step_id, $current_page_id = '', $checker = 'accept' )
30 {
31 if( !$step_id ){
32 return false;
33 }
34
35 $group_conditions = Wpfnl_functions::get_conditions( $step_id );
36 if( !is_array($group_conditions) ){
37 return false;
38 }
39
40 // Loop through group condition.
41 foreach ($group_conditions as $group) {
42
43 if (empty($group)) {
44 continue;
45 }
46
47 // Loop over rules and determine if all rules match.
48 foreach ($group as $rule) {
49 if (!$this->match_rule( $funnel_id ,$rule, $order, $current_page_id, $checker )) {
50 return false;
51 }
52 }
53 }
54 return true;
55 }
56
57
58 /**
59 * Check if rule is matched
60 *
61 * @param $rule
62 * @param $order
63 * @param $current_page_id
64 * @param $checker
65 *
66 * @return mixed
67 *
68 * @since 2.0.2
69 */
70 public function match_rule( $funnel_id , $rule, $order = '' , $current_page_id = '', $checker = 'accept' )
71 {
72
73 if ($rule['field'] == 'downsell') {
74 $rule['field'] = 'upsell';
75 }
76 $condition = $rule['field'];
77
78 if ( false !== strpos($rule['field'] , 'optin')){
79 $condition = 'optin';
80 }
81
82 $checker_function = $condition . '_condition_checker';
83
84 return self::$checker_function( $funnel_id ,$rule, $order, $current_page_id, $checker );
85 }
86
87
88 /**
89 * Optin condition checker for conditional step
90 *
91 * @param Integer $funnel_id
92 * @param Array $data
93 * @param Object $order
94 * @param Integer $current_page_id
95 * @param String $checker
96 *
97 * @return Boolean
98 *
99 * @since 2.5.7
100 */
101 public static function optin_condition_checker( $funnel_id, $rule, $data, $current_page_id, $checker = 'accept' ){
102
103 if( is_array($data) && isset($data['step_id']) ){
104 $step_id = str_replace('optin_','',$data['step_id'] );
105 $optin_steps = get_option('optin_data');
106 if( isset( $optin_steps['optin_data'] )){
107 $key = array_search($step_id, array_column($optin_steps['optin_data'], 'step_id'));
108 if( false !== $key ){
109 unset($optin_steps[$key]);
110 update_option('optin_data', $optin_steps );
111 return true;
112 }
113 }
114
115 }elseif( is_array($data) && !empty($data['cta']) ){
116 return false;
117 }
118
119 if( isset($rule['field']) ){
120 $step_id = str_replace('optin_','',$rule['field'] );
121 $optin_steps = get_option('optin_data');
122 if( isset( $optin_steps['optin_data'] )){
123 $key = array_search($step_id, array_column($optin_steps['optin_data'], 'step_id'));
124 if( false !== $key ){
125 unset($optin_steps[$key]);
126 update_option('optin_data', $optin_steps );
127 return true;
128 }
129 }
130 }
131
132 return false;
133 }
134
135
136 /**
137 * Order bump condition checker
138 *
139 * @param $data
140 * @param $order
141 * @param $current_page_id
142 *
143 * @return bool
144 */
145 public static function orderbump_condition_checker( $funnel_id, $data, $order, $current_page_id, $checker = 'accept' )
146 {
147
148 if ( Wpfnl_functions::is_wc_active() ) {
149 $order_bump_accepted = WC()->session->get('order_bump_accepted');
150
151 WC()->session->set('order_bump_accepted', null);
152 $cookie_name = 'wpfnl_order_bump';
153 $cookie = isset( $_COOKIE[$cookie_name] ) ? json_decode( wp_unslash( $_COOKIE[$cookie_name] ), true ) : array();
154
155 if( isset( $cookie['order_bump_accepted'] ) ){
156 $is_accepted = false;
157 if( ( $data['value'] == $cookie['order_bump_accepted'] ) || ( 'no' === $data['value'] && '' === $cookie['order_bump_accepted'] )){
158 $is_accepted = true;
159 }
160 ob_start();
161 if( isset( $_COOKIE[$cookie_name] ) ){
162 setcookie( $cookie_name, null, strtotime( '-1 days' ), '/', COOKIE_DOMAIN );
163 }
164 ob_end_flush();
165
166 return $is_accepted;
167 }else{
168 if( 'no' === $data['value'] ){
169 return true;
170 }
171 }
172 }
173
174 return false;
175 }
176
177
178 /**
179 * Cart total condition checker
180 *
181 * @param $data
182 * @param $order
183 * @param $current_page_id
184 *
185 * @return bool
186 */
187 public static function carttotal_condition_checker( $funnel_id, $data, $order, $current_page_id, $checker = 'accept' )
188 {
189 $cart_total = $order->get_total();
190
191 $checker = false;
192
193 if( !isset( $data['condition'], $data['value'] ) ){
194 return $checker;
195 }
196
197 if ( 'greater' === $data['condition'] ) {
198 if ($cart_total > $data['value']) {
199 $checker = true;
200 }
201 } elseif ( 'equal' === $data['condition'] ) {
202 if ($cart_total == $data['value']) {
203 $checker = true;
204 }
205 } elseif ( 'less' === $data['condition'] ) {
206 if ($cart_total < $data['value']) {
207 $checker = true;
208 }
209 }
210 return $checker;
211 }
212
213
214
215 public static function upsell_condition_checker($funnel_id ,$data, $order, $current_page_id, $checker)
216 {
217
218 if( !isset( $data['value'] ) ){
219 return false;
220 }
221
222 if ($data['value'] == 'yes') {
223 if ( $checker == 'accept' ) {
224 return true;
225 } else {
226 return false;
227 }
228
229 } else if ($data['value'] == 'no') {
230 if ($checker == 'reject') {
231 return true;
232 } else {
233 return false;
234 }
235 }
236 return false;
237 }
238
239
240 /**
241 * Billing country condition checker
242 *
243 * @param Array
244 * @param Object
245 * @param String
246 * @param String
247 *
248 * @return Bool
249 * @since 2.4.18
250 */
251 public static function billing_condition_checker( $funnel_id, $data, $order, $current_page_id, $checker ){
252
253 if( !$order || !isset( $data['field'], $data['value'] ) ){
254 return false;
255 }
256
257 $billing_country = $order->get_billing_country();
258 if( 'billing' !== $data['field'] || $billing_country !== $data['value'] ){
259 return false;
260 }
261 return true;
262
263 }
264
265
266 /**
267 * Shipping country condition checker
268 *
269 * @param Array
270 * @param Object
271 * @param String
272 * @param String
273 *
274 * @return Bool
275 * @since 2.4.18
276 */
277 public static function shipping_condition_checker( $funnel_id, $data, $order, $current_page_id, $checker ){
278 if( !$order || !isset( $data['field'], $data['value'] ) ){
279 return false;
280 }
281
282 $shipping_country = $order->get_shipping_country();
283 if( 'shipping' !== $data['field'] || $shipping_country !== $data['value'] ){
284 return false;
285 }
286
287 return true;
288 }
289
290
291
292
293
294 }
295