PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / trunk
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell vtrunk
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 2.8.17 2.8.18 All 259 releases
wpfunnels / admin / modules / steps / class-wpfnl-steps.php

class-wpfnl-steps.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell trunk, at admin/modules/steps/class-wpfnl-steps.php

306 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Step module
4 *
5 * @package
6 */
7 namespace WPFunnels\Admin\Modules\Steps;
8
9 use WPFunnels\Admin\Module\Steps\Wpfnl_Steps_Factory;
10 use WPFunnels\Admin\Module\Wpfnl_Admin_Module;
11 use WPFunnels\Wpfnl;
12 use WPFunnels\Wpfnl_functions;
13 use WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
14 class Module extends Wpfnl_Admin_Module
15 {
16 protected $steps = [];
17
18 protected $id;
19
20 protected $type;
21
22 protected $step;
23
24 public $step_title;
25
26 public function __construct()
27 {
28 $this->steps = $this->get_steps();
29 }
30
31 /**
32 * Get step
33 *
34 * @return Obj
35 */
36 public function get_step($name)
37 {
38 $this->step = Wpfnl_Steps_Factory::build($name);
39 return $this->step;
40 }
41
42 /**
43 * Get all steps
44 *
45 * @return Array
46 * @since 2.0.4
47 */
48 public function get_steps()
49 {
50 return [
51 'landing',
52 'thankyou',
53 'checkout',
54 'upsell',
55 'downsell',
56 ];
57 }
58
59
60 /**
61 * Initialize class
62 *
63 * @return void
64 * @since 2.0.4
65 */
66 public function init($id)
67 {
68 $this->set_id($id);
69 $this->step = Wpfnl::get_instance()->step_store;
70 $this->step->read($this->get_id());
71 $this->set_type($this->step->get_type());
72 }
73
74 /**
75 * Set step ID
76 *
77 * @param Int $id
78 *
79 * @return void
80 * @since 2.0.4
81 */
82 public function set_id($id)
83 {
84 $this->id = $id;
85 }
86
87 /**
88 * Get step ID
89 *
90 * @return Int
91 * @since 2.0.4
92 */
93 public function get_id()
94 {
95 return $this->id;
96 }
97
98 /**
99 * Set step type
100 *
101 * @param String $type
102 *
103 * @return void
104 * @since 2.0.4
105 */
106 public function set_type($type)
107 {
108 $this->type = $type;
109 }
110
111
112 /**
113 * Get step type
114 *
115 * @return String
116 * @since 2.0.4
117 */
118 public function get_type()
119 {
120 return $this->type;
121 }
122
123
124 /**
125 * Set internal meta fields for this step
126 *
127 * @since 1.0.0
128 */
129 public function set_internal_meta_value()
130 {
131 $meta_values = [];
132 foreach ($this->_internal_keys as $key => $value) {
133 $meta_value = $this->step->get_meta($this->get_id(), $key);
134 $meta_values[$key] = $meta_value ? $meta_value : $value;
135 }
136 $this->_internal_keys = $meta_values;
137 }
138
139
140 /**
141 * Get internal meta
142 *
143 * @return Array
144 * @since 2.0.4
145 */
146 public function get_internal_metas()
147 {
148 return $this->_internal_keys;
149 }
150
151 /**
152 * Get meta value by key
153 *
154 * @param $key
155 *
156 * @return mixed
157 * @since 1.0.0
158 */
159 public function get_internal_metas_by_key($key)
160 {
161 if (isset($this->_internal_keys[$key])) {
162 return $this->_internal_keys[$key];
163 }
164
165 return '';
166 }
167
168 /**
169 * Get module name
170 *
171 * @return String
172 * @since 2.0.4
173 */
174 public function get_name()
175 {
176 return __('steps', 'wpfnl');
177 }
178
179
180 /**
181 * Initialize ajax callback functions
182 *
183 * @return void
184 * @since 2.0.4
185 */
186 public function init_ajax()
187 {
188 wp_ajax_helper()->handle('step-edit')
189 ->with_callback([ $this, 'step_edit' ])
190 ->with_validation($this->get_validation_data());
191
192 wp_ajax_helper()->handle('wpfnl-save-skip-offer-settings')
193 ->with_callback([ $this, 'save_skip_offer_settings' ])
194 ->with_validation($this->get_validation_data());
195
196 wp_ajax_helper()->handle('wpfnl-get-skip-offer-settings')
197 ->with_callback([ $this, 'get_skip_offer_settings' ])
198 ->with_validation($this->get_validation_data());
199 }
200
201 /**
202 * Edit step by ajax request
203 *
204 * @return array
205 * @since 1.0.0
206 */
207 public function step_edit($payload)
208 {
209 $step_id = $payload['step_id'];
210 $input = sanitize_text_field($payload['input']);
211
212 $step_post = [
213 'ID' => $step_id,
214 'post_title' => $input,
215 ];
216
217 wp_update_post($step_post);
218 return [
219 'success' => true,
220 'message' => "Step title updated",
221 ];
222 }
223
224 /**
225 * Save skip offer settings
226 *
227 * @param array $payload
228 * @return array
229 * @since 3.0.0
230 */
231 public function save_skip_offer_settings($payload)
232 {
233 $step_id = isset($payload['step_id']) ? absint($payload['step_id']) : 0;
234 $funnel_id = isset($payload['funnel_id']) ? absint($payload['funnel_id']) : 0;
235
236 if (!$step_id) {
237 return [
238 'success' => false,
239 'message' => __('Invalid step ID', 'wpfnl'),
240 ];
241 }
242
243 // Sanitize and save settings
244 $skip_offer_enabled = isset($payload['skip_offer_enabled']) ? sanitize_text_field($payload['skip_offer_enabled']) : 'no';
245 $skip_if_parent_product_exists = isset($payload['skip_if_parent_product_exists']) ? sanitize_text_field($payload['skip_if_parent_product_exists']) : 'no';
246 $skip_if_ever_purchased = isset($payload['skip_if_ever_purchased']) ? sanitize_text_field($payload['skip_if_ever_purchased']) : 'no';
247
248 // Update post meta
249 update_post_meta($step_id, '_wpfnl_skip_offer_enabled', $skip_offer_enabled);
250 update_post_meta($step_id, '_wpfnl_skip_if_parent_product_exists', $skip_if_parent_product_exists);
251 update_post_meta($step_id, '_wpfnl_skip_if_ever_purchased', $skip_if_ever_purchased);
252
253 return [
254 'success' => true,
255 'message' => __('Offer settings saved successfully', 'wpfnl'),
256 ];
257 }
258
259 /**
260 * Get skip offer settings
261 *
262 * @param array $payload
263 * @return array
264 * @since 3.0.0
265 */
266 public function get_skip_offer_settings($payload)
267 {
268 $step_id = isset($payload['step_id']) ? absint($payload['step_id']) : 0;
269
270 if (!$step_id) {
271 return [
272 'success' => false,
273 'message' => __('Invalid step ID', 'wpfnl'),
274 ];
275 }
276
277 // Get settings from post meta
278 $skip_offer_enabled = get_post_meta($step_id, '_wpfnl_skip_offer_enabled', true);
279 $skip_if_parent_product_exists = get_post_meta($step_id, '_wpfnl_skip_if_parent_product_exists', true);
280 $skip_if_ever_purchased = get_post_meta($step_id, '_wpfnl_skip_if_ever_purchased', true);
281
282 // Set defaults if not set
283 $skip_offer_enabled = $skip_offer_enabled ? $skip_offer_enabled : 'no';
284 $skip_if_parent_product_exists = $skip_if_parent_product_exists ? $skip_if_parent_product_exists : 'no';
285 $skip_if_ever_purchased = $skip_if_ever_purchased ? $skip_if_ever_purchased : 'no';
286
287 return [
288 'success' => true,
289 'data' => [
290 'skip_offer_enabled' => $skip_offer_enabled,
291 'skip_if_parent_product_exists' => $skip_if_parent_product_exists,
292 'skip_if_ever_purchased' => $skip_if_ever_purchased,
293 ],
294 ];
295 }
296
297 /**
298 * Get view
299 */
300 public function get_view()
301 {
302 }
303 }
304
305
306