Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress - Version 1.1.17

Version Description

Download this release

Release Info

Developer sandesh055
Plugin Icon Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress
Version 1.1.17
Comparing to
See all releases

Code changes from version 1.1.16 to 1.1.17

cartflows.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: CartFlows
4
  * Plugin URI: https://cartflows.com/
5
  * Description: Create beautiful checkout pages & sales flows for WooCommerce.
6
- * Version: 1.1.16
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
3
  * Plugin Name: CartFlows
4
  * Plugin URI: https://cartflows.com/
5
  * Description: Create beautiful checkout pages & sales flows for WooCommerce.
6
+ * Version: 1.1.17
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
changelog.txt CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  Version 1.1.16 - Thursday, 25th April 2019
2
  - Improvement: Added compatibility for the Cartflows Pro plugin update for an older versions.
3
 
1
+ Version 1.1.17 - Tuesday, 30th April 2019
2
+ - Fix: Database connectivity error while cloning the flow.
3
+
4
  Version 1.1.16 - Thursday, 25th April 2019
5
  - Improvement: Added compatibility for the Cartflows Pro plugin update for an older versions.
6
 
classes/class-cartflows-cloning.php CHANGED
@@ -1,436 +1,445 @@
1
- <?php
2
- /**
3
- * Cloning.
4
- *
5
- * @package cartflows-pro
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Cloning {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self;
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- add_filter( 'post_row_actions', array( $this, 'clone_link' ), 99, 2 );
39
- add_action( 'admin_action_cartflows_clone_flow', array( $this, 'clone_flow' ) );
40
- add_action( 'admin_action_cartflows_clone_step', array( $this, 'clone_step' ) );
41
- }
42
-
43
- /**
44
- * Clone flow with steps and its meta.
45
- */
46
- function clone_flow() {
47
-
48
- global $wpdb;
49
-
50
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_flow' == $_REQUEST['action'] ) ) ) {
51
- wp_die( 'No post to duplicate has been supplied!' );
52
- }
53
-
54
- /*
55
- * Nonce verification
56
- */
57
- if ( ! isset( $_GET['flow_clone_nonce'] ) || ! wp_verify_nonce( $_GET['flow_clone_nonce'], basename( __FILE__ ) ) ) {
58
- return;
59
- }
60
-
61
- /**
62
- * Get the original post id
63
- */
64
- $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
65
-
66
- /**
67
- * And all the original post data then
68
- */
69
- $post = get_post( $post_id );
70
-
71
- /**
72
- * Assign current user to be the new post author
73
- */
74
- $current_user = wp_get_current_user();
75
- $new_post_author = $current_user->ID;
76
-
77
- /**
78
- * If post data exists, create the post duplicate
79
- */
80
- if ( isset( $post ) && null !== $post ) {
81
-
82
- /**
83
- * New post data array
84
- */
85
-
86
- $args = array(
87
- 'comment_status' => $post->comment_status,
88
- 'ping_status' => $post->ping_status,
89
- 'post_author' => $new_post_author,
90
- 'post_content' => $post->post_content,
91
- 'post_excerpt' => $post->post_excerpt,
92
- 'post_name' => $post->post_name,
93
- 'post_parent' => $post->post_parent,
94
- 'post_password' => $post->post_password,
95
- 'post_status' => $post->post_status,
96
- 'post_title' => $post->post_title . ' Clone',
97
- 'post_type' => $post->post_type,
98
- 'to_ping' => $post->to_ping,
99
- 'menu_order' => $post->menu_order,
100
- );
101
-
102
- /**
103
- * Insert the post
104
- */
105
- $new_flow_id = wp_insert_post( $args );
106
-
107
- /**
108
- * Get all current post terms ad set them to the new post
109
- */
110
- // returns array of taxonomy names for post type, ex array("category", "post_tag");.
111
- $taxonomies = get_object_taxonomies( $post->post_type );
112
-
113
- foreach ( $taxonomies as $taxonomy ) {
114
-
115
- $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
116
-
117
- wp_set_object_terms( $new_flow_id, $post_terms, $taxonomy, false );
118
- }
119
-
120
- /**
121
- * Duplicate all post meta just in two SQL queries
122
- */
123
- // @codingStandardsIgnoreStart
124
- $post_meta_infos = $wpdb->get_results(
125
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
126
- );
127
- // @codingStandardsIgnoreEnd
128
-
129
- if ( ! empty( $post_meta_infos ) ) {
130
-
131
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
132
-
133
- foreach ( $post_meta_infos as $meta_info ) {
134
-
135
- $meta_key = $meta_info->meta_key;
136
-
137
- if ( '_wp_old_slug' === $meta_key ) {
138
- continue;
139
- }
140
-
141
- $meta_value = addslashes( $meta_info->meta_value );
142
-
143
- $sql_query_sel[] = "SELECT $new_flow_id, '$meta_key', '$meta_value'";
144
- }
145
-
146
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
147
-
148
- // @codingStandardsIgnoreStart
149
- $wpdb->query( $sql_query );
150
- // @codingStandardsIgnoreEnd
151
- }
152
-
153
- /* Steps Cloning */
154
- $flow_steps = get_post_meta( $post_id, 'wcf-steps', true );
155
- $new_flow_steps = array();
156
-
157
- if ( is_array( $flow_steps ) && ! empty( $flow_steps ) ) {
158
-
159
- foreach ( $flow_steps as $index => $step_data ) {
160
-
161
- $step_id = $step_data['id'];
162
- $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
163
-
164
- $step_object = get_post( $step_id );
165
-
166
- /**
167
- * New step post data array
168
- */
169
- $step_args = array(
170
- 'comment_status' => $step_object->comment_status,
171
- 'ping_status' => $step_object->ping_status,
172
- 'post_author' => $new_post_author,
173
- 'post_content' => $step_object->post_content,
174
- 'post_excerpt' => $step_object->post_excerpt,
175
- 'post_name' => $step_object->post_name,
176
- 'post_parent' => $step_object->post_parent,
177
- 'post_password' => $step_object->post_password,
178
- 'post_status' => $step_object->post_status,
179
- 'post_title' => $step_object->post_title,
180
- 'post_type' => $step_object->post_type,
181
- 'to_ping' => $step_object->to_ping,
182
- 'menu_order' => $step_object->menu_order,
183
- );
184
-
185
- /**
186
- * Insert the post
187
- */
188
- $new_step_id = wp_insert_post( $step_args );
189
-
190
- /**
191
- * Duplicate all step meta
192
- */
193
- // @codingStandardsIgnoreStart
194
- $post_meta_infos = $wpdb->get_results(
195
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$step_id"
196
- );
197
- // @codingStandardsIgnoreEnd
198
-
199
- if ( ! empty( $post_meta_infos ) ) {
200
-
201
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
202
-
203
- foreach ( $post_meta_infos as $meta_info ) {
204
-
205
- $meta_key = $meta_info->meta_key;
206
-
207
- if ( '_wp_old_slug' === $meta_key ) {
208
- continue;
209
- }
210
-
211
- $meta_value = addslashes( $meta_info->meta_value );
212
-
213
- $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
214
- }
215
-
216
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
217
-
218
- // @codingStandardsIgnoreStart
219
- $wpdb->query( $sql_query );
220
- // @codingStandardsIgnoreEnd
221
- }
222
-
223
- // insert post meta.
224
- update_post_meta( $new_step_id, 'wcf-flow-id', $new_flow_id );
225
- update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
226
-
227
- wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
228
- wp_set_object_terms( $new_step_id, 'flow-' . $new_flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
229
-
230
- /* Add New Flow Steps */
231
- $new_flow_steps[] = array(
232
- 'id' => $new_step_id,
233
- 'title' => $step_object->post_title,
234
- 'type' => $step_type,
235
- );
236
- }
237
- }
238
-
239
- /* Update New Flow Step Post Meta */
240
- update_post_meta( $new_flow_id, 'wcf-steps', $new_flow_steps );
241
-
242
- /* Clear Page Builder Cache */
243
- $this->clear_cache();
244
-
245
- /**
246
- * Redirect to the new flow edit screen
247
- */
248
- wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_flow_id ) );
249
- exit;
250
- } else {
251
- wp_die( 'Post creation failed, could not find original post: ' . $post_id );
252
- }
253
- }
254
-
255
- /**
256
- * Clone step with its meta.
257
- */
258
- function clone_step() {
259
-
260
- global $wpdb;
261
-
262
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_step' === $_REQUEST['action'] ) ) ) {
263
- wp_die( 'No post to duplicate has been supplied!' );
264
- }
265
-
266
- /*
267
- * Nonce verification
268
- */
269
- if ( ! isset( $_GET['step_clone_nonce'] ) || ! wp_verify_nonce( $_GET['step_clone_nonce'], 'step_clone' ) ) {
270
- return;
271
- }
272
-
273
- /**
274
- * Get the original post id
275
- */
276
- $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
277
-
278
- /**
279
- * And all the original post data then
280
- */
281
- $post = get_post( $post_id );
282
-
283
- /**
284
- * Assign current user to be the new post author
285
- */
286
- $current_user = wp_get_current_user();
287
- $new_post_author = $current_user->ID;
288
-
289
- /**
290
- * If post data exists, create the post duplicate
291
- */
292
- if ( isset( $post ) && null !== $post ) {
293
-
294
- /**
295
- * New post data array
296
- */
297
- $args = array(
298
- 'comment_status' => $post->comment_status,
299
- 'ping_status' => $post->ping_status,
300
- 'post_author' => $new_post_author,
301
- 'post_content' => $post->post_content,
302
- 'post_excerpt' => $post->post_excerpt,
303
- 'post_name' => $post->post_name,
304
- 'post_parent' => $post->post_parent,
305
- 'post_password' => $post->post_password,
306
- 'post_status' => $post->post_status,
307
- 'post_title' => $post->post_title . ' Clone',
308
- 'post_type' => $post->post_type,
309
- 'to_ping' => $post->to_ping,
310
- 'menu_order' => $post->menu_order,
311
- );
312
-
313
- /**
314
- * Insert the post
315
- */
316
- $new_step_id = wp_insert_post( $args );
317
-
318
- /**
319
- * Get all current post terms ad set them to the new post
320
- */
321
- // returns array of taxonomy names for post type, ex array("category", "post_tag");.
322
- $taxonomies = get_object_taxonomies( $post->post_type );
323
-
324
- foreach ( $taxonomies as $taxonomy ) {
325
-
326
- $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
327
-
328
- wp_set_object_terms( $new_step_id, $post_terms, $taxonomy, false );
329
- }
330
-
331
- /**
332
- * Duplicate all post meta just in two SQL queries
333
- */
334
- // @codingStandardsIgnoreStart
335
- $post_meta_infos = $wpdb->get_results(
336
- "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
337
- );
338
- // @codingStandardsIgnoreEnd
339
-
340
- if ( ! empty( $post_meta_infos ) ) {
341
-
342
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
343
-
344
- foreach ( $post_meta_infos as $meta_info ) {
345
-
346
- $meta_key = $meta_info->meta_key;
347
-
348
- if ( '_wp_old_slug' === $meta_key ) {
349
- continue;
350
- }
351
-
352
- $meta_value = addslashes( $meta_info->meta_value );
353
-
354
- $sql_query_sel[] = "SELECT $new_step_id, '$meta_key', '$meta_value'";
355
- }
356
-
357
- $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
358
-
359
- // @codingStandardsIgnoreStart
360
- $wpdb->query( $sql_query );
361
- // @codingStandardsIgnoreEnd
362
- }
363
-
364
- $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
365
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
366
- $step_type = get_post_meta( $post_id, 'wcf-step-type', true );
367
-
368
- if ( ! is_array( $flow_steps ) ) {
369
- $flow_steps = array();
370
- }
371
-
372
- $flow_steps[] = array(
373
- 'id' => $new_step_id,
374
- 'title' => $post->post_title,
375
- 'type' => $step_type,
376
- );
377
-
378
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
379
-
380
- /* Clear Page Builder Cache */
381
- $this->clear_cache();
382
-
383
- /**
384
- * Redirect to the new flow edit screen
385
- */
386
- $redirect_url = add_query_arg( 'highlight-step-id', $new_step_id, get_edit_post_link( $flow_id, 'default' ) );
387
-
388
- wp_redirect( $redirect_url );
389
- exit;
390
- } else {
391
- wp_die( 'Post creation failed, could not find original post: ' . $post_id );
392
- }
393
- }
394
-
395
- /**
396
- * Add the clone link to action list for flows row actions
397
- *
398
- * @param array $actions Actions array.
399
- * @param object $post Post object.
400
- *
401
- * @return array
402
- */
403
- function clone_link( $actions, $post ) {
404
-
405
- if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
406
-
407
- if ( isset( $actions['duplicate'] ) ) { // Duplicate page plugin remove.
408
- unset( $actions['duplicate'] );
409
- }
410
- if ( isset( $actions['edit_as_new_draft'] ) ) { // Duplicate post plugin remove.
411
- unset( $actions['edit_as_new_draft'] );
412
- }
413
-
414
- $actions['clone'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_clone_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_clone_nonce' ) . '" title="' . __( 'Clone this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Clone', 'cartflows' ) . '</a>';
415
- }
416
-
417
- return $actions;
418
- }
419
-
420
- /**
421
- * Clear Page Builder Cache
422
- */
423
- function clear_cache() {
424
-
425
- // Clear 'Elementor' file cache.
426
- if ( class_exists( '\Elementor\Plugin' ) ) {
427
- Elementor\Plugin::$instance->files_manager->clear_cache();
428
- }
429
- }
430
-
431
- }
432
-
433
- /**
434
- * Kicking this off by calling 'get_instance()' method
435
- */
436
- Cartflows_Cloning::get_instance();
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cloning.
4
+ *
5
+ * @package cartflows-pro
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Cloning {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self;
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ add_filter( 'post_row_actions', array( $this, 'clone_link' ), 99, 2 );
39
+ add_action( 'admin_action_cartflows_clone_flow', array( $this, 'clone_flow' ) );
40
+ add_action( 'admin_action_cartflows_clone_step', array( $this, 'clone_step' ) );
41
+ }
42
+
43
+ /**
44
+ * Clone flow with steps and its meta.
45
+ */
46
+ function clone_flow() {
47
+
48
+ global $wpdb;
49
+
50
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_flow' == $_REQUEST['action'] ) ) ) {
51
+ wp_die( 'No post to duplicate has been supplied!' );
52
+ }
53
+
54
+ /*
55
+ * Nonce verification
56
+ */
57
+ if ( ! isset( $_GET['flow_clone_nonce'] ) || ! wp_verify_nonce( $_GET['flow_clone_nonce'], basename( __FILE__ ) ) ) {
58
+ return;
59
+ }
60
+
61
+ /**
62
+ * Get the original post id
63
+ */
64
+ $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
65
+
66
+ /**
67
+ * And all the original post data then
68
+ */
69
+ $post = get_post( $post_id );
70
+
71
+ /**
72
+ * Assign current user to be the new post author
73
+ */
74
+ $current_user = wp_get_current_user();
75
+ $new_post_author = $current_user->ID;
76
+
77
+ /**
78
+ * If post data exists, create the post duplicate
79
+ */
80
+ if ( isset( $post ) && null !== $post ) {
81
+
82
+ /**
83
+ * New post data array
84
+ */
85
+
86
+ $args = array(
87
+ 'comment_status' => $post->comment_status,
88
+ 'ping_status' => $post->ping_status,
89
+ 'post_author' => $new_post_author,
90
+ 'post_content' => $post->post_content,
91
+ 'post_excerpt' => $post->post_excerpt,
92
+ 'post_name' => $post->post_name,
93
+ 'post_parent' => $post->post_parent,
94
+ 'post_password' => $post->post_password,
95
+ 'post_status' => $post->post_status,
96
+ 'post_title' => $post->post_title . ' Clone',
97
+ 'post_type' => $post->post_type,
98
+ 'to_ping' => $post->to_ping,
99
+ 'menu_order' => $post->menu_order,
100
+ );
101
+
102
+ /**
103
+ * Insert the post
104
+ */
105
+ $new_flow_id = wp_insert_post( $args );
106
+
107
+ /**
108
+ * Get all current post terms ad set them to the new post
109
+ */
110
+ // returns array of taxonomy names for post type, ex array("category", "post_tag");.
111
+ $taxonomies = get_object_taxonomies( $post->post_type );
112
+
113
+ foreach ( $taxonomies as $taxonomy ) {
114
+
115
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
116
+
117
+ wp_set_object_terms( $new_flow_id, $post_terms, $taxonomy, false );
118
+ }
119
+
120
+ /**
121
+ * Duplicate all post meta just in two SQL queries
122
+ */
123
+ // @codingStandardsIgnoreStart
124
+ $post_meta_infos = $wpdb->get_results(
125
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
126
+ );
127
+ // @codingStandardsIgnoreEnd
128
+
129
+ if ( ! empty( $post_meta_infos ) ) {
130
+
131
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES ";
132
+
133
+ $sql_query_sel = array();
134
+
135
+ foreach ( $post_meta_infos as $meta_info ) {
136
+
137
+ $meta_key = $meta_info->meta_key;
138
+
139
+ if ( '_wp_old_slug' === $meta_key ) {
140
+ continue;
141
+ }
142
+
143
+ $meta_value = addslashes( $meta_info->meta_value );
144
+
145
+ $sql_query_sel[] = "($new_flow_id, '$meta_key', '$meta_value')";
146
+ }
147
+
148
+ $sql_query .= implode( ',', $sql_query_sel );
149
+
150
+ // @codingStandardsIgnoreStart
151
+ $wpdb->query( $sql_query );
152
+ // @codingStandardsIgnoreEnd
153
+ }
154
+
155
+ /* Steps Cloning */
156
+ $flow_steps = get_post_meta( $post_id, 'wcf-steps', true );
157
+ $new_flow_steps = array();
158
+
159
+ /* Set Steps Empty */
160
+ update_post_meta( $new_flow_id, 'wcf-steps', $new_flow_steps );
161
+
162
+ if ( is_array( $flow_steps ) && ! empty( $flow_steps ) ) {
163
+
164
+ foreach ( $flow_steps as $index => $step_data ) {
165
+
166
+ $step_id = $step_data['id'];
167
+ $step_type = get_post_meta( $step_id, 'wcf-step-type', true );
168
+
169
+ $step_object = get_post( $step_id );
170
+
171
+ /**
172
+ * New step post data array
173
+ */
174
+ $step_args = array(
175
+ 'comment_status' => $step_object->comment_status,
176
+ 'ping_status' => $step_object->ping_status,
177
+ 'post_author' => $new_post_author,
178
+ 'post_content' => $step_object->post_content,
179
+ 'post_excerpt' => $step_object->post_excerpt,
180
+ 'post_name' => $step_object->post_name,
181
+ 'post_parent' => $step_object->post_parent,
182
+ 'post_password' => $step_object->post_password,
183
+ 'post_status' => $step_object->post_status,
184
+ 'post_title' => $step_object->post_title,
185
+ 'post_type' => $step_object->post_type,
186
+ 'to_ping' => $step_object->to_ping,
187
+ 'menu_order' => $step_object->menu_order,
188
+ );
189
+
190
+ /**
191
+ * Insert the post
192
+ */
193
+ $new_step_id = wp_insert_post( $step_args );
194
+
195
+ /**
196
+ * Duplicate all step meta
197
+ */
198
+ // @codingStandardsIgnoreStart
199
+ $post_meta_infos = $wpdb->get_results(
200
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$step_id"
201
+ );
202
+ // @codingStandardsIgnoreEnd
203
+
204
+ if ( ! empty( $post_meta_infos ) ) {
205
+
206
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES ";
207
+
208
+ $sql_query_sel = array();
209
+
210
+ foreach ( $post_meta_infos as $meta_info ) {
211
+
212
+ $meta_key = $meta_info->meta_key;
213
+
214
+ if ( '_wp_old_slug' === $meta_key ) {
215
+ continue;
216
+ }
217
+
218
+ $meta_value = addslashes( $meta_info->meta_value );
219
+
220
+ $sql_query_sel[] = "($new_step_id, '$meta_key', '$meta_value')";
221
+ }
222
+
223
+ $sql_query .= implode( ',', $sql_query_sel );
224
+
225
+ // @codingStandardsIgnoreStart
226
+ $wpdb->query( $sql_query );
227
+ // @codingStandardsIgnoreEnd
228
+ }
229
+
230
+ // insert post meta.
231
+ update_post_meta( $new_step_id, 'wcf-flow-id', $new_flow_id );
232
+ update_post_meta( $new_step_id, 'wcf-step-type', $step_type );
233
+
234
+ wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
235
+ wp_set_object_terms( $new_step_id, 'flow-' . $new_flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
236
+
237
+ /* Add New Flow Steps */
238
+ $new_flow_steps[] = array(
239
+ 'id' => $new_step_id,
240
+ 'title' => $step_object->post_title,
241
+ 'type' => $step_type,
242
+ );
243
+ }
244
+ }
245
+
246
+ /* Update New Flow Step Post Meta */
247
+ update_post_meta( $new_flow_id, 'wcf-steps', $new_flow_steps );
248
+
249
+ /* Clear Page Builder Cache */
250
+ $this->clear_cache();
251
+
252
+ /**
253
+ * Redirect to the new flow edit screen
254
+ */
255
+ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_flow_id ) );
256
+ exit;
257
+ } else {
258
+ wp_die( 'Post creation failed, could not find original post: ' . $post_id );
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Clone step with its meta.
264
+ */
265
+ function clone_step() {
266
+
267
+ global $wpdb;
268
+
269
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_clone_step' === $_REQUEST['action'] ) ) ) {
270
+ wp_die( 'No post to duplicate has been supplied!' );
271
+ }
272
+
273
+ /*
274
+ * Nonce verification
275
+ */
276
+ if ( ! isset( $_GET['step_clone_nonce'] ) || ! wp_verify_nonce( $_GET['step_clone_nonce'], 'step_clone' ) ) {
277
+ return;
278
+ }
279
+
280
+ /**
281
+ * Get the original post id
282
+ */
283
+ $post_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
284
+
285
+ /**
286
+ * And all the original post data then
287
+ */
288
+ $post = get_post( $post_id );
289
+
290
+ /**
291
+ * Assign current user to be the new post author
292
+ */
293
+ $current_user = wp_get_current_user();
294
+ $new_post_author = $current_user->ID;
295
+
296
+ /**
297
+ * If post data exists, create the post duplicate
298
+ */
299
+ if ( isset( $post ) && null !== $post ) {
300
+
301
+ /**
302
+ * New post data array
303
+ */
304
+ $args = array(
305
+ 'comment_status' => $post->comment_status,
306
+ 'ping_status' => $post->ping_status,
307
+ 'post_author' => $new_post_author,
308
+ 'post_content' => $post->post_content,
309
+ 'post_excerpt' => $post->post_excerpt,
310
+ 'post_name' => $post->post_name,
311
+ 'post_parent' => $post->post_parent,
312
+ 'post_password' => $post->post_password,
313
+ 'post_status' => $post->post_status,
314
+ 'post_title' => $post->post_title . ' Clone',
315
+ 'post_type' => $post->post_type,
316
+ 'to_ping' => $post->to_ping,
317
+ 'menu_order' => $post->menu_order,
318
+ );
319
+
320
+ /**
321
+ * Insert the post
322
+ */
323
+ $new_step_id = wp_insert_post( $args );
324
+
325
+ /**
326
+ * Get all current post terms ad set them to the new post
327
+ */
328
+ // returns array of taxonomy names for post type, ex array("category", "post_tag");.
329
+ $taxonomies = get_object_taxonomies( $post->post_type );
330
+
331
+ foreach ( $taxonomies as $taxonomy ) {
332
+
333
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
334
+
335
+ wp_set_object_terms( $new_step_id, $post_terms, $taxonomy, false );
336
+ }
337
+
338
+ /**
339
+ * Duplicate all post meta just in two SQL queries
340
+ */
341
+ // @codingStandardsIgnoreStart
342
+ $post_meta_infos = $wpdb->get_results(
343
+ "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
344
+ );
345
+ // @codingStandardsIgnoreEnd
346
+
347
+ if ( ! empty( $post_meta_infos ) ) {
348
+
349
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES ";
350
+
351
+ $sql_query_sel = array();
352
+
353
+ foreach ( $post_meta_infos as $meta_info ) {
354
+
355
+ $meta_key = $meta_info->meta_key;
356
+
357
+ if ( '_wp_old_slug' === $meta_key ) {
358
+ continue;
359
+ }
360
+
361
+ $meta_value = addslashes( $meta_info->meta_value );
362
+
363
+ $sql_query_sel[] = "($new_step_id, '$meta_key', '$meta_value')";
364
+ }
365
+
366
+ $sql_query .= implode( ',', $sql_query_sel );
367
+
368
+ // @codingStandardsIgnoreStart
369
+ $wpdb->query( $sql_query );
370
+ // @codingStandardsIgnoreEnd
371
+ }
372
+
373
+ $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
374
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
375
+ $step_type = get_post_meta( $post_id, 'wcf-step-type', true );
376
+
377
+ if ( ! is_array( $flow_steps ) ) {
378
+ $flow_steps = array();
379
+ }
380
+
381
+ $flow_steps[] = array(
382
+ 'id' => $new_step_id,
383
+ 'title' => $post->post_title,
384
+ 'type' => $step_type,
385
+ );
386
+
387
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
388
+
389
+ /* Clear Page Builder Cache */
390
+ $this->clear_cache();
391
+
392
+ /**
393
+ * Redirect to the new flow edit screen
394
+ */
395
+ $redirect_url = add_query_arg( 'highlight-step-id', $new_step_id, get_edit_post_link( $flow_id, 'default' ) );
396
+
397
+ wp_redirect( $redirect_url );
398
+ exit;
399
+ } else {
400
+ wp_die( 'Post creation failed, could not find original post: ' . $post_id );
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Add the clone link to action list for flows row actions
406
+ *
407
+ * @param array $actions Actions array.
408
+ * @param object $post Post object.
409
+ *
410
+ * @return array
411
+ */
412
+ function clone_link( $actions, $post ) {
413
+
414
+ if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
415
+
416
+ if ( isset( $actions['duplicate'] ) ) { // Duplicate page plugin remove.
417
+ unset( $actions['duplicate'] );
418
+ }
419
+ if ( isset( $actions['edit_as_new_draft'] ) ) { // Duplicate post plugin remove.
420
+ unset( $actions['edit_as_new_draft'] );
421
+ }
422
+
423
+ $actions['clone'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_clone_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_clone_nonce' ) . '" title="' . __( 'Clone this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Clone', 'cartflows' ) . '</a>';
424
+ }
425
+
426
+ return $actions;
427
+ }
428
+
429
+ /**
430
+ * Clear Page Builder Cache
431
+ */
432
+ function clear_cache() {
433
+
434
+ // Clear 'Elementor' file cache.
435
+ if ( class_exists( '\Elementor\Plugin' ) ) {
436
+ Elementor\Plugin::$instance->files_manager->clear_cache();
437
+ }
438
+ }
439
+
440
+ }
441
+
442
+ /**
443
+ * Kicking this off by calling 'get_instance()' method
444
+ */
445
+ Cartflows_Cloning::get_instance();
classes/class-cartflows-loader.php CHANGED
@@ -118,7 +118,7 @@ if ( ! class_exists( 'Cartflows_Loader' ) ) {
118
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
119
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
120
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
121
- define( 'CARTFLOWS_VER', '1.1.16' );
122
  define( 'CARTFLOWS_SLUG', 'cartflows' );
123
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
124
 
118
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
119
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
120
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
121
+ define( 'CARTFLOWS_VER', '1.1.17' );
122
  define( 'CARTFLOWS_SLUG', 'cartflows' );
123
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
124
 
classes/class-cartflows-update.php CHANGED
@@ -1,78 +1,78 @@
1
- <?php
2
- /**
3
- * Update Compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- if ( ! class_exists( 'Cartflows_Update' ) ) :
9
-
10
- /**
11
- * CartFlows Update initial setup
12
- *
13
- * @since 1.0.0
14
- */
15
- class Cartflows_Update {
16
-
17
- /**
18
- * Class instance.
19
- *
20
- * @access private
21
- * @var $instance Class instance.
22
- */
23
- private static $instance;
24
-
25
- /**
26
- * Initiator
27
- */
28
- public static function get_instance() {
29
- if ( ! isset( self::$instance ) ) {
30
- self::$instance = new self();
31
- }
32
- return self::$instance;
33
- }
34
-
35
- /**
36
- * Constructor
37
- */
38
- public function __construct() {
39
- add_action( 'admin_init', __CLASS__ . '::init' );
40
- }
41
-
42
- /**
43
- * Init
44
- *
45
- * @since 1.0.0
46
- * @return void
47
- */
48
- static public function init() {
49
-
50
- do_action( 'cartflows_update_before' );
51
-
52
- // Get auto saved version number.
53
- $saved_version = get_option( 'cartflows-version', false );
54
-
55
- // Update auto saved version number.
56
- if ( ! $saved_version ) {
57
- update_option( 'cartflows-version', CARTFLOWS_VER );
58
- return;
59
- }
60
-
61
- // If equals then return.
62
- if ( version_compare( $saved_version, CARTFLOWS_VER, '=' ) ) {
63
- return;
64
- }
65
-
66
- // Update auto saved version number.
67
- update_option( 'cartflows-version', CARTFLOWS_VER );
68
-
69
- do_action( 'cartflows_update_after' );
70
- }
71
- }
72
-
73
- /**
74
- * Kicking this off by calling 'get_instance()' method
75
- */
76
- Cartflows_Update::get_instance();
77
-
78
- endif;
1
+ <?php
2
+ /**
3
+ * Update Compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_Update' ) ) :
9
+
10
+ /**
11
+ * CartFlows Update initial setup
12
+ *
13
+ * @since 1.0.0
14
+ */
15
+ class Cartflows_Update {
16
+
17
+ /**
18
+ * Class instance.
19
+ *
20
+ * @access private
21
+ * @var $instance Class instance.
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Initiator
27
+ */
28
+ public static function get_instance() {
29
+ if ( ! isset( self::$instance ) ) {
30
+ self::$instance = new self();
31
+ }
32
+ return self::$instance;
33
+ }
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+ add_action( 'admin_init', __CLASS__ . '::init' );
40
+ }
41
+
42
+ /**
43
+ * Init
44
+ *
45
+ * @since 1.0.0
46
+ * @return void
47
+ */
48
+ static public function init() {
49
+
50
+ do_action( 'cartflows_update_before' );
51
+
52
+ // Get auto saved version number.
53
+ $saved_version = get_option( 'cartflows-version', false );
54
+
55
+ // Update auto saved version number.
56
+ if ( ! $saved_version ) {
57
+ update_option( 'cartflows-version', CARTFLOWS_VER );
58
+ return;
59
+ }
60
+
61
+ // If equals then return.
62
+ if ( version_compare( $saved_version, CARTFLOWS_VER, '=' ) ) {
63
+ return;
64
+ }
65
+
66
+ // Update auto saved version number.
67
+ update_option( 'cartflows-version', CARTFLOWS_VER );
68
+
69
+ do_action( 'cartflows_update_after' );
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Kicking this off by calling 'get_instance()' method
75
+ */
76
+ Cartflows_Update::get_instance();
77
+
78
+ endif;
languages/cartflows.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: CartFlows 1.1.16\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
- "POT-Creation-Date: 2019-04-25 10:43:16+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -93,11 +93,11 @@ msgstr ""
93
  msgid "Request successfully processed!"
94
  msgstr ""
95
 
96
- #: classes/class-cartflows-cloning.php:414
97
  msgid "Clone this flow"
98
  msgstr ""
99
 
100
- #: classes/class-cartflows-cloning.php:414
101
  msgid "Clone"
102
  msgstr ""
103
 
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: CartFlows 1.1.17\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
+ "POT-Creation-Date: 2019-04-30 06:45:35+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
93
  msgid "Request successfully processed!"
94
  msgstr ""
95
 
96
+ #: classes/class-cartflows-cloning.php:423
97
  msgid "Clone this flow"
98
  msgstr ""
99
 
100
+ #: classes/class-cartflows-cloning.php:423
101
  msgid "Clone"
102
  msgstr ""
103
 
modules/checkout/classes/class-cartflows-checkout-markup.php CHANGED
@@ -1,1157 +1,1157 @@
1
- <?php
2
- /**
3
- * Checkout markup.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Checkout Markup
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Checkout_Markup {
14
-
15
- /**
16
- * Member Variable
17
- *
18
- * @var object instance
19
- */
20
- private static $instance;
21
-
22
- /**
23
- * Initiator
24
- */
25
- public static function get_instance() {
26
- if ( ! isset( self::$instance ) ) {
27
- self::$instance = new self;
28
- }
29
- return self::$instance;
30
- }
31
-
32
- /**
33
- * Constructor
34
- */
35
- public function __construct() {
36
-
37
- /* Set is checkout flag */
38
- add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
39
-
40
- add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_checkout_fields' ), 10, 2 );
41
-
42
- /* Show notice if cart is empty */
43
- add_action( 'cartflows_checkout_cart_empty', array( $this, 'display_woo_notices' ) );
44
-
45
- /* Checkout Shortcode */
46
- add_shortcode( 'cartflows_checkout', array( $this, 'checkout_shortcode_markup' ) );
47
-
48
- /* Preconfigured cart data */
49
- add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
50
-
51
- /* Embed Checkout */
52
- add_action( 'wp', array( $this, 'shortcode_load_data' ), 999 );
53
-
54
- /* Ajax Endpoint */
55
- add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ) );
56
-
57
- add_filter( 'cartflows_add_before_main_section', array( $this, 'enable_logo_in_header' ) );
58
-
59
- add_filter( 'cartflows_primary_container_bottom', array( $this, 'show_cartflows_copyright_message' ) );
60
-
61
- add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
62
-
63
- add_action( 'wp_ajax_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64
- add_action( 'wp_ajax_nopriv_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
65
-
66
- add_filter( 'global_cartflows_js_localize', array( $this, 'add_localize_vars' ) );
67
-
68
- /* Global Checkout */
69
- add_action( 'template_redirect', array( $this, 'global_checkout_template_redirect' ), 1 );
70
-
71
- add_action( 'wp_ajax_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
72
- add_action( 'wp_ajax_nopriv_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
73
-
74
- }
75
-
76
- /**
77
- * Display all WooCommerce notices.
78
- *
79
- * @since 1.1.5
80
- */
81
- function display_woo_notices() {
82
-
83
- if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
84
- woocommerce_output_all_notices();
85
- }
86
- }
87
-
88
-
89
- /**
90
- * Redirect from default to the global checkout page
91
- *
92
- * @since 1.0.0
93
- */
94
- function global_checkout_template_redirect() {
95
-
96
- if ( ! is_checkout() ) {
97
- return;
98
- }
99
-
100
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
101
- return;
102
- }
103
-
104
- // redirect only from any non HC checkout pages.
105
- $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
106
- $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
107
-
108
- $common = Cartflows_Helper::get_common_settings();
109
-
110
- $global_checkout = $common['global_checkout'];
111
-
112
- if (
113
- // ignore on order-pay.
114
- false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
115
- // ignore on TY page.
116
- false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
117
- ) {
118
-
119
- if ( '' !== $global_checkout ) {
120
-
121
- $link = get_permalink( $global_checkout );
122
-
123
- if ( ! empty( $link ) ) {
124
-
125
- wp_redirect( $link );
126
- die();
127
- }
128
- }
129
- }
130
- }
131
-
132
- /**
133
- * Check for checkout flag
134
- *
135
- * @param bool $is_checkout is checkout.
136
- *
137
- * @return bool
138
- */
139
- function woo_checkout_flag( $is_checkout ) {
140
-
141
- if ( ! is_admin() ) {
142
-
143
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
144
-
145
- $is_checkout = true;
146
- }
147
- }
148
-
149
- return $is_checkout;
150
- }
151
-
152
- /**
153
- * Render checkout shortcode markup.
154
- *
155
- * @param array $atts attributes.
156
- * @return string
157
- */
158
- function checkout_shortcode_markup( $atts ) {
159
-
160
- if ( ! function_exists( 'wc_print_notices' ) ) {
161
- return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
162
- }
163
-
164
- $atts = shortcode_atts(
165
- array(
166
- 'id' => 0,
167
- ),
168
- $atts
169
- );
170
-
171
- $checkout_id = intval( $atts['id'] );
172
-
173
- if ( empty( $checkout_id ) ) {
174
-
175
- if ( ! _is_wcf_checkout_type() ) {
176
-
177
- return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
178
- }
179
-
180
- global $post;
181
-
182
- $checkout_id = intval( $post->ID );
183
- }
184
-
185
- $output = '';
186
-
187
- ob_start();
188
-
189
- do_action( 'cartflows_checkout_form_before', $checkout_id );
190
-
191
- $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
192
-
193
- $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
194
-
195
- $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
196
-
197
- if ( file_exists( $template_layout ) ) {
198
- include $template_layout;
199
- } else {
200
- include $template_default;
201
- }
202
-
203
- $output .= ob_get_clean();
204
-
205
- return $output;
206
- }
207
-
208
- /**
209
- * Configure Cart Data.
210
- *
211
- * @since 1.0.0
212
- *
213
- * @return void
214
- */
215
- function preconfigured_cart_data() {
216
-
217
- if ( is_admin() ) {
218
- return;
219
- }
220
-
221
- global $post;
222
-
223
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
224
-
225
- if ( wp_doing_ajax() ) {
226
-
227
- return;
228
- } else {
229
-
230
- if ( _is_wcf_checkout_type() ) {
231
- $checkout_id = $post->ID;
232
- } else {
233
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
234
- }
235
-
236
- do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
237
-
238
- $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
239
-
240
- if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
241
- $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
242
- } else {
243
- $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
244
- }
245
-
246
- if ( ! is_array( $products ) ) {
247
-
248
- if ( 'dummy' === $products ) {
249
-
250
- $args = array(
251
- 'posts_per_page' => 1,
252
- 'orderby' => 'rand',
253
- 'post_type' => 'product',
254
- 'meta_query' => array(
255
- // Exclude out of stock products.
256
- array(
257
- 'key' => '_stock_status',
258
- 'value' => 'outofstock',
259
- 'compare' => 'NOT IN',
260
- ),
261
- ),
262
- 'tax_query' => array(
263
- array(
264
- 'taxonomy' => 'product_type',
265
- 'field' => 'slug',
266
- 'terms' => 'simple',
267
- ),
268
- ),
269
- );
270
-
271
- $random_product = get_posts( $args );
272
-
273
- if ( isset( $random_product[0]->ID ) ) {
274
- $products = array(
275
- array(
276
- 'product' => $random_product[0]->ID,
277
- ),
278
- );
279
- } else {
280
- return;
281
- }
282
- } else {
283
- return;
284
- }
285
- }
286
-
287
- if ( is_array( $products ) && count( $products ) < 1 ) {
288
-
289
- return;
290
- }
291
- /* Empty the current cart */
292
- WC()->cart->empty_cart();
293
-
294
- /* Set customer session if not set */
295
- if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
296
- WC()->session->set_customer_session_cookie( true );
297
- }
298
-
299
- $cart_product_count = 0;
300
-
301
- foreach ( $products as $index => $data ) {
302
-
303
- if ( ! isset( $data['product'] ) ) {
304
- return;
305
- }
306
-
307
- if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
308
- break;
309
- }
310
-
311
- $product_id = $data['product'];
312
- $_product = wc_get_product( $product_id );
313
-
314
- if ( ! empty( $_product ) ) {
315
-
316
- $quantity = 1;
317
-
318
- if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
319
-
320
- if ( $_product->is_type( 'variable' ) ) {
321
-
322
- $default_attributes = $_product->get_default_attributes();
323
-
324
- if ( ! empty( $default_attributes ) ) {
325
-
326
- foreach ( $_product->get_children() as $variation_id ) {
327
-
328
- $single_variation = new WC_Product_Variation( $variation_id );
329
-
330
- if ( $default_attributes == $single_variation->get_attributes() ) {
331
- WC()->cart->add_to_cart( $variation_id, $quantity );
332
- $cart_product_count++;
333
- }
334
- }
335
- } else {
336
-
337
- $product_childrens = $_product->get_children();
338
-
339
- if ( isset( $product_childrens[0] ) ) {
340
- WC()->cart->add_to_cart( $product_childrens[0], $quantity );
341
- $cart_product_count++;
342
- } else {
343
- echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
344
- }
345
- }
346
- } else {
347
- WC()->cart->add_to_cart( $product_id, $quantity );
348
- $cart_product_count++;
349
- }
350
- } else {
351
-
352
- echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
353
- // WC()->cart->add_to_cart( $product_id, $quantity );.
354
- }
355
- }
356
- }
357
-
358
- do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
359
- do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
360
- }
361
- }
362
- }
363
-
364
- /**
365
- * Load shortcode data.
366
- *
367
- * @return void
368
- */
369
- function shortcode_load_data() {
370
-
371
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
372
-
373
- add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
374
-
375
- add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
376
-
377
- /* Show notices if cart has errors */
378
- add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
379
-
380
- add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
381
-
382
- add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
383
-
384
- // Outputting the hidden field in checkout page.
385
- add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
386
- add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
387
-
388
- remove_all_actions( 'woocommerce_checkout_billing' );
389
- remove_all_actions( 'woocommerce_checkout_shipping' );
390
-
391
- // Hook in actions once.
392
- add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
393
- add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
394
-
395
- remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
396
-
397
- add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
398
-
399
- add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
400
-
401
- add_filter( 'woocommerce_cart_totals_coupon_html', array( $this, 'remove_coupon_text' ) );
402
- global $post;
403
-
404
- if ( _is_wcf_checkout_type() ) {
405
- $checkout_id = $post->ID;
406
- } else {
407
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
408
- }
409
-
410
- do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
411
- }
412
- }
413
-
414
- /**
415
- * Render checkout ID hidden field.
416
- *
417
- * @param array $checkout checkout session data.
418
- * @return void
419
- */
420
- function checkout_shortcode_post_id( $checkout ) {
421
-
422
- global $post;
423
-
424
- if ( _is_wcf_checkout_type() ) {
425
- $checkout_id = $post->ID;
426
- } else {
427
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
428
- }
429
-
430
- $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
431
-
432
- echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
433
- echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
434
- }
435
-
436
- /**
437
- * Load shortcode scripts.
438
- *
439
- * @return void
440
- */
441
- function shortcode_scripts() {
442
-
443
- wp_enqueue_style( 'wcf-checkout-template', wcf()->utils->get_css_url( 'checkout-template' ), '', CARTFLOWS_VER );
444
-
445
- wp_enqueue_script(
446
- 'wcf-checkout-template',
447
- wcf()->utils->get_js_url( 'checkout-template' ),
448
- array( 'jquery' ),
449
- CARTFLOWS_VER,
450
- true
451
- );
452
-
453
- do_action( 'cartflows_checkout_scripts' );
454
-
455
- $style = $this->generate_style();
456
-
457
- wp_add_inline_style( 'wcf-checkout-template', $style );
458
-
459
- }
460
-
461
- /**
462
- * Load compatibility scripts.
463
- *
464
- * @return void
465
- */
466
- function compatibility_scripts() {
467
-
468
- global $post;
469
-
470
- if ( _is_wcf_checkout_type() ) {
471
- $checkout_id = $post->ID;
472
- } else {
473
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
474
- }
475
-
476
- // Add DIVI Compatibility css if DIVI theme is enabled.
477
- if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
478
- Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
479
- ) {
480
- wp_enqueue_style( 'wcf-checkout-template-divi', wcf()->utils->get_css_url( 'checkout-template-divi' ), '', CARTFLOWS_VER );
481
- }
482
-
483
- // Add Flatsome Compatibility css if Flatsome theme is enabled.
484
- if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
485
- wp_enqueue_style( 'wcf-checkout-template-flatsome', wcf()->utils->get_css_url( 'checkout-template-flatsome' ), '', CARTFLOWS_VER );
486
- }
487
-
488
- // Add The7 Compatibility css if The7 theme is enabled.
489
- if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
490
- wp_enqueue_style( 'wcf-checkout-template-the-seven', wcf()->utils->get_css_url( 'checkout-template-the-seven' ), '', CARTFLOWS_VER );
491
- }
492
- }
493
-
494
- /**
495
- * Generate styles.
496
- *
497
- * @return string
498
- */
499
- function generate_style() {
500
-
501
- global $post;
502
-
503
- if ( _is_wcf_checkout_type() ) {
504
- $checkout_id = $post->ID;
505
- } else {
506
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
507
- }
508
-
509
- CartFlows_Font_Families::render_fonts( $checkout_id );
510
-
511
- $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
512
-
513
- $base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
514
-
515
- $header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
516
-
517
- /*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
518
- $r = '';
519
- $g = '';
520
- $b = '';
521
-
522
- $field_tb_padding = '';
523
- $field_lr_padding = '';
524
-
525
- $field_heading_color = '';
526
- $field_color = '';
527
- $field_bg_color = '';
528
- $field_border_color = '';
529
- $field_label_color = '';
530
- $submit_tb_padding = '';
531
- $submit_lr_padding = '';
532
- $hl_bg_color = '';
533
- $field_input_size = '';
534
- $box_border_color = '';
535
- $section_bg_color = '';
536
- $submit_button_height = '';
537
- $submit_color = '';
538
- $submit_bg_color = $primary_color;
539
- $submit_border_color = $primary_color;
540
-
541
- $submit_hover_color = '';
542
- $submit_bg_hover_color = $primary_color;
543
- $submit_border_hover_color = $primary_color;
544
-
545
- $section_heading_color = '';
546
-
547
- $is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
548
-
549
- $button_font_family = '';
550
- $button_font_weight = '';
551
- $input_font_family = '';
552
- $input_font_weight = '';
553
- $heading_font_family = '';
554
- $heading_font_weight = '';
555
- $base_font_family = $base_font_family;
556
- /*$base_font_weight = $base_font_weight;*/
557
-
558
- if ( 'yes' == $is_advance_option ) {
559
-
560
- /**
561
- * Get Font Family and Font Weight weight values
562
- */
563
- $section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
564
-
565
- $heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
566
- $heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
567
- $section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
568
- $button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
569
- $button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
570
- $input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
571
- $input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
572
- $field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
573
- $field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
574
- $field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
575
-
576
- $field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
577
-
578
- $field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
579
-
580
- $field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
581
-
582
- $field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
583
-
584
- $field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
585
-
586
- $submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
587
-
588
- $submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
589
-
590
- $submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
591
-
592
- $submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
593
-
594
- $submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
595
-
596
- $submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
597
-
598
- $submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
599
-
600
- $submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
601
-
602
- $hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
603
-
604
- $box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
605
-
606
- $submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
607
-
608
- /**
609
- * Get font values
610
- */
611
-
612
- if ( 'custom' == $submit_button_height ) {
613
- $submit_button_height = '38px';
614
- }
615
-
616
- if ( 'custom' == $field_input_size ) {
617
- $field_input_size = '38px';
618
- }
619
- }
620
- if ( isset( $primary_color ) ) {
621
-
622
- list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' );
623
- }
624
- $output = "
625
- .wcf-embed-checkout-form .wcf-checkout-header-image img{
626
- width: {$header_logo_width}px;
627
- }
628
- .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
629
- .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
630
- color: {$primary_color};
631
- }
632
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
633
- background-color: {$primary_color};
634
- }
635
- .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
636
- .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
637
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
638
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
639
- border-color: {$primary_color};
640
- box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
641
- }
642
- .wcf-embed-checkout-form .woocommerce-checkout label{
643
- color: {$field_label_color};
644
- }
645
- .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
646
- background-color: {$hl_bg_color};
647
- font-family: {$input_font_family};
648
- font-weight: {$input_font_weight};
649
- }
650
-
651
- .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
652
- .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
653
- .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
654
- {
655
- border-bottom-color: {$hl_bg_color};
656
- border-right-color: transparent;
657
- border-left-color: transparent;
658
- border-top-color: transparent;
659
- position: absolute;
660
- }
661
-
662
- .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
663
- .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
664
- font-family: {$input_font_family};
665
- font-weight: {$input_font_weight};
666
- }
667
-
668
- .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
669
- .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
670
- .wcf-embed-checkout-form .woocommerce form .form-row textarea,
671
- .wcf-embed-checkout-form .select2-container--default .select2-selection--single {
672
- color: {$field_color};
673
- background: {$field_bg_color};
674
- border-color: {$field_border_color};
675
- padding-top: {$field_tb_padding}px;
676
- padding-bottom: {$field_tb_padding}px;
677
- padding-left: {$field_lr_padding}px;
678
- padding-right: {$field_lr_padding}px;
679
- min-height: {$field_input_size};
680
- font-family: {$input_font_family};
681
- font-weight: {$input_font_weight};
682
- }
683
-
684
- .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
685
- .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
686
- .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
687
- .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
688
- .wcf-embed-checkout-form .woocommerce-checkout #payment,
689
- .wcf-embed-checkout-form .woocommerce form.checkout_coupon
690
- {
691
- background-color: {$section_bg_color};
692
- border-color: {$box_border_color};
693
- font-family: {$input_font_family};
694
- font-weight: {$input_font_weight};
695
- }
696
-
697
- .woocommerce table.shop_table th{
698
- color: {$field_label_color};
699
- }
700
- /*.wcf-embed-checkout-form .woocommerce .woocommerce-info,
701
- .wcf-embed-checkout-form .woocommerce-message{
702
- border-top-color: {$primary_color};
703
- background-color: {$hl_bg_color};
704
- }*/
705
- .wcf-embed-checkout-form .woocommerce a{
706
- color: {$primary_color};
707
- }
708
- .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
709
- color: {$field_color};
710
- }
711
- .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
712
- color: {$field_color};
713
- }
714
- .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
715
- color: {$field_color};
716
- }
717
- .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
718
- color: {$field_color};
719
- }
720
- .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
721
- color: {$field_color};
722
- }
723
- .wcf-embed-checkout-form .woocommerce form p.form-row label {
724
- color: {$field_label_color};
725
- font-family: {$input_font_family};
726
- font-weight: {$input_font_weight};
727
- }
728
- .wcf-embed-checkout-form .woocommerce #order_review button,
729
- .wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
730
- .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
731
- color: {$submit_color};
732
- background: {$submit_bg_color};
733
- padding-top: {$submit_tb_padding}px;
734
- padding-bottom: {$submit_tb_padding}px;
735
- padding-left: {$submit_lr_padding}px;
736
- padding-right: {$submit_lr_padding}px;
737
- border-color: {$submit_border_color};
738
- min-height: {$submit_button_height};
739
- font-family: {$button_font_family};
740
- font-weight: {$button_font_weight};
741
- }
742
- .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
743
- .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
744
- background: {$submit_bg_color};
745
- border: 1px {$submit_border_color} solid;
746
- color: {$submit_color};
747
- min-height: {$submit_button_height};
748
- font-family: {$button_font_family};
749
- font-weight: {$button_font_weight};
750
- }
751
- .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
752
- .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
753
- .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
754
- .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
755
- color: {$submit_hover_color};
756
- background-color: {$submit_bg_hover_color};
757
- border-color: {$submit_border_hover_color};
758
- }
759
- .wcf-embed-checkout-form .woocommerce h3,
760
- .wcf-embed-checkout-form .woocommerce h3 span,
761
- .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
762
- color: {$section_heading_color};
763
- font-family: {$heading_font_family};
764
- font-weight: {$heading_font_weight};
765
- }
766
- .wcf-embed-checkout-form .woocommerce-info::before,
767
- .wcf-embed-checkout-form .woocommerce-message::before{
768
- color: {$primary_color};
769
- }
770
- .wcf-embed-checkout-form{
771
- font-family: {$base_font_family};
772
- }
773
- img.emoji, img.wp-smiley {}";
774
-
775
- return $output;
776
- }
777
-
778
- /**
779
- * Get ajax end points.
780
- *
781
- * @param string $endpoint_url end point URL.
782
- * @return string
783
- */
784
- function get_ajax_endpoint( $endpoint_url ) {
785
-
786
- global $post;
787
-
788
- if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
789
-
790
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
791
-
792
- if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
793
-
794
- $query_args = array(
795
- 'wc-ajax' => '%%endpoint%%',
796
- );
797
-
798
- $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
799
- $uri = $uri[0];
800
-
801
- $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
802
- }
803
- }
804
- }
805
-
806
- return $endpoint_url;
807
- }
808
-
809
-
810
- /**
811
- * Save checkout fields.
812
- *
813
- * @param int $order_id order id.
814
- * @param array $posted posted data.
815
- * @return void
816
- */
817
- function save_checkout_fields( $order_id, $posted ) {
818
-
819
- if ( isset( $_POST['_wcf_checkout_id'] ) ) {
820
-
821
- $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
822
-
823
- update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
824
-
825
- /*
826
- Custom Field To Do
827
- $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
828
-
829
- if ( 'yes' === $custom_fields ) {
830
-
831
- $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
832
-
833
- foreach ( $billing_fields as $field => $data ) {
834
-
835
- if ( isset( $data['custom'] ) && $data['custom'] ) {
836
-
837
- if ( isset( $_POST[ $field ] ) ) {
838
- update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
839
- }
840
- }
841
- }
842
-
843
- $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
844
-
845
- foreach ( $shipping_fields as $field => $data ) {
846
-
847
- if ( isset( $data['custom'] ) && $data['custom'] ) {
848
-
849
- if ( isset( $_POST[ $field ] ) ) {
850
- update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
851
- }
852
- }
853
- }
854
- }
855
- */
856
- if ( isset( $_POST['_wcf_flow_id'] ) ) {
857
-
858
- $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
859
-
860
- update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
861
- }
862
- }
863
-
864
- }
865
-
866
- /**
867
- * Enable Logo In Header Of Checkout Page
868
- *
869
- * @return void
870
- */
871
- function enable_logo_in_header() {
872
- global $post;
873
-
874
- if ( _is_wcf_checkout_type() ) {
875
- $checkout_id = $post->ID;
876
- } else {
877
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
878
- }
879
-
880
- $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
881
- $add_image_markup = '';
882
-
883
- if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
884
- $add_image_markup = '<div class="wcf-checkout-header-image">';
885
- $add_image_markup .= '<img src="' . $header_logo_image . '" />';
886
- $add_image_markup .= '</div>';
887
- }
888
-
889
- echo $add_image_markup;
890
- }
891
-
892
- /**
893
- * Add text to the bootom of the checkout page.
894
- *
895
- * @return void
896
- */
897
- function show_cartflows_copyright_message() {
898
- $output_string = '';
899
-
900
- $output_string .= '<div class="wcf-footer-primary">';
901
- $output_string .= '<div class="wcf-footer-content">';
902
- $output_string .= '<p class="wcf-footer-message">';
903
- $output_string .= 'Checkout powered by CartFlows';
904
- $output_string .= '</p>';
905
- $output_string .= '</div>';
906
- $output_string .= '</div>';
907
-
908
- echo $output_string;
909
- }
910
-
911
- /**
912
- * Redirect users to our checkout if hidden param
913
- *
914
- * @param string $redirect redirect url.
915
- * @param object $user user.
916
- * @return string
917
- */
918
- function after_login_redirect( $redirect, $user ) {
919
-
920
- if ( isset( $_POST['_wcf_checkout_id'] ) ) {
921
-
922
- $checkout_id = intval( $_POST['_wcf_checkout_id'] );
923
-
924
- $redirect = get_permalink( $checkout_id );
925
- }
926
-
927
- return $redirect;
928
- }
929
-
930
- /**
931
- * Display coupon code field after review order fields.
932
- */
933
- function display_custom_coupon_field() {
934
-
935
- $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
936
- $show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
937
-
938
- if ( ! ( $coupon_enabled && $show_coupon ) ) {
939
- return;
940
-
941
- }
942
-
943
- ob_start();
944
- ?>
945
- <div class="wcf-custom-coupon-field">
946
- <div class="wcf-coupon-col-1">
947
- <span>
948
- <input type="text" name="coupon_code" class="input-text wcf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
949
- </span>
950
- </div>
951
- <div class="wcf-coupon-col-2">
952
- <span>
953
- <button type="button" class="button wcf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
954
- </span>
955
- </div>
956
- </div>
957
- <?php
958
- echo ob_get_clean();
959
- }
960
-
961
- /**
962
- * Apply filter to change class of remove coupon field.
963
- *
964
- * @param string $coupon coupon.
965
- * @return string
966
- */
967
- function remove_coupon_text( $coupon ) {
968
-
969
- $coupon = str_replace( 'woocommerce-remove-coupon', 'wcf-remove-coupon', $coupon );
970
- return $coupon;
971
-
972
- }
973
- /**
974
- * Apply filter to change the placeholder text of coupon field.
975
- *
976
- * @return string
977
- */
978
- function coupon_field_placeholder() {
979
- return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
980
- }
981
-
982
- /**
983
- * Apply filter to change the button text of coupon field.
984
- *
985
- * @return string
986
- */
987
- function coupon_button_text() {
988
- return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
989
- }
990
-
991
- /**
992
- * Apply coupon on submit of custom coupon form.
993
- */
994
- function apply_coupon() {
995
-
996
- $response = '';
997
-
998
- check_ajax_referer( 'wcf-apply-coupon', 'security' );
999
- if ( ! empty( $_POST['coupon_code'] ) ) {
1000
- $result = WC()->cart->add_discount( sanitize_text_field( $_POST['coupon_code'] ) );
1001
- } else {
1002
- wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' );
1003
- }
1004
-
1005
- $response = array(
1006
- 'status' => $result,
1007
- 'msg' => wc_print_notices( true ),
1008
- );
1009
-
1010
- echo json_encode( $response );
1011
-
1012
- die();
1013
- }
1014
-
1015
-
1016
- /**
1017
- * Added ajax nonce to localize variable.
1018
- *
1019
- * @param array $vars localize variables.
1020
- */
1021
- function add_localize_vars( $vars ) {
1022
-
1023
- $vars['wcf_validate_coupon_nonce'] = wp_create_nonce( 'wcf-apply-coupon' );
1024
-
1025
- $vars['wcf_validate_remove_coupon_nonce'] = wp_create_nonce( 'wcf-remove-coupon' );
1026
-
1027
- $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1028
-
1029
- return $vars;
1030
- }
1031
-
1032
- /**
1033
- * Add custom class to the fields to change the UI to three column.
1034
- *
1035
- * @param array $fields fields.
1036
- */
1037
- function add_three_column_layout_fields( $fields ) {
1038
-
1039
- if ( empty( $fields['billing']['billing_address_2'] ) ) {
1040
-
1041
- if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1042
- $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1043
- }
1044
- }
1045
-
1046
- if ( ! empty( $fields['billing']['billing_company'] ) ) {
1047
-
1048
- if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1049
- $fields['billing']['billing_company']['class'][] = 'form-row-full';
1050
- }
1051
- }
1052
-
1053
- if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1054
-
1055
- if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1056
- $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1057
- }
1058
- }
1059
-
1060
- if ( ! empty( $fields['billing']['billing_country'] ) ) {
1061
-
1062
- if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1063
- $fields['billing']['billing_country']['class'][] = 'form-row-full';
1064
- }
1065
- }
1066
-
1067
- if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1068
-
1069
- if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1070
- $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1071
- }
1072
- }
1073
-
1074
- if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1075
-
1076
- if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1077
- $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1078
- }
1079
- }
1080
-
1081
- if ( ! empty( $fields['billing']['billing_email'] ) ) {
1082
-
1083
- if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1084
- $fields['billing']['billing_email']['class'][] = 'form-row-full';
1085
- }
1086
- }
1087
-
1088
- if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1089
-
1090
- if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1091
- $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1092
- }
1093
- }
1094
-
1095
- if ( isset( $fields['billing']['billing_city'] ) &&
1096
- isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1097
-
1098
- $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1099
- $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1100
- $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1101
- }
1102
-
1103
- if ( isset( $fields['shipping']['shipping_city'] ) &&
1104
- isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1105
-
1106
- $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1107
- $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1108
- $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1109
- }
1110
-
1111
- return $fields;
1112
- }
1113
-
1114
- /**
1115
- * Add opening dev
1116
- *
1117
- * @since 1.0.0
1118
- */
1119
- function order_wrap_div_start() {
1120
-
1121
- echo "<div class='wcf-order-wrap'> ";
1122
- }
1123
-
1124
- /**
1125
- * Add closing dev
1126
- *
1127
- * @since 1.0.0
1128
- */
1129
- function order_wrap_div_end() {
1130
-
1131
- echo '</div> ';
1132
- }
1133
-
1134
- /**
1135
- * Remove coupon.
1136
- */
1137
- function remove_coupon() {
1138
-
1139
- check_ajax_referer( 'wcf-remove-coupon', 'security' );
1140
- $coupon = isset( $_POST['coupon_code'] ) ? wc_clean( $_POST['coupon_code'] ) : false;
1141
-
1142
- if ( empty( $coupon ) ) {
1143
- echo "<div class='woocommerce-error'>Sorry there was a problem removing this coupon.";
1144
- } else {
1145
- WC()->cart->remove_coupon( $coupon );
1146
- echo "<div class='woocommerce-error'>Coupon has been removed.</div>";
1147
- }
1148
- wc_print_notices();
1149
- wp_die();
1150
- }
1151
-
1152
- }
1153
-
1154
- /**
1155
- * Kicking this off by calling 'get_instance()' method
1156
- */
1157
- Cartflows_Checkout_Markup::get_instance();
1
+ <?php
2
+ /**
3
+ * Checkout markup.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Checkout Markup
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Checkout_Markup {
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var object instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ */
25
+ public static function get_instance() {
26
+ if ( ! isset( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct() {
36
+
37
+ /* Set is checkout flag */
38
+ add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
39
+
40
+ add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_checkout_fields' ), 10, 2 );
41
+
42
+ /* Show notice if cart is empty */
43
+ add_action( 'cartflows_checkout_cart_empty', array( $this, 'display_woo_notices' ) );
44
+
45
+ /* Checkout Shortcode */
46
+ add_shortcode( 'cartflows_checkout', array( $this, 'checkout_shortcode_markup' ) );
47
+
48
+ /* Preconfigured cart data */
49
+ add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
50
+
51
+ /* Embed Checkout */
52
+ add_action( 'wp', array( $this, 'shortcode_load_data' ), 999 );
53
+
54
+ /* Ajax Endpoint */
55
+ add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ) );
56
+
57
+ add_filter( 'cartflows_add_before_main_section', array( $this, 'enable_logo_in_header' ) );
58
+
59
+ add_filter( 'cartflows_primary_container_bottom', array( $this, 'show_cartflows_copyright_message' ) );
60
+
61
+ add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
62
+
63
+ add_action( 'wp_ajax_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64
+ add_action( 'wp_ajax_nopriv_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
65
+
66
+ add_filter( 'global_cartflows_js_localize', array( $this, 'add_localize_vars' ) );
67
+
68
+ /* Global Checkout */
69
+ add_action( 'template_redirect', array( $this, 'global_checkout_template_redirect' ), 1 );
70
+
71
+ add_action( 'wp_ajax_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
72
+ add_action( 'wp_ajax_nopriv_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
73
+
74
+ }
75
+
76
+ /**
77
+ * Display all WooCommerce notices.
78
+ *
79
+ * @since 1.1.5
80
+ */
81
+ function display_woo_notices() {
82
+
83
+ if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
84
+ woocommerce_output_all_notices();
85
+ }
86
+ }
87
+
88
+
89
+ /**
90
+ * Redirect from default to the global checkout page
91
+ *
92
+ * @since 1.0.0
93
+ */
94
+ function global_checkout_template_redirect() {
95
+
96
+ if ( ! is_checkout() ) {
97
+ return;
98
+ }
99
+
100
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
101
+ return;
102
+ }
103
+
104
+ // redirect only for cartflows checkout pages.
105
+ $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
106
+ $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
107
+
108
+ $common = Cartflows_Helper::get_common_settings();
109
+
110
+ $global_checkout = $common['global_checkout'];
111
+
112
+ if (
113
+ // ignore on order-pay.
114
+ false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
115
+ // ignore on TY page.
116
+ false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
117
+ ) {
118
+
119
+ if ( '' !== $global_checkout ) {
120
+
121
+ $link = get_permalink( $global_checkout );
122
+
123
+ if ( ! empty( $link ) ) {
124
+
125
+ wp_redirect( $link );
126
+ die();
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Check for checkout flag
134
+ *
135
+ * @param bool $is_checkout is checkout.
136
+ *
137
+ * @return bool
138
+ */
139
+ function woo_checkout_flag( $is_checkout ) {
140
+
141
+ if ( ! is_admin() ) {
142
+
143
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
144
+
145
+ $is_checkout = true;
146
+ }
147
+ }
148
+
149
+ return $is_checkout;
150
+ }
151
+
152
+ /**
153
+ * Render checkout shortcode markup.
154
+ *
155
+ * @param array $atts attributes.
156
+ * @return string
157
+ */
158
+ function checkout_shortcode_markup( $atts ) {
159
+
160
+ if ( ! function_exists( 'wc_print_notices' ) ) {
161
+ return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
162
+ }
163
+
164
+ $atts = shortcode_atts(
165
+ array(
166
+ 'id' => 0,
167
+ ),
168
+ $atts
169
+ );
170
+
171
+ $checkout_id = intval( $atts['id'] );
172
+
173
+ if ( empty( $checkout_id ) ) {
174
+
175
+ if ( ! _is_wcf_checkout_type() ) {
176
+
177
+ return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
178
+ }
179
+
180
+ global $post;
181
+
182
+ $checkout_id = intval( $post->ID );
183
+ }
184
+
185
+ $output = '';
186
+
187
+ ob_start();
188
+
189
+ do_action( 'cartflows_checkout_form_before', $checkout_id );
190
+
191
+ $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
192
+
193
+ $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
194
+
195
+ $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
196
+
197
+ if ( file_exists( $template_layout ) ) {
198
+ include $template_layout;
199
+ } else {
200
+ include $template_default;
201
+ }
202
+
203
+ $output .= ob_get_clean();
204
+
205
+ return $output;
206
+ }
207
+
208
+ /**
209
+ * Configure Cart Data.
210
+ *
211
+ * @since 1.0.0
212
+ *
213
+ * @return void
214
+ */
215
+ function preconfigured_cart_data() {
216
+
217
+ if ( is_admin() ) {
218
+ return;
219
+ }
220
+
221
+ global $post;
222
+
223
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
224
+
225
+ if ( wp_doing_ajax() ) {
226
+
227
+ return;
228
+ } else {
229
+
230
+ if ( _is_wcf_checkout_type() ) {
231
+ $checkout_id = $post->ID;
232
+ } else {
233
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
234
+ }
235
+
236
+ do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
237
+
238
+ $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
239
+
240
+ if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
241
+ $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
242
+ } else {
243
+ $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
244
+ }
245
+
246
+ if ( ! is_array( $products ) ) {
247
+
248
+ if ( 'dummy' === $products ) {
249
+
250
+ $args = array(
251
+ 'posts_per_page' => 1,
252
+ 'orderby' => 'rand',
253
+ 'post_type' => 'product',
254
+ 'meta_query' => array(
255
+ // Exclude out of stock products.
256
+ array(
257
+ 'key' => '_stock_status',
258
+ 'value' => 'outofstock',
259
+ 'compare' => 'NOT IN',
260
+ ),
261
+ ),
262
+ 'tax_query' => array(
263
+ array(
264
+ 'taxonomy' => 'product_type',
265
+ 'field' => 'slug',
266
+ 'terms' => 'simple',
267
+ ),
268
+ ),
269
+ );
270
+
271
+ $random_product = get_posts( $args );
272
+
273
+ if ( isset( $random_product[0]->ID ) ) {
274
+ $products = array(
275
+ array(
276
+ 'product' => $random_product[0]->ID,
277
+ ),
278
+ );
279
+ } else {
280
+ return;
281
+ }
282
+ } else {
283
+ return;
284
+ }
285
+ }
286
+
287
+ if ( is_array( $products ) && count( $products ) < 1 ) {
288
+
289
+ return;
290
+ }
291
+ /* Empty the current cart */
292
+ WC()->cart->empty_cart();
293
+
294
+ /* Set customer session if not set */
295
+ if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
296
+ WC()->session->set_customer_session_cookie( true );
297
+ }
298
+
299
+ $cart_product_count = 0;
300
+
301
+ foreach ( $products as $index => $data ) {
302
+
303
+ if ( ! isset( $data['product'] ) ) {
304
+ return;
305
+ }
306
+
307
+ if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
308
+ break;
309
+ }
310
+
311
+ $product_id = $data['product'];
312
+ $_product = wc_get_product( $product_id );
313
+
314
+ if ( ! empty( $_product ) ) {
315
+
316
+ $quantity = 1;
317
+
318
+ if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
319
+
320
+ if ( $_product->is_type( 'variable' ) ) {
321
+
322
+ $default_attributes = $_product->get_default_attributes();
323
+
324
+ if ( ! empty( $default_attributes ) ) {
325
+
326
+ foreach ( $_product->get_children() as $variation_id ) {
327
+
328
+ $single_variation = new WC_Product_Variation( $variation_id );
329
+
330
+ if ( $default_attributes == $single_variation->get_attributes() ) {
331
+ WC()->cart->add_to_cart( $variation_id, $quantity );
332
+ $cart_product_count++;
333
+ }
334
+ }
335
+ } else {
336
+
337
+ $product_childrens = $_product->get_children();
338
+
339
+ if ( isset( $product_childrens[0] ) ) {
340
+ WC()->cart->add_to_cart( $product_childrens[0], $quantity );
341
+ $cart_product_count++;
342
+ } else {
343
+ echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
344
+ }
345
+ }
346
+ } else {
347
+ WC()->cart->add_to_cart( $product_id, $quantity );
348
+ $cart_product_count++;
349
+ }
350
+ } else {
351
+
352
+ echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
353
+ // WC()->cart->add_to_cart( $product_id, $quantity );.
354
+ }
355
+ }
356
+ }
357
+
358
+ do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
359
+ do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
360
+ }
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Load shortcode data.
366
+ *
367
+ * @return void
368
+ */
369
+ function shortcode_load_data() {
370
+
371
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
372
+
373
+ add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
374
+
375
+ add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
376
+
377
+ /* Show notices if cart has errors */
378
+ add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
379
+
380
+ add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
381
+
382
+ add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
383
+
384
+ // Outputting the hidden field in checkout page.
385
+ add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
386
+ add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
387
+
388
+ remove_all_actions( 'woocommerce_checkout_billing' );
389
+ remove_all_actions( 'woocommerce_checkout_shipping' );
390
+
391
+ // Hook in actions once.
392
+ add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
393
+ add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
394
+
395
+ remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
396
+
397
+ add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
398
+
399
+ add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
400
+
401
+ add_filter( 'woocommerce_cart_totals_coupon_html', array( $this, 'remove_coupon_text' ) );
402
+ global $post;
403
+
404
+ if ( _is_wcf_checkout_type() ) {
405
+ $checkout_id = $post->ID;
406
+ } else {
407
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
408
+ }
409
+
410
+ do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
411
+ }
412
+ }
413
+
414
+ /**
415
+ * Render checkout ID hidden field.
416
+ *
417
+ * @param array $checkout checkout session data.
418
+ * @return void
419
+ */
420
+ function checkout_shortcode_post_id( $checkout ) {
421
+
422
+ global $post;
423
+
424
+ if ( _is_wcf_checkout_type() ) {
425
+ $checkout_id = $post->ID;
426
+ } else {
427
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
428
+ }
429
+
430
+ $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
431
+
432
+ echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
433
+ echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
434
+ }
435
+
436
+ /**
437
+ * Load shortcode scripts.
438
+ *
439
+ * @return void
440
+ */
441
+ function shortcode_scripts() {
442
+
443
+ wp_enqueue_style( 'wcf-checkout-template', wcf()->utils->get_css_url( 'checkout-template' ), '', CARTFLOWS_VER );
444
+
445
+ wp_enqueue_script(
446
+ 'wcf-checkout-template',
447
+ wcf()->utils->get_js_url( 'checkout-template' ),
448
+ array( 'jquery' ),
449
+ CARTFLOWS_VER,
450
+ true
451
+ );
452
+
453
+ do_action( 'cartflows_checkout_scripts' );
454
+
455
+ $style = $this->generate_style();
456
+
457
+ wp_add_inline_style( 'wcf-checkout-template', $style );
458
+
459
+ }
460
+
461
+ /**
462
+ * Load compatibility scripts.
463
+ *
464
+ * @return void
465
+ */
466
+ function compatibility_scripts() {
467
+
468
+ global $post;
469
+
470
+ if ( _is_wcf_checkout_type() ) {
471
+ $checkout_id = $post->ID;
472
+ } else {
473
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
474
+ }
475
+
476
+ // Add DIVI Compatibility css if DIVI theme is enabled.
477
+ if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
478
+ Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
479
+ ) {
480
+ wp_enqueue_style( 'wcf-checkout-template-divi', wcf()->utils->get_css_url( 'checkout-template-divi' ), '', CARTFLOWS_VER );
481
+ }
482
+
483
+ // Add Flatsome Compatibility css if Flatsome theme is enabled.
484
+ if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
485
+ wp_enqueue_style( 'wcf-checkout-template-flatsome', wcf()->utils->get_css_url( 'checkout-template-flatsome' ), '', CARTFLOWS_VER );
486
+ }
487
+
488
+ // Add The7 Compatibility css if The7 theme is enabled.
489
+ if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
490
+ wp_enqueue_style( 'wcf-checkout-template-the-seven', wcf()->utils->get_css_url( 'checkout-template-the-seven' ), '', CARTFLOWS_VER );
491
+ }
492
+ }
493
+
494
+ /**
495
+ * Generate styles.
496
+ *
497
+ * @return string
498
+ */
499
+ function generate_style() {
500
+
501
+ global $post;
502
+
503
+ if ( _is_wcf_checkout_type() ) {
504
+ $checkout_id = $post->ID;
505
+ } else {
506
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
507
+ }
508
+
509
+ CartFlows_Font_Families::render_fonts( $checkout_id );
510
+
511
+ $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
512
+
513
+ $base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
514
+
515
+ $header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
516
+
517
+ /*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
518
+ $r = '';
519
+ $g = '';
520
+ $b = '';
521
+
522
+ $field_tb_padding = '';
523
+ $field_lr_padding = '';
524
+
525
+ $field_heading_color = '';
526
+ $field_color = '';
527
+ $field_bg_color = '';
528
+ $field_border_color = '';
529
+ $field_label_color = '';
530
+ $submit_tb_padding = '';
531
+ $submit_lr_padding = '';
532
+ $hl_bg_color = '';
533
+ $field_input_size = '';
534
+ $box_border_color = '';
535
+ $section_bg_color = '';
536
+ $submit_button_height = '';
537
+ $submit_color = '';
538
+ $submit_bg_color = $primary_color;
539
+ $submit_border_color = $primary_color;
540
+
541
+ $submit_hover_color = '';
542
+ $submit_bg_hover_color = $primary_color;
543
+ $submit_border_hover_color = $primary_color;
544
+
545
+ $section_heading_color = '';
546
+
547
+ $is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
548
+
549
+ $button_font_family = '';
550
+ $button_font_weight = '';
551
+ $input_font_family = '';
552
+ $input_font_weight = '';
553
+ $heading_font_family = '';
554
+ $heading_font_weight = '';
555
+ $base_font_family = $base_font_family;
556
+ /*$base_font_weight = $base_font_weight;*/
557
+
558
+ if ( 'yes' == $is_advance_option ) {
559
+
560
+ /**
561
+ * Get Font Family and Font Weight weight values
562
+ */
563
+ $section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
564
+
565
+ $heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
566
+ $heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
567
+ $section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
568
+ $button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
569
+ $button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
570
+ $input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
571
+ $input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
572
+ $field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
573
+ $field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
574
+ $field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
575
+
576
+ $field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
577
+
578
+ $field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
579
+
580
+ $field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
581
+
582
+ $field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
583
+
584
+ $field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
585
+
586
+ $submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
587
+
588
+ $submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
589
+
590
+ $submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
591
+
592
+ $submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
593
+
594
+ $submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
595
+
596
+ $submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
597
+
598
+ $submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
599
+
600
+ $submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
601
+
602
+ $hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
603
+
604
+ $box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
605
+
606
+ $submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
607
+
608
+ /**
609
+ * Get font values
610
+ */
611
+
612
+ if ( 'custom' == $submit_button_height ) {
613
+ $submit_button_height = '38px';
614
+ }
615
+
616
+ if ( 'custom' == $field_input_size ) {
617
+ $field_input_size = '38px';
618
+ }
619
+ }
620
+ if ( isset( $primary_color ) ) {
621
+
622
+ list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' );
623
+ }
624
+ $output = "
625
+ .wcf-embed-checkout-form .wcf-checkout-header-image img{
626
+ width: {$header_logo_width}px;
627
+ }
628
+ .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
629
+ .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
630
+ color: {$primary_color};
631
+ }
632
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
633
+ background-color: {$primary_color};
634
+ }
635
+ .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
636
+ .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
637
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
638
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
639
+ border-color: {$primary_color};
640
+ box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
641
+ }
642
+ .wcf-embed-checkout-form .woocommerce-checkout label{
643
+ color: {$field_label_color};
644
+ }
645
+ .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
646
+ background-color: {$hl_bg_color};
647
+ font-family: {$input_font_family};
648
+ font-weight: {$input_font_weight};
649
+ }
650
+
651
+ .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
652
+ .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
653
+ .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
654
+ {
655
+ border-bottom-color: {$hl_bg_color};
656
+ border-right-color: transparent;
657
+ border-left-color: transparent;
658
+ border-top-color: transparent;
659
+ position: absolute;
660
+ }
661
+
662
+ .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
663
+ .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
664
+ font-family: {$input_font_family};
665
+ font-weight: {$input_font_weight};
666
+ }
667
+
668
+ .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
669
+ .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
670
+ .wcf-embed-checkout-form .woocommerce form .form-row textarea,
671
+ .wcf-embed-checkout-form .select2-container--default .select2-selection--single {
672
+ color: {$field_color};
673
+ background: {$field_bg_color};
674
+ border-color: {$field_border_color};
675
+ padding-top: {$field_tb_padding}px;
676
+ padding-bottom: {$field_tb_padding}px;
677
+ padding-left: {$field_lr_padding}px;
678
+ padding-right: {$field_lr_padding}px;
679
+ min-height: {$field_input_size};
680
+ font-family: {$input_font_family};
681
+ font-weight: {$input_font_weight};
682
+ }
683
+
684
+ .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
685
+ .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
686
+ .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
687
+ .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
688
+ .wcf-embed-checkout-form .woocommerce-checkout #payment,
689
+ .wcf-embed-checkout-form .woocommerce form.checkout_coupon
690
+ {
691
+ background-color: {$section_bg_color};
692
+ border-color: {$box_border_color};
693
+ font-family: {$input_font_family};
694
+ font-weight: {$input_font_weight};
695
+ }
696
+
697
+ .woocommerce table.shop_table th{
698
+ color: {$field_label_color};
699
+ }
700
+ /*.wcf-embed-checkout-form .woocommerce .woocommerce-info,
701
+ .wcf-embed-checkout-form .woocommerce-message{
702
+ border-top-color: {$primary_color};
703
+ background-color: {$hl_bg_color};
704
+ }*/
705
+ .wcf-embed-checkout-form .woocommerce a{
706
+ color: {$primary_color};
707
+ }
708
+ .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
709
+ color: {$field_color};
710
+ }
711
+ .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
712
+ color: {$field_color};
713
+ }
714
+ .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
715
+ color: {$field_color};
716
+ }
717
+ .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
718
+ color: {$field_color};
719
+ }
720
+ .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
721
+ color: {$field_color};
722
+ }
723
+ .wcf-embed-checkout-form .woocommerce form p.form-row label {
724
+ color: {$field_label_color};
725
+ font-family: {$input_font_family};
726
+ font-weight: {$input_font_weight};
727
+ }
728
+ .wcf-embed-checkout-form .woocommerce #order_review button,
729
+ .wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
730
+ .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
731
+ color: {$submit_color};
732
+ background: {$submit_bg_color};
733
+ padding-top: {$submit_tb_padding}px;
734
+ padding-bottom: {$submit_tb_padding}px;
735
+ padding-left: {$submit_lr_padding}px;
736
+ padding-right: {$submit_lr_padding}px;
737
+ border-color: {$submit_border_color};
738
+ min-height: {$submit_button_height};
739
+ font-family: {$button_font_family};
740
+ font-weight: {$button_font_weight};
741
+ }
742
+ .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
743
+ .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
744
+ background: {$submit_bg_color};
745
+ border: 1px {$submit_border_color} solid;
746
+ color: {$submit_color};
747
+ min-height: {$submit_button_height};
748
+ font-family: {$button_font_family};
749
+ font-weight: {$button_font_weight};
750
+ }
751
+ .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
752
+ .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
753
+ .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
754
+ .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
755
+ color: {$submit_hover_color};
756
+ background-color: {$submit_bg_hover_color};
757
+ border-color: {$submit_border_hover_color};
758
+ }
759
+ .wcf-embed-checkout-form .woocommerce h3,
760
+ .wcf-embed-checkout-form .woocommerce h3 span,
761
+ .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
762
+ color: {$section_heading_color};
763
+ font-family: {$heading_font_family};
764
+ font-weight: {$heading_font_weight};
765
+ }
766
+ .wcf-embed-checkout-form .woocommerce-info::before,
767
+ .wcf-embed-checkout-form .woocommerce-message::before{
768
+ color: {$primary_color};
769
+ }
770
+ .wcf-embed-checkout-form{
771
+ font-family: {$base_font_family};
772
+ }
773
+ img.emoji, img.wp-smiley {}";
774
+
775
+ return $output;
776
+ }
777
+
778
+ /**
779
+ * Get ajax end points.
780
+ *
781
+ * @param string $endpoint_url end point URL.
782
+ * @return string
783
+ */
784
+ function get_ajax_endpoint( $endpoint_url ) {
785
+
786
+ global $post;
787
+
788
+ if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
789
+
790
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
791
+
792
+ if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
793
+
794
+ $query_args = array(
795
+ 'wc-ajax' => '%%endpoint%%',
796
+ );
797
+
798
+ $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
799
+ $uri = $uri[0];
800
+
801
+ $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
802
+ }
803
+ }
804
+ }
805
+
806
+ return $endpoint_url;
807
+ }
808
+
809
+
810
+ /**
811
+ * Save checkout fields.
812
+ *
813
+ * @param int $order_id order id.
814
+ * @param array $posted posted data.
815
+ * @return void
816
+ */
817
+ function save_checkout_fields( $order_id, $posted ) {
818
+
819
+ if ( isset( $_POST['_wcf_checkout_id'] ) ) {
820
+
821
+ $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
822
+
823
+ update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
824
+
825
+ /*
826
+ Custom Field To Do
827
+ $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
828
+
829
+ if ( 'yes' === $custom_fields ) {
830
+
831
+ $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
832
+
833
+ foreach ( $billing_fields as $field => $data ) {
834
+
835
+ if ( isset( $data['custom'] ) && $data['custom'] ) {
836
+
837
+ if ( isset( $_POST[ $field ] ) ) {
838
+ update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
839
+ }
840
+ }
841
+ }
842
+
843
+ $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
844
+
845
+ foreach ( $shipping_fields as $field => $data ) {
846
+
847
+ if ( isset( $data['custom'] ) && $data['custom'] ) {
848
+
849
+ if ( isset( $_POST[ $field ] ) ) {
850
+ update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
851
+ }
852
+ }
853
+ }
854
+ }
855
+ */
856
+ if ( isset( $_POST['_wcf_flow_id'] ) ) {
857
+
858
+ $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
859
+
860
+ update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
861
+ }
862
+ }
863
+
864
+ }
865
+
866
+ /**
867
+ * Enable Logo In Header Of Checkout Page
868
+ *
869
+ * @return void
870
+ */
871
+ function enable_logo_in_header() {
872
+ global $post;
873
+
874
+ if ( _is_wcf_checkout_type() ) {
875
+ $checkout_id = $post->ID;
876
+ } else {
877
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
878
+ }
879
+
880
+ $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
881
+ $add_image_markup = '';
882
+
883
+ if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
884
+ $add_image_markup = '<div class="wcf-checkout-header-image">';
885
+ $add_image_markup .= '<img src="' . $header_logo_image . '" />';
886
+ $add_image_markup .= '</div>';
887
+ }
888
+
889
+ echo $add_image_markup;
890
+ }
891
+
892
+ /**
893
+ * Add text to the bootom of the checkout page.
894
+ *
895
+ * @return void
896
+ */
897
+ function show_cartflows_copyright_message() {
898
+ $output_string = '';
899
+
900
+ $output_string .= '<div class="wcf-footer-primary">';
901
+ $output_string .= '<div class="wcf-footer-content">';
902
+ $output_string .= '<p class="wcf-footer-message">';
903
+ $output_string .= 'Checkout powered by CartFlows';
904
+ $output_string .= '</p>';
905
+ $output_string .= '</div>';
906
+ $output_string .= '</div>';
907
+
908
+ echo $output_string;
909
+ }
910
+
911
+ /**
912
+ * Redirect users to our checkout if hidden param
913
+ *
914
+ * @param string $redirect redirect url.
915
+ * @param object $user user.
916
+ * @return string
917
+ */
918
+ function after_login_redirect( $redirect, $user ) {
919
+
920
+ if ( isset( $_POST['_wcf_checkout_id'] ) ) {
921
+
922
+ $checkout_id = intval( $_POST['_wcf_checkout_id'] );
923
+
924
+ $redirect = get_permalink( $checkout_id );
925
+ }
926
+
927
+ return $redirect;
928
+ }
929
+
930
+ /**
931
+ * Display coupon code field after review order fields.
932
+ */
933
+ function display_custom_coupon_field() {
934
+
935
+ $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
936
+ $show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
937
+
938
+ if ( ! ( $coupon_enabled && $show_coupon ) ) {
939
+ return;
940
+
941
+ }
942
+
943
+ ob_start();
944
+ ?>
945
+ <div class="wcf-custom-coupon-field">
946
+ <div class="wcf-coupon-col-1">
947
+ <span>
948
+ <input type="text" name="coupon_code" class="input-text wcf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
949
+ </span>
950
+ </div>
951
+ <div class="wcf-coupon-col-2">
952
+ <span>
953
+ <button type="button" class="button wcf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
954
+ </span>
955
+ </div>
956
+ </div>
957
+ <?php
958
+ echo ob_get_clean();
959
+ }
960
+
961
+ /**
962
+ * Apply filter to change class of remove coupon field.
963
+ *
964
+ * @param string $coupon coupon.
965
+ * @return string
966
+ */
967
+ function remove_coupon_text( $coupon ) {
968
+
969
+ $coupon = str_replace( 'woocommerce-remove-coupon', 'wcf-remove-coupon', $coupon );
970
+ return $coupon;
971
+
972
+ }
973
+ /**
974
+ * Apply filter to change the placeholder text of coupon field.
975
+ *
976
+ * @return string
977
+ */
978
+ function coupon_field_placeholder() {
979
+ return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
980
+ }
981
+
982
+ /**
983
+ * Apply filter to change the button text of coupon field.
984
+ *
985
+ * @return string
986
+ */
987
+ function coupon_button_text() {
988
+ return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
989
+ }
990
+
991
+ /**
992
+ * Apply coupon on submit of custom coupon form.
993
+ */
994
+ function apply_coupon() {
995
+
996
+ $response = '';
997
+
998
+ check_ajax_referer( 'wcf-apply-coupon', 'security' );
999
+ if ( ! empty( $_POST['coupon_code'] ) ) {
1000
+ $result = WC()->cart->add_discount( sanitize_text_field( $_POST['coupon_code'] ) );
1001
+ } else {
1002
+ wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' );
1003
+ }
1004
+
1005
+ $response = array(
1006
+ 'status' => $result,
1007
+ 'msg' => wc_print_notices( true ),
1008
+ );
1009
+
1010
+ echo json_encode( $response );
1011
+
1012
+ die();
1013
+ }
1014
+
1015
+
1016
+ /**
1017
+ * Added ajax nonce to localize variable.
1018
+ *
1019
+ * @param array $vars localize variables.
1020
+ */
1021
+ function add_localize_vars( $vars ) {
1022
+
1023
+ $vars['wcf_validate_coupon_nonce'] = wp_create_nonce( 'wcf-apply-coupon' );
1024
+
1025
+ $vars['wcf_validate_remove_coupon_nonce'] = wp_create_nonce( 'wcf-remove-coupon' );
1026
+
1027
+ $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1028
+
1029
+ return $vars;
1030
+ }
1031
+
1032
+ /**
1033
+ * Add custom class to the fields to change the UI to three column.
1034
+ *
1035
+ * @param array $fields fields.
1036
+ */
1037
+ function add_three_column_layout_fields( $fields ) {
1038
+
1039
+ if ( empty( $fields['billing']['billing_address_2'] ) ) {
1040
+
1041
+ if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1042
+ $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1043
+ }
1044
+ }
1045
+
1046
+ if ( ! empty( $fields['billing']['billing_company'] ) ) {
1047
+
1048
+ if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1049
+ $fields['billing']['billing_company']['class'][] = 'form-row-full';
1050
+ }
1051
+ }
1052
+
1053
+ if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1054
+
1055
+ if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1056
+ $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1057
+ }
1058
+ }
1059
+
1060
+ if ( ! empty( $fields['billing']['billing_country'] ) ) {
1061
+
1062
+ if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1063
+ $fields['billing']['billing_country']['class'][] = 'form-row-full';
1064
+ }
1065
+ }
1066
+
1067
+ if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1068
+
1069
+ if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1070
+ $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1071
+ }
1072
+ }
1073
+
1074
+ if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1075
+
1076
+ if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1077
+ $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1078
+ }
1079
+ }
1080
+
1081
+ if ( ! empty( $fields['billing']['billing_email'] ) ) {
1082
+
1083
+ if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1084
+ $fields['billing']['billing_email']['class'][] = 'form-row-full';
1085
+ }
1086
+ }
1087
+
1088
+ if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1089
+
1090
+ if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1091
+ $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1092
+ }
1093
+ }
1094
+
1095
+ if ( isset( $fields['billing']['billing_city'] ) &&
1096
+ isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1097
+
1098
+ $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1099
+ $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1100
+ $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1101
+ }
1102
+
1103
+ if ( isset( $fields['shipping']['shipping_city'] ) &&
1104
+ isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1105
+
1106
+ $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1107
+ $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1108
+ $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1109
+ }
1110
+
1111
+ return $fields;
1112
+ }
1113
+
1114
+ /**
1115
+ * Add opening dev
1116
+ *
1117
+ * @since 1.0.0
1118
+ */
1119
+ function order_wrap_div_start() {
1120
+
1121
+ echo "<div class='wcf-order-wrap'> ";
1122
+ }
1123
+
1124
+ /**
1125
+ * Add closing dev
1126
+ *
1127
+ * @since 1.0.0
1128
+ */
1129
+ function order_wrap_div_end() {
1130
+
1131
+ echo '</div> ';
1132
+ }
1133
+
1134
+ /**
1135
+ * Remove coupon.
1136
+ */
1137
+ function remove_coupon() {
1138
+
1139
+ check_ajax_referer( 'wcf-remove-coupon', 'security' );
1140
+ $coupon = isset( $_POST['coupon_code'] ) ? wc_clean( $_POST['coupon_code'] ) : false;
1141
+
1142
+ if ( empty( $coupon ) ) {
1143
+ echo "<div class='woocommerce-error'>Sorry there was a problem removing this coupon.";
1144
+ } else {
1145
+ WC()->cart->remove_coupon( $coupon );
1146
+ echo "<div class='woocommerce-error'>Coupon has been removed.</div>";
1147
+ }
1148
+ wc_print_notices();
1149
+ wp_die();
1150
+ }
1151
+
1152
+ }
1153
+
1154
+ /**
1155
+ * Kicking this off by calling 'get_instance()' method
1156
+ */
1157
+ Cartflows_Checkout_Markup::get_instance();
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, cart
5
  Requires at least: 4.4
6
  Requires PHP: 5.6
7
  Tested up to: 5.1
8
- Stable tag: 1.1.16
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -93,6 +93,9 @@ Say goodby to using the same ridgid checkout page that everyone else is using. C
93
 
94
  == Changelog ==
95
 
 
 
 
96
  = Version 1.1.16 - Thursday, 25th April 2019 =
97
  * Improvement: Added compatibility for the Cartflows Pro plugin update for an older versions.
98
 
5
  Requires at least: 4.4
6
  Requires PHP: 5.6
7
  Tested up to: 5.1
8
+ Stable tag: 1.1.17
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
93
 
94
  == Changelog ==
95
 
96
+ = Version 1.1.17 - Tuesday, 30th April 2019 =
97
+ * Fix: Database connectivity error while cloning the flow.
98
+
99
  = Version 1.1.16 - Thursday, 25th April 2019 =
100
  * Improvement: Added compatibility for the Cartflows Pro plugin update for an older versions.
101