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

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.9
Comparing to
See all releases

Code changes from version 1.1.8 to 1.1.9

assets/css/checkout-template-divi-rtl.css CHANGED
@@ -222,4 +222,10 @@
222
  float: none;
223
  width: 100%;
224
  }
 
 
 
 
 
 
225
  }
222
  float: none;
223
  width: 100%;
224
  }
225
+ }
226
+
227
+ @media (max-width: 767px){
228
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .form-row {
229
+ width: 100% !important;
230
+ }
231
  }
assets/css/checkout-template-divi.css CHANGED
@@ -222,4 +222,10 @@
222
  float: none;
223
  width: 100%;
224
  }
 
 
 
 
 
 
225
  }
222
  float: none;
223
  width: 100%;
224
  }
225
+ }
226
+
227
+ @media (max-width: 767px){
228
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .form-row {
229
+ width: 100% !important;
230
+ }
231
  }
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.8
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.9
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  Version 1.1.8 - Wednesday, 27th February 2019
2
  - New: Custom script support added for Landing, Checkout and Thank You page type.
3
  - Fix: Added compatibility for pre-applied coupon field fix.
1
+ Version 1.1.9 - Tuesday, 5th March 2019
2
+ - Fix: Divi builder fails to open if the page is set as home page.
3
+ - Fix: Checkout field's width issue on mobile devices in Divi.
4
+
5
  Version 1.1.8 - Wednesday, 27th February 2019
6
  - New: Custom script support added for Landing, Checkout and Thank You page type.
7
  - Fix: Added compatibility for pre-applied coupon field fix.
classes/batch-process/class-cartflows-batch-process.php CHANGED
@@ -1,270 +1,270 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Batch_Process' ) ) :
10
-
11
- /**
12
- * CartFlows_Batch_Process
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_Batch_Process {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @var object Class object.
23
- * @access private
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Elementor Batch Instance
29
- *
30
- * @since 1.1.1 Updated instance name with elementor specific.
31
- *
32
- * @since 1.0.0
33
- * @var object Class object.
34
- * @access public
35
- */
36
- public static $batch_instance_elementor;
37
-
38
- /**
39
- * Beaver Builder Batch Instance
40
- *
41
- * @since 1.1.1
42
- * @var object Class object.
43
- * @access public
44
- */
45
- public static $batch_instance_bb;
46
-
47
- /**
48
- * Divi Batch Instance
49
- *
50
- * @since 1.1.1
51
- * @var object Class object.
52
- * @access public
53
- */
54
- public static $batch_instance_divi;
55
-
56
- /**
57
- * Initiator
58
- *
59
- * @since 1.0.0
60
- * @return object initialized object of class.
61
- */
62
- public static function get_instance() {
63
- if ( ! isset( self::$instance ) ) {
64
- self::$instance = new self;
65
- }
66
- return self::$instance;
67
- }
68
-
69
- /**
70
- * Constructor
71
- *
72
- * @since 1.0.0
73
- */
74
- public function __construct() {
75
-
76
- // Not BB or Elementor then avoid importer.
77
- // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) {
78
- // return;
79
- // }
80
- // Core Helpers - Image.
81
- require_once ABSPATH . 'wp-admin/includes/image.php';
82
-
83
- // Core Helpers - Batch Processing.
84
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php';
85
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php';
86
- require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php';
87
-
88
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
89
-
90
- // Elementor.
91
- if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) {
92
- // Add "elementor" in import [queue].
93
- // @todo Remove required `allow_url_fopen` support.
94
- if ( ini_get( 'allow_url_fopen' ) ) {
95
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
96
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php';
97
- self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch();
98
- }
99
- }
100
-
101
- // Beaver Builder.
102
- if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) {
103
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php';
104
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php';
105
- self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch();
106
- }
107
-
108
- // Divi.
109
- if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) {
110
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php';
111
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php';
112
- self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch();
113
- }
114
-
115
- // Start image importing after site import complete.
116
- add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) );
117
- add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) );
118
- add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
119
- add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
120
- }
121
-
122
- /**
123
- * Added .svg files as supported format in the uploader.
124
- *
125
- * @since 1.1.4
126
- *
127
- * @param array $mimes Already supported mime types.
128
- */
129
- public function custom_upload_mimes( $mimes ) {
130
-
131
- // Allow SVG files.
132
- $mimes['svg'] = 'image/svg+xml';
133
- $mimes['svgz'] = 'image/svg+xml';
134
-
135
- // Allow XML files.
136
- $mimes['xml'] = 'text/xml';
137
-
138
- return $mimes;
139
- }
140
-
141
- /**
142
- * Add SVG image support
143
- *
144
- * @since 1.1.4
145
- *
146
- * @param array $response Attachment response.
147
- * @param object $attachment Attachment object.
148
- * @param array $meta Attachment meta data.
149
- */
150
- function add_svg_image_support( $response, $attachment, $meta ) {
151
- if ( ! function_exists( 'simplexml_load_file' ) ) {
152
- return $response;
153
- }
154
-
155
- if ( ! empty( $response['sizes'] ) ) {
156
- return $response;
157
- }
158
-
159
- if ( 'image/svg+xml' !== $response['mime'] ) {
160
- return $response;
161
- }
162
-
163
- $svg_path = get_attached_file( $attachment->ID );
164
-
165
- $dimensions = self::get_svg_dimensions( $svg_path );
166
-
167
- $response['sizes'] = array(
168
- 'full' => array(
169
- 'url' => $response['url'],
170
- 'width' => $dimensions->width,
171
- 'height' => $dimensions->height,
172
- 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
173
- ),
174
- );
175
-
176
- return $response;
177
- }
178
-
179
- /**
180
- * Get SVG Dimensions
181
- *
182
- * @since 1.1.4.
183
- *
184
- * @param string $svg SVG file path.
185
- * @return array Return SVG file height & width for valid SVG file.
186
- */
187
- public static function get_svg_dimensions( $svg ) {
188
-
189
- $svg = simplexml_load_file( $svg );
190
-
191
- if ( false === $svg ) {
192
- $width = '0';
193
- $height = '0';
194
- } else {
195
- $attributes = $svg->attributes();
196
- $width = (string) $attributes->width;
197
- $height = (string) $attributes->height;
198
- }
199
-
200
- return (object) array(
201
- 'width' => $width,
202
- 'height' => $height,
203
- );
204
- }
205
-
206
- /**
207
- * Batch Process Complete.
208
- *
209
- * @return void
210
- */
211
- public function complete_batch_import() {
212
- wcf()->logger->import_log( '(✓) BATCH Process Complete!' );
213
- }
214
-
215
- /**
216
- * Start Image Import
217
- *
218
- * @param integer $post_id Post Id.
219
- *
220
- * @return void
221
- */
222
- public function start_batch_process( $post_id = '' ) {
223
-
224
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
225
-
226
- wcf()->logger->import_log( '(✓) BATCH Started!' );
227
- wcf()->logger->import_log( '(✓) Step ID ' . $post_id );
228
-
229
- // Add "elementor" in import [queue].
230
- if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) {
231
-
232
- // Add to queue.
233
- self::$batch_instance_bb->push_to_queue( $post_id );
234
-
235
- // Dispatch Queue.
236
- self::$batch_instance_bb->save()->dispatch();
237
-
238
- wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' );
239
-
240
- } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) {
241
-
242
- // Add to queue.
243
- self::$batch_instance_elementor->push_to_queue( $post_id );
244
-
245
- // Dispatch Queue.
246
- self::$batch_instance_elementor->save()->dispatch();
247
-
248
- wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' );
249
- } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) {
250
-
251
- // Add to queue.
252
- self::$batch_instance_divi->push_to_queue( $post_id );
253
-
254
- // Dispatch Queue.
255
- self::$batch_instance_divi->save()->dispatch();
256
-
257
- wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' );
258
- } else {
259
- wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' );
260
- }
261
- }
262
-
263
- }
264
-
265
- /**
266
- * Kicking this off by calling 'get_instance()' method
267
- */
268
- CartFlows_Batch_Process::get_instance();
269
-
270
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Batch_Process' ) ) :
10
+
11
+ /**
12
+ * CartFlows_Batch_Process
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_Batch_Process {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @var object Class object.
23
+ * @access private
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Elementor Batch Instance
29
+ *
30
+ * @since 1.1.1 Updated instance name with elementor specific.
31
+ *
32
+ * @since 1.0.0
33
+ * @var object Class object.
34
+ * @access public
35
+ */
36
+ public static $batch_instance_elementor;
37
+
38
+ /**
39
+ * Beaver Builder Batch Instance
40
+ *
41
+ * @since 1.1.1
42
+ * @var object Class object.
43
+ * @access public
44
+ */
45
+ public static $batch_instance_bb;
46
+
47
+ /**
48
+ * Divi Batch Instance
49
+ *
50
+ * @since 1.1.1
51
+ * @var object Class object.
52
+ * @access public
53
+ */
54
+ public static $batch_instance_divi;
55
+
56
+ /**
57
+ * Initiator
58
+ *
59
+ * @since 1.0.0
60
+ * @return object initialized object of class.
61
+ */
62
+ public static function get_instance() {
63
+ if ( ! isset( self::$instance ) ) {
64
+ self::$instance = new self;
65
+ }
66
+ return self::$instance;
67
+ }
68
+
69
+ /**
70
+ * Constructor
71
+ *
72
+ * @since 1.0.0
73
+ */
74
+ public function __construct() {
75
+
76
+ // Not BB or Elementor then avoid importer.
77
+ // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) {
78
+ // return;
79
+ // }
80
+ // Core Helpers - Image.
81
+ require_once ABSPATH . 'wp-admin/includes/image.php';
82
+
83
+ // Core Helpers - Batch Processing.
84
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php';
85
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php';
86
+ require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php';
87
+
88
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
89
+
90
+ // Elementor.
91
+ if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) {
92
+ // Add "elementor" in import [queue].
93
+ // @todo Remove required `allow_url_fopen` support.
94
+ if ( ini_get( 'allow_url_fopen' ) ) {
95
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
96
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php';
97
+ self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch();
98
+ }
99
+ }
100
+
101
+ // Beaver Builder.
102
+ if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) {
103
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php';
104
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php';
105
+ self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch();
106
+ }
107
+
108
+ // Divi.
109
+ if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) {
110
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php';
111
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php';
112
+ self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch();
113
+ }
114
+
115
+ // Start image importing after site import complete.
116
+ add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) );
117
+ add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) );
118
+ add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
119
+ add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
120
+ }
121
+
122
+ /**
123
+ * Added .svg files as supported format in the uploader.
124
+ *
125
+ * @since 1.1.4
126
+ *
127
+ * @param array $mimes Already supported mime types.
128
+ */
129
+ public function custom_upload_mimes( $mimes ) {
130
+
131
+ // Allow SVG files.
132
+ $mimes['svg'] = 'image/svg+xml';
133
+ $mimes['svgz'] = 'image/svg+xml';
134
+
135
+ // Allow XML files.
136
+ $mimes['xml'] = 'text/xml';
137
+
138
+ return $mimes;
139
+ }
140
+
141
+ /**
142
+ * Add SVG image support
143
+ *
144
+ * @since 1.1.4
145
+ *
146
+ * @param array $response Attachment response.
147
+ * @param object $attachment Attachment object.
148
+ * @param array $meta Attachment meta data.
149
+ */
150
+ function add_svg_image_support( $response, $attachment, $meta ) {
151
+ if ( ! function_exists( 'simplexml_load_file' ) ) {
152
+ return $response;
153
+ }
154
+
155
+ if ( ! empty( $response['sizes'] ) ) {
156
+ return $response;
157
+ }
158
+
159
+ if ( 'image/svg+xml' !== $response['mime'] ) {
160
+ return $response;
161
+ }
162
+
163
+ $svg_path = get_attached_file( $attachment->ID );
164
+
165
+ $dimensions = self::get_svg_dimensions( $svg_path );
166
+
167
+ $response['sizes'] = array(
168
+ 'full' => array(
169
+ 'url' => $response['url'],
170
+ 'width' => $dimensions->width,
171
+ 'height' => $dimensions->height,
172
+ 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
173
+ ),
174
+ );
175
+
176
+ return $response;
177
+ }
178
+
179
+ /**
180
+ * Get SVG Dimensions
181
+ *
182
+ * @since 1.1.4.
183
+ *
184
+ * @param string $svg SVG file path.
185
+ * @return array Return SVG file height & width for valid SVG file.
186
+ */
187
+ public static function get_svg_dimensions( $svg ) {
188
+
189
+ $svg = simplexml_load_file( $svg );
190
+
191
+ if ( false === $svg ) {
192
+ $width = '0';
193
+ $height = '0';
194
+ } else {
195
+ $attributes = $svg->attributes();
196
+ $width = (string) $attributes->width;
197
+ $height = (string) $attributes->height;
198
+ }
199
+
200
+ return (object) array(
201
+ 'width' => $width,
202
+ 'height' => $height,
203
+ );
204
+ }
205
+
206
+ /**
207
+ * Batch Process Complete.
208
+ *
209
+ * @return void
210
+ */
211
+ public function complete_batch_import() {
212
+ wcf()->logger->import_log( '(✓) BATCH Process Complete!' );
213
+ }
214
+
215
+ /**
216
+ * Start Image Import
217
+ *
218
+ * @param integer $post_id Post Id.
219
+ *
220
+ * @return void
221
+ */
222
+ public function start_batch_process( $post_id = '' ) {
223
+
224
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
225
+
226
+ wcf()->logger->import_log( '(✓) BATCH Started!' );
227
+ wcf()->logger->import_log( '(✓) Step ID ' . $post_id );
228
+
229
+ // Add "elementor" in import [queue].
230
+ if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) {
231
+
232
+ // Add to queue.
233
+ self::$batch_instance_bb->push_to_queue( $post_id );
234
+
235
+ // Dispatch Queue.
236
+ self::$batch_instance_bb->save()->dispatch();
237
+
238
+ wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' );
239
+
240
+ } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) {
241
+
242
+ // Add to queue.
243
+ self::$batch_instance_elementor->push_to_queue( $post_id );
244
+
245
+ // Dispatch Queue.
246
+ self::$batch_instance_elementor->save()->dispatch();
247
+
248
+ wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' );
249
+ } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) {
250
+
251
+ // Add to queue.
252
+ self::$batch_instance_divi->push_to_queue( $post_id );
253
+
254
+ // Dispatch Queue.
255
+ self::$batch_instance_divi->save()->dispatch();
256
+
257
+ wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' );
258
+ } else {
259
+ wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' );
260
+ }
261
+ }
262
+
263
+ }
264
+
265
+ /**
266
+ * Kicking this off by calling 'get_instance()' method
267
+ */
268
+ CartFlows_Batch_Process::get_instance();
269
+
270
+ endif;
classes/batch-process/class-cartflows-importer-divi.php CHANGED
@@ -1,217 +1,217 @@
1
- <?php
2
- /**
3
- * Divi Importer
4
- *
5
- * @package CartFlows
6
- * @since 1.1.1
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) :
10
-
11
- /**
12
- * CartFlows Import Divi
13
- *
14
- * @since 1.1.1
15
- */
16
- class CartFlows_Importer_Divi {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.1
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.1.1
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.1.1
45
- */
46
- public function __construct() {
47
- add_action( 'admin_head', array( $this, 're_process_data_flow' ) );
48
- add_action( 'admin_head', array( $this, 're_process_data_step' ) );
49
- }
50
-
51
- /**
52
- * Rest Data.
53
- *
54
- * @param integer $post_id Post ID.
55
- * @return void
56
- */
57
- function reset_data( $post_id ) {
58
-
59
- $content = get_post_meta( $post_id, 'divi_content_processed', true );
60
-
61
- if ( ! empty( $content ) ) {
62
-
63
- $content = CartFlows_Importer::get_instance()->get_content( $content );
64
-
65
- // Update post content.
66
- wp_update_post(
67
- array(
68
- 'ID' => $post_id,
69
- 'post_content' => $content,
70
- )
71
- );
72
- }
73
- }
74
-
75
- /**
76
- * Re process data.
77
- */
78
- function re_process_data_flow() {
79
- wcf()->logger->import_log( ' Without batch started.. ' );
80
-
81
- if ( CARTFLOWS_FLOW_POST_TYPE !== get_post_type() ) {
82
- return;
83
- }
84
-
85
- global $pagenow;
86
-
87
- if ( 'post.php' !== $pagenow ) {
88
- return;
89
- }
90
-
91
- // Is Highlight step then return!
92
- // Because, It process only for the first flow import.
93
- if ( isset( $_GET['highlight-step-id'] ) ) {
94
- return;
95
- }
96
-
97
- $post_id = get_the_ID();
98
-
99
- /* If Imported Flow */
100
- if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_flow', true ) ) {
101
- return;
102
- }
103
-
104
- // wcf()->logger->import_log( ' Reprocessing Divi Data.. ' . $post_id );.
105
- $flow_processed = get_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
106
-
107
- if ( ! $flow_processed ) {
108
-
109
- $steps = get_post_meta( $post_id, 'wcf-steps', true );
110
- $steps_count = count( $steps );
111
- $steps_remaing = $steps_count;
112
-
113
- foreach ( $steps as $key => $step ) {
114
-
115
- $step_processed = get_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
116
-
117
- if ( ! $step_processed ) {
118
-
119
- $content = get_post_meta( $step['id'], 'divi_content_processed', true );
120
- // It means that batch is not complete yet.
121
- if ( ! empty( $content ) ) {
122
- $this->reset_data( $step['id'] );
123
-
124
- wcf()->logger->import_log( ' Processing without batch.. ' . $step['id'] );
125
-
126
- // Step processed!
127
- update_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
128
-
129
- $steps_remaing--;
130
- }
131
- }
132
- }
133
-
134
- // All step data processed.
135
- if ( 0 === $steps_remaing ) {
136
- wcf()->logger->import_log( ' ----------- FLOW COMPLETE ----------------- ' . $post_id );
137
- update_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
138
- }
139
- } else {
140
- wcf()->logger->import_log( ' Already processed.. ' );
141
- }
142
-
143
- wcf()->logger->import_log( ' Without batch end.. ' );
144
-
145
- }
146
-
147
- /**
148
- * Re process data for step.
149
- */
150
- function re_process_data_step() {
151
-
152
- wcf()->logger->import_log( ' Without batch started.. ' );
153
-
154
- if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
155
- return;
156
- }
157
-
158
- $post_id = get_the_ID();
159
-
160
- /* If Imported Step */
161
- if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_step', true ) ) {
162
- return;
163
- }
164
-
165
- $step_processed = get_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
166
-
167
- if ( ! $step_processed ) {
168
-
169
- $content = get_post_meta( $post_id, 'divi_content_processed', true );
170
- // It means that batch is not complete yet.
171
- if ( ! empty( $content ) ) {
172
- $this->reset_data( $post_id );
173
-
174
- wcf()->logger->import_log( ' Processing without batch.. ' . $post_id );
175
-
176
- // Step processed!
177
- update_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
178
- }
179
- }
180
- }
181
-
182
- /**
183
- * Update post meta.
184
- *
185
- * @param integer $post_id Post ID.
186
- * @return void
187
- */
188
- public function import_single_post( $post_id = 0 ) {
189
-
190
- // Download and replace images.
191
- $content = get_post_meta( $post_id, 'divi_content', true );
192
-
193
- if ( empty( $content ) ) {
194
- wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' );
195
- } else {
196
-
197
- wcf()->logger->import_log( '(✓) Processing Request..' );
198
-
199
- // Update hotlink images.
200
- $content = CartFlows_Importer::get_instance()->get_content( $content );
201
-
202
- // Save processed data.
203
- update_post_meta( $post_id, 'divi_content_processed', $content );
204
-
205
- // Delete temporary meta key.
206
- wcf()->logger->import_log( '(✓) Process Complete' );
207
- }
208
- }
209
-
210
- }
211
-
212
- /**
213
- * Initialize class object with 'get_instance()' method
214
- */
215
- CartFlows_Importer_Divi::get_instance();
216
-
217
- endif;
1
+ <?php
2
+ /**
3
+ * Divi Importer
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) :
10
+
11
+ /**
12
+ * CartFlows Import Divi
13
+ *
14
+ * @since 1.1.1
15
+ */
16
+ class CartFlows_Importer_Divi {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.1
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.1.1
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.1.1
45
+ */
46
+ public function __construct() {
47
+ add_action( 'admin_head', array( $this, 're_process_data_flow' ) );
48
+ add_action( 'admin_head', array( $this, 're_process_data_step' ) );
49
+ }
50
+
51
+ /**
52
+ * Rest Data.
53
+ *
54
+ * @param integer $post_id Post ID.
55
+ * @return void
56
+ */
57
+ function reset_data( $post_id ) {
58
+
59
+ $content = get_post_meta( $post_id, 'divi_content_processed', true );
60
+
61
+ if ( ! empty( $content ) ) {
62
+
63
+ $content = CartFlows_Importer::get_instance()->get_content( $content );
64
+
65
+ // Update post content.
66
+ wp_update_post(
67
+ array(
68
+ 'ID' => $post_id,
69
+ 'post_content' => $content,
70
+ )
71
+ );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Re process data.
77
+ */
78
+ function re_process_data_flow() {
79
+ wcf()->logger->import_log( ' Without batch started.. ' );
80
+
81
+ if ( CARTFLOWS_FLOW_POST_TYPE !== get_post_type() ) {
82
+ return;
83
+ }
84
+
85
+ global $pagenow;
86
+
87
+ if ( 'post.php' !== $pagenow ) {
88
+ return;
89
+ }
90
+
91
+ // Is Highlight step then return!
92
+ // Because, It process only for the first flow import.
93
+ if ( isset( $_GET['highlight-step-id'] ) ) {
94
+ return;
95
+ }
96
+
97
+ $post_id = get_the_ID();
98
+
99
+ /* If Imported Flow */
100
+ if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_flow', true ) ) {
101
+ return;
102
+ }
103
+
104
+ // wcf()->logger->import_log( ' Reprocessing Divi Data.. ' . $post_id );.
105
+ $flow_processed = get_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
106
+
107
+ if ( ! $flow_processed ) {
108
+
109
+ $steps = get_post_meta( $post_id, 'wcf-steps', true );
110
+ $steps_count = count( $steps );
111
+ $steps_remaing = $steps_count;
112
+
113
+ foreach ( $steps as $key => $step ) {
114
+
115
+ $step_processed = get_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
116
+
117
+ if ( ! $step_processed ) {
118
+
119
+ $content = get_post_meta( $step['id'], 'divi_content_processed', true );
120
+ // It means that batch is not complete yet.
121
+ if ( ! empty( $content ) ) {
122
+ $this->reset_data( $step['id'] );
123
+
124
+ wcf()->logger->import_log( ' Processing without batch.. ' . $step['id'] );
125
+
126
+ // Step processed!
127
+ update_post_meta( $step['id'], 'wcf_divi_step_data_processed', true );
128
+
129
+ $steps_remaing--;
130
+ }
131
+ }
132
+ }
133
+
134
+ // All step data processed.
135
+ if ( 0 === $steps_remaing ) {
136
+ wcf()->logger->import_log( ' ----------- FLOW COMPLETE ----------------- ' . $post_id );
137
+ update_post_meta( $post_id, 'wcf_divi_flow_data_processed', true );
138
+ }
139
+ } else {
140
+ wcf()->logger->import_log( ' Already processed.. ' );
141
+ }
142
+
143
+ wcf()->logger->import_log( ' Without batch end.. ' );
144
+
145
+ }
146
+
147
+ /**
148
+ * Re process data for step.
149
+ */
150
+ function re_process_data_step() {
151
+
152
+ wcf()->logger->import_log( ' Without batch started.. ' );
153
+
154
+ if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type() ) {
155
+ return;
156
+ }
157
+
158
+ $post_id = get_the_ID();
159
+
160
+ /* If Imported Step */
161
+ if ( 'yes' !== get_post_meta( $post_id, 'cartflows_imported_step', true ) ) {
162
+ return;
163
+ }
164
+
165
+ $step_processed = get_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
166
+
167
+ if ( ! $step_processed ) {
168
+
169
+ $content = get_post_meta( $post_id, 'divi_content_processed', true );
170
+ // It means that batch is not complete yet.
171
+ if ( ! empty( $content ) ) {
172
+ $this->reset_data( $post_id );
173
+
174
+ wcf()->logger->import_log( ' Processing without batch.. ' . $post_id );
175
+
176
+ // Step processed!
177
+ update_post_meta( $post_id, 'wcf_divi_step_data_processed', true );
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Update post meta.
184
+ *
185
+ * @param integer $post_id Post ID.
186
+ * @return void
187
+ */
188
+ public function import_single_post( $post_id = 0 ) {
189
+
190
+ // Download and replace images.
191
+ $content = get_post_meta( $post_id, 'divi_content', true );
192
+
193
+ if ( empty( $content ) ) {
194
+ wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' );
195
+ } else {
196
+
197
+ wcf()->logger->import_log( '(✓) Processing Request..' );
198
+
199
+ // Update hotlink images.
200
+ $content = CartFlows_Importer::get_instance()->get_content( $content );
201
+
202
+ // Save processed data.
203
+ update_post_meta( $post_id, 'divi_content_processed', $content );
204
+
205
+ // Delete temporary meta key.
206
+ wcf()->logger->import_log( '(✓) Process Complete' );
207
+ }
208
+ }
209
+
210
+ }
211
+
212
+ /**
213
+ * Initialize class object with 'get_instance()' method
214
+ */
215
+ CartFlows_Importer_Divi::get_instance();
216
+
217
+ endif;
classes/class-cartflows-api.php CHANGED
@@ -1,381 +1,381 @@
1
- <?php
2
- /**
3
- * CartFlows API
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_API' ) ) :
10
-
11
- /**
12
- * CartFlows API
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_API {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @access private
22
- * @var object Class object.
23
- * @since 1.0.0
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.0
44
- */
45
- public function __construct() {
46
- }
47
-
48
- /**
49
- * Get site URL.
50
- *
51
- * @since 1.0.0
52
- *
53
- * @return string Site URL.
54
- */
55
- public static function get_site_url() {
56
- return apply_filters( 'cartflows_templates_url', CARTFLOWS_TEMPLATES_URL );
57
- }
58
-
59
- /**
60
- * Get Client Site Templates Rest API URL.
61
- *
62
- * @since 1.0.0
63
- *
64
- * @return string API site URL.
65
- */
66
- public static function get_step_endpoint_url() {
67
- return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_STEP_POST_TYPE . '/';
68
- }
69
-
70
- /**
71
- * Get Client Site Category Rest API URL.
72
- *
73
- * @since 1.0.0
74
- *
75
- * @return string API site URL.
76
- */
77
- public static function get_category_endpoint_url() {
78
- return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER . '/';
79
- }
80
-
81
- /**
82
- * Get API request URL.
83
- *
84
- * @since 1.0.0
85
- *
86
- * @param string $api_base base of api request.
87
- * @return string API site URL.
88
- */
89
- public static function get_request_api_url( $api_base = '' ) {
90
- return self::get_site_url() . 'wp-json/' . CARTFLOWS_STEP_POST_TYPE . '/v1/' . $api_base;
91
- }
92
-
93
- /**
94
- * License Args.
95
- *
96
- * @return array License arguments.
97
- */
98
- public static function get_licence_args() {
99
- return apply_filters( 'cartflows_licence_args', array() );
100
- }
101
-
102
- /**
103
- * Get single demo.
104
- *
105
- * @since 1.0.0
106
- *
107
- * @param string $site_id Template ID of the site.
108
- * @return array Template data.
109
- */
110
- public static function get_template( $site_id ) {
111
- // @codingStandardsIgnoreStart
112
- $request_params = array(
113
- 'licence_args' => self::get_licence_args(),
114
- '_fields' => 'id,slug,status,type,link,title,featured_media,template,cartflows_step_page_builder,cartflows_step_type,cartflows_step_flow,featured_image_url,licence_status,flow_type,step_type,page_builder,divi_content,post_meta',
115
- );
116
- // @codingStandardsIgnoreEnd
117
-
118
- $url = add_query_arg( $request_params, self::get_step_endpoint_url() . $site_id );
119
-
120
- $api_args = array(
121
- 'timeout' => 15,
122
- );
123
-
124
- $response = self::remote_get( $url, $api_args );
125
-
126
- if ( $response['success'] ) {
127
- $template = $response['data'];
128
- return array(
129
- 'title' => ( isset( $template['title']->rendered ) ) ? $template['title']->rendered : '',
130
- 'post_meta' => ( isset( $template['post_meta'] ) ) ? $template['post_meta'] : '',
131
- 'data' => $template,
132
- 'divi_content' => isset( $response['data']['divi_content'] ) ? $response['data']['divi_content'] : '',
133
- 'message' => $response['message'], // __( 'Your API Key is not valid. Please add valid API Key.', 'cartflows' ),
134
- 'success' => $response['success'],
135
- );
136
- }
137
-
138
- return array(
139
- 'title' => '',
140
- 'post_meta' => array(),
141
- 'message' => $response['message'],
142
- 'data' => $response['data'],
143
- 'divi_content' => '',
144
- 'success' => $response['success'],
145
- );
146
- }
147
-
148
- /**
149
- * Get Cloud Templates
150
- *
151
- * @since 1.0.0
152
- *
153
- * @param array $args For selecting the demos (Search terms, pagination etc).
154
- * @return array CartFlows list.
155
- */
156
- public static function get_templates( $args = array() ) {
157
-
158
- $request_params = wp_parse_args(
159
- $args,
160
- array(
161
- 'page' => '1',
162
- 'per_page' => '15',
163
- )
164
- );
165
-
166
- $url = add_query_arg( $request_params, self::get_step_endpoint_url() );
167
-
168
- $api_args = array(
169
- 'timeout' => 15,
170
- );
171
-
172
- $response = self::remote_get( $url, $api_args );
173
-
174
- if ( $response['success'] ) {
175
- $templates_data = $response['data'];
176
- $templates = array();
177
- foreach ( $templates_data as $key => $template ) {
178
-
179
- if ( ! isset( $template->id ) ) {
180
- continue;
181
- }
182
-
183
- $templates[ $key ]['id'] = isset( $template->id ) ? esc_attr( $template->id ) : '';
184
- $templates[ $key ]['slug'] = isset( $template->slug ) ? esc_attr( $template->slug ) : '';
185
- $templates[ $key ]['link'] = isset( $template->link ) ? esc_url( $template->link ) : '';
186
- $templates[ $key ]['date'] = isset( $template->date ) ? esc_attr( $template->date ) : '';
187
- $templates[ $key ]['title'] = isset( $template->title->rendered ) ? esc_attr( $template->title->rendered ) : '';
188
- $templates[ $key ]['featured_image_url'] = isset( $template->featured_image_url ) ? esc_url( $template->featured_image_url ) : '';
189
- $templates[ $key ]['content'] = isset( $template->content->rendered ) ? $template->content->rendered : '';
190
- $templates[ $key ]['divi_content'] = isset( $template->divi_content ) ? $template->divi_content : '';
191
- $templates[ $key ]['post_meta'] = isset( $template->post_meta ) ? $template->post_meta : '';
192
- }
193
-
194
- return array(
195
- 'templates' => $templates,
196
- 'templates_count' => $response['count'],
197
- 'data' => $response,
198
- );
199
- }
200
-
201
- return array(
202
- 'templates' => array(),
203
- 'templates_count' => 0,
204
- 'data' => $response,
205
- );
206
-
207
- }
208
-
209
- /**
210
- * Get categories.
211
- *
212
- * @since 1.0.0
213
- * @param array $args Arguments.
214
- * @return array Category data.
215
- */
216
- public static function get_categories( $args = array() ) {
217
-
218
- $request_params = apply_filters(
219
- 'cartflows_categories_api_params',
220
- wp_parse_args(
221
- $args,
222
- array(
223
- 'page' => '1',
224
- 'per_page' => '15',
225
- )
226
- )
227
- );
228
-
229
- $url = add_query_arg( $request_params, self::get_category_endpoint_url() );
230
-
231
- $api_args = apply_filters(
232
- 'cartflows_api_args',
233
- array(
234
- 'timeout' => 15,
235
- )
236
- );
237
-
238
- $response = self::remote_get( $url, $api_args );
239
-
240
- if ( $response['success'] ) {
241
- $categories_data = $response['data'];
242
- $categories = array();
243
-
244
- foreach ( $categories_data as $key => $category ) {
245
- if ( isset( $category->count ) && ! empty( $category->count ) ) {
246
- $categories[] = array(
247
- 'id' => isset( $category->id ) ? absint( $category->id ) : 0,
248
- 'count' => isset( $category->count ) ? absint( $category->count ) : 0,
249
- 'description' => isset( $category->description ) ? $category->description : '',
250
- 'link' => isset( $category->link ) ? esc_url( $category->link ) : '',
251
- 'name' => isset( $category->name ) ? $category->name : '',
252
- 'slug' => isset( $category->slug ) ? sanitize_text_field( $category->slug ) : '',
253
- 'taxonomy' => isset( $category->taxonomy ) ? $category->taxonomy : '',
254
- 'parent' => isset( $category->parent ) ? $category->parent : '',
255
- );
256
- }
257
- }
258
-
259
- return array(
260
- 'categories' => $categories,
261
- 'categories_count' => $response['count'],
262
- 'data' => $response,
263
- );
264
- }
265
-
266
- return array(
267
- 'categories' => array(),
268
- 'categories_count' => 0,
269
- 'data' => $response,
270
- );
271
- }
272
-
273
- /**
274
- * Remote GET API Request
275
- *
276
- * @since 1.0.0
277
- *
278
- * @param string $url Target server API URL.
279
- * @param array $args Array of arguments for the API request.
280
- * @return mixed Return the API request result.
281
- */
282
- public static function remote_get( $url = '', $args = array() ) {
283
- $request = wp_remote_get( $url, $args );
284
- return self::request( $request );
285
- }
286
-
287
- /**
288
- * Remote POST API Request
289
- *
290
- * @since 1.0.0
291
- *
292
- * @param string $url Target server API URL.
293
- * @param array $args Array of arguments for the API request.
294
- * @return mixed Return the API request result.
295
- */
296
- public static function remote_post( $url = '', $args = array() ) {
297
- $request = wp_remote_post( $url, $args );
298
-
299
- return self::request( $request );
300
- }
301
-
302
- /**
303
- * Site API Request
304
- *
305
- * @since 1.0.0
306
- *
307
- * @param boolean $api_base Target server API URL.
308
- * @param array $args Array of arguments for the API request.
309
- * @return mixed Return the API request result.
310
- */
311
- public static function site_request( $api_base = '', $args = array() ) {
312
-
313
- $api_url = self::get_request_api_url( $api_base );
314
-
315
- return self::remote_post( $api_url, $args );
316
- }
317
-
318
- /**
319
- * API Request
320
- *
321
- * Handle the API request and return the result.
322
- *
323
- * @since 1.0.0
324
- *
325
- * @param array $request Array of arguments for the API request.
326
- * @return mixed Return the API request result.
327
- */
328
- public static function request( $request ) {
329
-
330
- // Is WP Error?
331
- if ( is_wp_error( $request ) ) {
332
- return array(
333
- 'success' => false,
334
- 'message' => $request->get_error_message(),
335
- 'data' => $request,
336
- 'count' => 0,
337
- );
338
- }
339
-
340
- // Invalid response code.
341
- if ( wp_remote_retrieve_response_code( $request ) != 200 ) {
342
- return array(
343
- 'success' => false,
344
- 'message' => $request['response'],
345
- 'data' => $request,
346
- 'count' => 0,
347
- );
348
- }
349
-
350
- // Get body data.
351
- $body = wp_remote_retrieve_body( $request );
352
-
353
- // Is WP Error?
354
- if ( is_wp_error( $body ) ) {
355
- return array(
356
- 'success' => false,
357
- 'message' => $body->get_error_message(),
358
- 'data' => $request,
359
- 'count' => 0,
360
- );
361
- }
362
-
363
- // Decode body content.
364
- $body_decoded = json_decode( $body );
365
-
366
- return array(
367
- 'success' => true,
368
- 'message' => __( 'Request successfully processed!', 'cartflows' ),
369
- 'data' => (array) $body_decoded,
370
- 'count' => wp_remote_retrieve_header( $request, 'x-wp-total' ),
371
- );
372
- }
373
-
374
- }
375
-
376
- /**
377
- * Initialize class object with 'get_instance()' method
378
- */
379
- CartFlows_API::get_instance();
380
-
381
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows API
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_API' ) ) :
10
+
11
+ /**
12
+ * CartFlows API
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_API {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @access private
22
+ * @var object Class object.
23
+ * @since 1.0.0
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function __construct() {
46
+ }
47
+
48
+ /**
49
+ * Get site URL.
50
+ *
51
+ * @since 1.0.0
52
+ *
53
+ * @return string Site URL.
54
+ */
55
+ public static function get_site_url() {
56
+ return apply_filters( 'cartflows_templates_url', CARTFLOWS_TEMPLATES_URL );
57
+ }
58
+
59
+ /**
60
+ * Get Client Site Templates Rest API URL.
61
+ *
62
+ * @since 1.0.0
63
+ *
64
+ * @return string API site URL.
65
+ */
66
+ public static function get_step_endpoint_url() {
67
+ return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_STEP_POST_TYPE . '/';
68
+ }
69
+
70
+ /**
71
+ * Get Client Site Category Rest API URL.
72
+ *
73
+ * @since 1.0.0
74
+ *
75
+ * @return string API site URL.
76
+ */
77
+ public static function get_category_endpoint_url() {
78
+ return self::get_site_url() . 'wp-json/wp/v2/' . CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER . '/';
79
+ }
80
+
81
+ /**
82
+ * Get API request URL.
83
+ *
84
+ * @since 1.0.0
85
+ *
86
+ * @param string $api_base base of api request.
87
+ * @return string API site URL.
88
+ */
89
+ public static function get_request_api_url( $api_base = '' ) {
90
+ return self::get_site_url() . 'wp-json/' . CARTFLOWS_STEP_POST_TYPE . '/v1/' . $api_base;
91
+ }
92
+
93
+ /**
94
+ * License Args.
95
+ *
96
+ * @return array License arguments.
97
+ */
98
+ public static function get_licence_args() {
99
+ return apply_filters( 'cartflows_licence_args', array() );
100
+ }
101
+
102
+ /**
103
+ * Get single demo.
104
+ *
105
+ * @since 1.0.0
106
+ *
107
+ * @param string $site_id Template ID of the site.
108
+ * @return array Template data.
109
+ */
110
+ public static function get_template( $site_id ) {
111
+ // @codingStandardsIgnoreStart
112
+ $request_params = array(
113
+ 'licence_args' => self::get_licence_args(),
114
+ '_fields' => 'id,slug,status,type,link,title,featured_media,template,cartflows_step_page_builder,cartflows_step_type,cartflows_step_flow,featured_image_url,licence_status,flow_type,step_type,page_builder,divi_content,post_meta',
115
+ );
116
+ // @codingStandardsIgnoreEnd
117
+
118
+ $url = add_query_arg( $request_params, self::get_step_endpoint_url() . $site_id );
119
+
120
+ $api_args = array(
121
+ 'timeout' => 15,
122
+ );
123
+
124
+ $response = self::remote_get( $url, $api_args );
125
+
126
+ if ( $response['success'] ) {
127
+ $template = $response['data'];
128
+ return array(
129
+ 'title' => ( isset( $template['title']->rendered ) ) ? $template['title']->rendered : '',
130
+ 'post_meta' => ( isset( $template['post_meta'] ) ) ? $template['post_meta'] : '',
131
+ 'data' => $template,
132
+ 'divi_content' => isset( $response['data']['divi_content'] ) ? $response['data']['divi_content'] : '',
133
+ 'message' => $response['message'], // __( 'Your API Key is not valid. Please add valid API Key.', 'cartflows' ),
134
+ 'success' => $response['success'],
135
+ );
136
+ }
137
+
138
+ return array(
139
+ 'title' => '',
140
+ 'post_meta' => array(),
141
+ 'message' => $response['message'],
142
+ 'data' => $response['data'],
143
+ 'divi_content' => '',
144
+ 'success' => $response['success'],
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Get Cloud Templates
150
+ *
151
+ * @since 1.0.0
152
+ *
153
+ * @param array $args For selecting the demos (Search terms, pagination etc).
154
+ * @return array CartFlows list.
155
+ */
156
+ public static function get_templates( $args = array() ) {
157
+
158
+ $request_params = wp_parse_args(
159
+ $args,
160
+ array(
161
+ 'page' => '1',
162
+ 'per_page' => '15',
163
+ )
164
+ );
165
+
166
+ $url = add_query_arg( $request_params, self::get_step_endpoint_url() );
167
+
168
+ $api_args = array(
169
+ 'timeout' => 15,
170
+ );
171
+
172
+ $response = self::remote_get( $url, $api_args );
173
+
174
+ if ( $response['success'] ) {
175
+ $templates_data = $response['data'];
176
+ $templates = array();
177
+ foreach ( $templates_data as $key => $template ) {
178
+
179
+ if ( ! isset( $template->id ) ) {
180
+ continue;
181
+ }
182
+
183
+ $templates[ $key ]['id'] = isset( $template->id ) ? esc_attr( $template->id ) : '';
184
+ $templates[ $key ]['slug'] = isset( $template->slug ) ? esc_attr( $template->slug ) : '';
185
+ $templates[ $key ]['link'] = isset( $template->link ) ? esc_url( $template->link ) : '';
186
+ $templates[ $key ]['date'] = isset( $template->date ) ? esc_attr( $template->date ) : '';
187
+ $templates[ $key ]['title'] = isset( $template->title->rendered ) ? esc_attr( $template->title->rendered ) : '';
188
+ $templates[ $key ]['featured_image_url'] = isset( $template->featured_image_url ) ? esc_url( $template->featured_image_url ) : '';
189
+ $templates[ $key ]['content'] = isset( $template->content->rendered ) ? $template->content->rendered : '';
190
+ $templates[ $key ]['divi_content'] = isset( $template->divi_content ) ? $template->divi_content : '';
191
+ $templates[ $key ]['post_meta'] = isset( $template->post_meta ) ? $template->post_meta : '';
192
+ }
193
+
194
+ return array(
195
+ 'templates' => $templates,
196
+ 'templates_count' => $response['count'],
197
+ 'data' => $response,
198
+ );
199
+ }
200
+
201
+ return array(
202
+ 'templates' => array(),
203
+ 'templates_count' => 0,
204
+ 'data' => $response,
205
+ );
206
+
207
+ }
208
+
209
+ /**
210
+ * Get categories.
211
+ *
212
+ * @since 1.0.0
213
+ * @param array $args Arguments.
214
+ * @return array Category data.
215
+ */
216
+ public static function get_categories( $args = array() ) {
217
+
218
+ $request_params = apply_filters(
219
+ 'cartflows_categories_api_params',
220
+ wp_parse_args(
221
+ $args,
222
+ array(
223
+ 'page' => '1',
224
+ 'per_page' => '15',
225
+ )
226
+ )
227
+ );
228
+
229
+ $url = add_query_arg( $request_params, self::get_category_endpoint_url() );
230
+
231
+ $api_args = apply_filters(
232
+ 'cartflows_api_args',
233
+ array(
234
+ 'timeout' => 15,
235
+ )
236
+ );
237
+
238
+ $response = self::remote_get( $url, $api_args );
239
+
240
+ if ( $response['success'] ) {
241
+ $categories_data = $response['data'];
242
+ $categories = array();
243
+
244
+ foreach ( $categories_data as $key => $category ) {
245
+ if ( isset( $category->count ) && ! empty( $category->count ) ) {
246
+ $categories[] = array(
247
+ 'id' => isset( $category->id ) ? absint( $category->id ) : 0,
248
+ 'count' => isset( $category->count ) ? absint( $category->count ) : 0,
249
+ 'description' => isset( $category->description ) ? $category->description : '',
250
+ 'link' => isset( $category->link ) ? esc_url( $category->link ) : '',
251
+ 'name' => isset( $category->name ) ? $category->name : '',
252
+ 'slug' => isset( $category->slug ) ? sanitize_text_field( $category->slug ) : '',
253
+ 'taxonomy' => isset( $category->taxonomy ) ? $category->taxonomy : '',
254
+ 'parent' => isset( $category->parent ) ? $category->parent : '',
255
+ );
256
+ }
257
+ }
258
+
259
+ return array(
260
+ 'categories' => $categories,
261
+ 'categories_count' => $response['count'],
262
+ 'data' => $response,
263
+ );
264
+ }
265
+
266
+ return array(
267
+ 'categories' => array(),
268
+ 'categories_count' => 0,
269
+ 'data' => $response,
270
+ );
271
+ }
272
+
273
+ /**
274
+ * Remote GET API Request
275
+ *
276
+ * @since 1.0.0
277
+ *
278
+ * @param string $url Target server API URL.
279
+ * @param array $args Array of arguments for the API request.
280
+ * @return mixed Return the API request result.
281
+ */
282
+ public static function remote_get( $url = '', $args = array() ) {
283
+ $request = wp_remote_get( $url, $args );
284
+ return self::request( $request );
285
+ }
286
+
287
+ /**
288
+ * Remote POST API Request
289
+ *
290
+ * @since 1.0.0
291
+ *
292
+ * @param string $url Target server API URL.
293
+ * @param array $args Array of arguments for the API request.
294
+ * @return mixed Return the API request result.
295
+ */
296
+ public static function remote_post( $url = '', $args = array() ) {
297
+ $request = wp_remote_post( $url, $args );
298
+
299
+ return self::request( $request );
300
+ }
301
+
302
+ /**
303
+ * Site API Request
304
+ *
305
+ * @since 1.0.0
306
+ *
307
+ * @param boolean $api_base Target server API URL.
308
+ * @param array $args Array of arguments for the API request.
309
+ * @return mixed Return the API request result.
310
+ */
311
+ public static function site_request( $api_base = '', $args = array() ) {
312
+
313
+ $api_url = self::get_request_api_url( $api_base );
314
+
315
+ return self::remote_post( $api_url, $args );
316
+ }
317
+
318
+ /**
319
+ * API Request
320
+ *
321
+ * Handle the API request and return the result.
322
+ *
323
+ * @since 1.0.0
324
+ *
325
+ * @param array $request Array of arguments for the API request.
326
+ * @return mixed Return the API request result.
327
+ */
328
+ public static function request( $request ) {
329
+
330
+ // Is WP Error?
331
+ if ( is_wp_error( $request ) ) {
332
+ return array(
333
+ 'success' => false,
334
+ 'message' => $request->get_error_message(),
335
+ 'data' => $request,
336
+ 'count' => 0,
337
+ );
338
+ }
339
+
340
+ // Invalid response code.
341
+ if ( wp_remote_retrieve_response_code( $request ) != 200 ) {
342
+ return array(
343
+ 'success' => false,
344
+ 'message' => $request['response'],
345
+ 'data' => $request,
346
+ 'count' => 0,
347
+ );
348
+ }
349
+
350
+ // Get body data.
351
+ $body = wp_remote_retrieve_body( $request );
352
+
353
+ // Is WP Error?
354
+ if ( is_wp_error( $body ) ) {
355
+ return array(
356
+ 'success' => false,
357
+ 'message' => $body->get_error_message(),
358
+ 'data' => $request,
359
+ 'count' => 0,
360
+ );
361
+ }
362
+
363
+ // Decode body content.
364
+ $body_decoded = json_decode( $body );
365
+
366
+ return array(
367
+ 'success' => true,
368
+ 'message' => __( 'Request successfully processed!', 'cartflows' ),
369
+ 'data' => (array) $body_decoded,
370
+ 'count' => wp_remote_retrieve_header( $request, 'x-wp-total' ),
371
+ );
372
+ }
373
+
374
+ }
375
+
376
+ /**
377
+ * Initialize class object with 'get_instance()' method
378
+ */
379
+ CartFlows_API::get_instance();
380
+
381
+ endif;
classes/class-cartflows-compatibility.php CHANGED
@@ -1,388 +1,392 @@
1
- <?php
2
- /**
3
- * Page builder compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
9
-
10
- /**
11
- * Class for page builder compatibility
12
- */
13
- class Cartflows_Compatibility {
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
- $this->load_files();
38
-
39
- // Override post meta.
40
- add_action( 'wp', array( $this, 'override_meta' ), 0 );
41
-
42
- add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
43
- }
44
-
45
- /**
46
- * Load page builder compatibility files
47
- */
48
- public function load_files() {
49
- if ( class_exists( '\Elementor\Plugin' ) ) {
50
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
51
- }
52
-
53
- if ( $this->is_divi_enabled() ) {
54
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
55
- }
56
-
57
- if ( $this->is_bb_enabled() ) {
58
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
59
- }
60
-
61
- if ( class_exists( 'TCB_Post' ) ) {
62
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
63
- }
64
- }
65
-
66
- /**
67
- * Check if it is beaver builder enabled.
68
- *
69
- * @since 1.1.4
70
- */
71
- public function is_bb_enabled() {
72
-
73
- if ( class_exists( 'FLBuilderModel' ) ) {
74
- return true;
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Check if elementor preview mode is on.
82
- */
83
- public function is_elementor_preview_mode() {
84
-
85
- if ( class_exists( '\Elementor\Plugin' ) ) {
86
-
87
- if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
88
- return true;
89
- }
90
- }
91
-
92
- return false;
93
- }
94
-
95
- /**
96
- * Get Current Theme.
97
- */
98
- public function get_current_theme() {
99
-
100
- $theme_name = '';
101
- $theme = wp_get_theme();
102
-
103
- if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
104
- $theme_name = $theme->parent_theme;
105
- } else {
106
- $theme_name = $theme->name;
107
- }
108
-
109
- return $theme_name;
110
- }
111
-
112
- /**
113
- * Check if it is beaver builder preview mode
114
- */
115
- public function is_bb_preview_mode() {
116
-
117
- if ( class_exists( 'FLBuilderModel' ) ) {
118
- if ( FLBuilderModel::is_builder_active() ) {
119
- return true;
120
- } else {
121
- return false;
122
- }
123
- }
124
-
125
- return false;
126
- }
127
-
128
- /**
129
- * Check for page builder preview mode.
130
- */
131
- public function is_page_builder_preview() {
132
-
133
- if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() ) {
134
- return true;
135
- }
136
-
137
- return false;
138
- }
139
-
140
- /**
141
- * Check if divi builder enabled for post id.
142
- *
143
- * @param int $post_id post id.
144
- */
145
- public function is_divi_builder_enabled( $post_id ) {
146
-
147
- if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
148
- return true;
149
- }
150
-
151
- return false;
152
- }
153
-
154
- /**
155
- * Check if compatibility theme enabled.
156
- */
157
- function is_compatibility_theme_enabled() {
158
-
159
- $theme = wp_get_theme();
160
-
161
- $is_compatibility = false;
162
-
163
- if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
164
-
165
- $is_compatibility = true;
166
- }
167
-
168
- return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
169
- }
170
-
171
- /**
172
- * Check if divi builder enabled for post id.
173
- *
174
- * @param object $theme theme data.
175
- * @return boolean
176
- */
177
- function is_divi_enabled( $theme = false ) {
178
-
179
- if ( ! $theme ) {
180
- $theme = wp_get_theme();
181
- }
182
-
183
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
184
- return true;
185
- }
186
-
187
- return false;
188
- }
189
-
190
- /**
191
- * Check if Divi theme is install status.
192
- *
193
- * @return boolean
194
- */
195
- function is_divi_theme_installed() {
196
- foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
197
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
198
- return true;
199
- }
200
- }
201
- return false;
202
- }
203
-
204
- /**
205
- * Check if Flatsome enabled for post id.
206
- *
207
- * @param object $theme theme data.
208
- * @return boolean
209
- */
210
- function is_flatsome_enabled( $theme = false ) {
211
-
212
- if ( ! $theme ) {
213
- $theme = wp_get_theme();
214
- }
215
-
216
- if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
217
- return true;
218
- }
219
-
220
- return false;
221
- }
222
-
223
- /**
224
- * Check if The7 enabled for post id.
225
- *
226
- * @param object $theme theme data.
227
- * @return boolean
228
- */
229
- function is_the_seven_enabled( $theme = false ) {
230
-
231
- if ( ! $theme ) {
232
- $theme = wp_get_theme();
233
- }
234
-
235
- if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
236
- return true;
237
- }
238
-
239
- return false;
240
- }
241
-
242
- /**
243
- * Check if OceanWp enabled for post id.
244
- *
245
- * @param object $theme theme data.
246
- * @return boolean
247
- */
248
- function is_oceanwp_enabled( $theme = false ) {
249
-
250
- if ( ! $theme ) {
251
- $theme = wp_get_theme();
252
- }
253
-
254
- if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
255
- return true;
256
- }
257
-
258
- return false;
259
- }
260
-
261
- /**
262
- * Check for thrive architect edit page.
263
- *
264
- * @param int $post_id post id.
265
- */
266
- public function is_thrive_edit_page( $post_id ) {
267
-
268
- if ( true === $this->is_thrive_builder_page( $post_id ) ) {
269
- return true;
270
- } else {
271
- return false;
272
- }
273
- }
274
-
275
- /**
276
- * Check if the page being rendered is the main ID on the editor page.
277
- *
278
- * @since 1.0.0
279
- * @param String $post_id Post ID which is to be rendered.
280
- * @return boolean True if current if is being rendered is not being edited.
281
- */
282
- private function is_thrive_builder_page( $post_id ) {
283
- $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
284
- $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
285
-
286
- return ( true == $tve && $post_id !== $post );
287
- }
288
-
289
- /**
290
- * Overwrite meta for page
291
- */
292
- public function override_meta() {
293
-
294
- // don't override meta for `elementor_library` post type.
295
- if ( 'elementor_library' == get_post_type() ) {
296
- return;
297
- }
298
-
299
- if ( ! is_singular() ) {
300
- return;
301
- }
302
-
303
- global $post;
304
- $post_id = $post->ID;
305
- $post_type = get_post_type();
306
-
307
- if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
308
- || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
309
- || $this->is_divi_builder_enabled( $post_id ) ) ) {
310
-
311
- if ( '' == $post->post_content ) {
312
-
313
- $this->overwrite_template( $post_id );
314
- }
315
- }
316
- }
317
-
318
- /**
319
- * Assign cartflow canvas template to page.
320
- *
321
- * @param int $post_id post ID.
322
- */
323
- public function overwrite_template( $post_id ) {
324
-
325
- $template = 'cartflows-canvas';
326
- $key = '_wp_page_template';
327
-
328
- $record_exists = get_post_meta( $post_id, $key, true );
329
-
330
- if ( 'cartflows-canvas' == $record_exists ) {
331
- return;
332
- }
333
-
334
- // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
335
- if ( class_exists( '\Elementor\Plugin' ) ) {
336
-
337
- global $wpdb;
338
-
339
- if ( '' == $record_exists || ! $record_exists ) {
340
-
341
- $wpdb->insert(
342
- $wpdb->prefix . 'postmeta',
343
- array(
344
- 'post_id' => $post_id,
345
- 'meta_key' => $key,
346
- 'meta_value' => $template, // ... and so on
347
- )
348
- );
349
- } else {
350
-
351
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
352
- }
353
- } else {
354
-
355
- update_post_meta( $post_id, $key, $template );
356
- }
357
- }
358
-
359
- /**
360
- * Load font awesome style from oceanwp on checkout page.
361
- */
362
- public function load_fontawesome() {
363
-
364
- $theme = get_template();
365
-
366
- if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
367
-
368
- $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
369
-
370
- if ( $load_fa ) {
371
-
372
- wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
373
- }
374
-
375
- $custom_css = '
376
- #oceanwp-cart-sidebar-wrap,
377
- #owp-qv-wrap{
378
- display: none;
379
- }';
380
-
381
- wp_add_inline_style( 'wcf-frontend-global', $custom_css );
382
- }
383
- }
384
- }
385
- }
386
-
387
- Cartflows_Compatibility::get_instance();
388
-
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Page builder compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
9
+
10
+ /**
11
+ * Class for page builder compatibility
12
+ */
13
+ class Cartflows_Compatibility {
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
+ $this->load_files();
38
+
39
+ // Override post meta.
40
+ add_action( 'wp', array( $this, 'override_meta' ), 0 );
41
+
42
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
43
+ }
44
+
45
+ /**
46
+ * Load page builder compatibility files
47
+ */
48
+ public function load_files() {
49
+ if ( class_exists( '\Elementor\Plugin' ) ) {
50
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
51
+ }
52
+
53
+ if ( $this->is_divi_enabled() ) {
54
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
55
+ }
56
+
57
+ if ( $this->is_bb_enabled() ) {
58
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
59
+ }
60
+
61
+ if ( class_exists( 'TCB_Post' ) ) {
62
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Check if it is beaver builder enabled.
68
+ *
69
+ * @since 1.1.4
70
+ */
71
+ public function is_bb_enabled() {
72
+
73
+ if ( class_exists( 'FLBuilderModel' ) ) {
74
+ return true;
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if elementor preview mode is on.
82
+ */
83
+ public function is_elementor_preview_mode() {
84
+
85
+ if ( class_exists( '\Elementor\Plugin' ) ) {
86
+
87
+ if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
88
+ return true;
89
+ }
90
+ }
91
+
92
+ return false;
93
+ }
94
+
95
+ /**
96
+ * Get Current Theme.
97
+ */
98
+ public function get_current_theme() {
99
+
100
+ $theme_name = '';
101
+ $theme = wp_get_theme();
102
+
103
+ if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
104
+ $theme_name = $theme->parent_theme;
105
+ } else {
106
+ $theme_name = $theme->name;
107
+ }
108
+
109
+ return $theme_name;
110
+ }
111
+
112
+ /**
113
+ * Check if it is beaver builder preview mode
114
+ */
115
+ public function is_bb_preview_mode() {
116
+
117
+ if ( class_exists( 'FLBuilderModel' ) ) {
118
+ if ( FLBuilderModel::is_builder_active() ) {
119
+ return true;
120
+ } else {
121
+ return false;
122
+ }
123
+ }
124
+
125
+ return false;
126
+ }
127
+
128
+ /**
129
+ * Check for page builder preview mode.
130
+ */
131
+ public function is_page_builder_preview() {
132
+
133
+ global $post;
134
+
135
+ $post_id = $post->ID;
136
+
137
+ if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_enabled( $post_id ) || $this->is_divi_enabled() ) {
138
+ return true;
139
+ }
140
+
141
+ return false;
142
+ }
143
+
144
+ /**
145
+ * Check if divi builder enabled for post id.
146
+ *
147
+ * @param int $post_id post id.
148
+ */
149
+ public function is_divi_builder_enabled( $post_id ) {
150
+
151
+ if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
152
+ return true;
153
+ }
154
+
155
+ return false;
156
+ }
157
+
158
+ /**
159
+ * Check if compatibility theme enabled.
160
+ */
161
+ function is_compatibility_theme_enabled() {
162
+
163
+ $theme = wp_get_theme();
164
+
165
+ $is_compatibility = false;
166
+
167
+ if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
168
+
169
+ $is_compatibility = true;
170
+ }
171
+
172
+ return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
173
+ }
174
+
175
+ /**
176
+ * Check if divi builder enabled for post id.
177
+ *
178
+ * @param object $theme theme data.
179
+ * @return boolean
180
+ */
181
+ function is_divi_enabled( $theme = false ) {
182
+
183
+ if ( ! $theme ) {
184
+ $theme = wp_get_theme();
185
+ }
186
+
187
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
188
+ return true;
189
+ }
190
+
191
+ return false;
192
+ }
193
+
194
+ /**
195
+ * Check if Divi theme is install status.
196
+ *
197
+ * @return boolean
198
+ */
199
+ function is_divi_theme_installed() {
200
+ foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
201
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
202
+ return true;
203
+ }
204
+ }
205
+ return false;
206
+ }
207
+
208
+ /**
209
+ * Check if Flatsome enabled for post id.
210
+ *
211
+ * @param object $theme theme data.
212
+ * @return boolean
213
+ */
214
+ function is_flatsome_enabled( $theme = false ) {
215
+
216
+ if ( ! $theme ) {
217
+ $theme = wp_get_theme();
218
+ }
219
+
220
+ if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
221
+ return true;
222
+ }
223
+
224
+ return false;
225
+ }
226
+
227
+ /**
228
+ * Check if The7 enabled for post id.
229
+ *
230
+ * @param object $theme theme data.
231
+ * @return boolean
232
+ */
233
+ function is_the_seven_enabled( $theme = false ) {
234
+
235
+ if ( ! $theme ) {
236
+ $theme = wp_get_theme();
237
+ }
238
+
239
+ if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
240
+ return true;
241
+ }
242
+
243
+ return false;
244
+ }
245
+
246
+ /**
247
+ * Check if OceanWp enabled for post id.
248
+ *
249
+ * @param object $theme theme data.
250
+ * @return boolean
251
+ */
252
+ function is_oceanwp_enabled( $theme = false ) {
253
+
254
+ if ( ! $theme ) {
255
+ $theme = wp_get_theme();
256
+ }
257
+
258
+ if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
259
+ return true;
260
+ }
261
+
262
+ return false;
263
+ }
264
+
265
+ /**
266
+ * Check for thrive architect edit page.
267
+ *
268
+ * @param int $post_id post id.
269
+ */
270
+ public function is_thrive_edit_page( $post_id ) {
271
+
272
+ if ( true === $this->is_thrive_builder_page( $post_id ) ) {
273
+ return true;
274
+ } else {
275
+ return false;
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Check if the page being rendered is the main ID on the editor page.
281
+ *
282
+ * @since 1.0.0
283
+ * @param String $post_id Post ID which is to be rendered.
284
+ * @return boolean True if current if is being rendered is not being edited.
285
+ */
286
+ private function is_thrive_builder_page( $post_id ) {
287
+ $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
288
+ $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
289
+
290
+ return ( true == $tve && $post_id !== $post );
291
+ }
292
+
293
+ /**
294
+ * Overwrite meta for page
295
+ */
296
+ public function override_meta() {
297
+
298
+ // don't override meta for `elementor_library` post type.
299
+ if ( 'elementor_library' == get_post_type() ) {
300
+ return;
301
+ }
302
+
303
+ if ( ! is_singular() ) {
304
+ return;
305
+ }
306
+
307
+ global $post;
308
+ $post_id = $post->ID;
309
+ $post_type = get_post_type();
310
+
311
+ if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
312
+ || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
313
+ || $this->is_divi_builder_enabled( $post_id ) ) ) {
314
+
315
+ if ( '' == $post->post_content ) {
316
+
317
+ $this->overwrite_template( $post_id );
318
+ }
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Assign cartflow canvas template to page.
324
+ *
325
+ * @param int $post_id post ID.
326
+ */
327
+ public function overwrite_template( $post_id ) {
328
+
329
+ $template = 'cartflows-canvas';
330
+ $key = '_wp_page_template';
331
+
332
+ $record_exists = get_post_meta( $post_id, $key, true );
333
+
334
+ if ( 'cartflows-canvas' == $record_exists ) {
335
+ return;
336
+ }
337
+
338
+ // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
339
+ if ( class_exists( '\Elementor\Plugin' ) ) {
340
+
341
+ global $wpdb;
342
+
343
+ if ( '' == $record_exists || ! $record_exists ) {
344
+
345
+ $wpdb->insert(
346
+ $wpdb->prefix . 'postmeta',
347
+ array(
348
+ 'post_id' => $post_id,
349
+ 'meta_key' => $key,
350
+ 'meta_value' => $template, // ... and so on
351
+ )
352
+ );
353
+ } else {
354
+
355
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
356
+ }
357
+ } else {
358
+
359
+ update_post_meta( $post_id, $key, $template );
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Load font awesome style from oceanwp on checkout page.
365
+ */
366
+ public function load_fontawesome() {
367
+
368
+ $theme = get_template();
369
+
370
+ if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
371
+
372
+ $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
373
+
374
+ if ( $load_fa ) {
375
+
376
+ wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
377
+ }
378
+
379
+ $custom_css = '
380
+ #oceanwp-cart-sidebar-wrap,
381
+ #owp-qv-wrap{
382
+ display: none;
383
+ }';
384
+
385
+ wp_add_inline_style( 'wcf-frontend-global', $custom_css );
386
+ }
387
+ }
388
+ }
389
+ }
390
+
391
+ Cartflows_Compatibility::get_instance();
392
+
classes/class-cartflows-default-meta.php CHANGED
@@ -1,926 +1,926 @@
1
- <?php
2
- /**
3
- * Cartflow default options.
4
- *
5
- * @package Cartflows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Default_Meta {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var checkout_fields
27
- */
28
- private static $checkout_fields = null;
29
-
30
- /**
31
- * Member Variable
32
- *
33
- * @var checkout_fields
34
- */
35
- private static $thankyou_fields = null;
36
-
37
- /**
38
- * Member Variable
39
- *
40
- * @var flow_fields
41
- */
42
- private static $flow_fields = null;
43
-
44
- /**
45
- * Member Variable
46
- *
47
- * @var landing_fields
48
- */
49
- private static $landing_fields = null;
50
-
51
- /**
52
- * Initiator
53
- */
54
- public static function get_instance() {
55
- if ( ! isset( self::$instance ) ) {
56
- self::$instance = new self;
57
- }
58
- return self::$instance;
59
- }
60
-
61
- /**
62
- * Constructor
63
- */
64
- public function __construct() {
65
-
66
- }
67
-
68
- /**
69
- * Checkout Default fields.
70
- *
71
- * @param int $post_id post id.
72
- * @return array
73
- */
74
- function get_checkout_fields( $post_id ) {
75
-
76
- if ( null === self::$checkout_fields ) {
77
-
78
- self::$checkout_fields = array(
79
- 'wcf-field-google-font-url' => array(
80
- 'default' => '',
81
- 'sanitize' => 'FILTER_DEFAULT',
82
- ),
83
- 'wcf-checkout-products' => array(
84
- 'default' => array(),
85
- 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
86
- ),
87
- 'wcf-checkout-layout' => array(
88
- 'default' => 'two-column',
89
- 'sanitize' => 'FILTER_DEFAULT',
90
- ),
91
- 'wcf-input-font-family' => array(
92
- 'default' => '',
93
- 'sanitize' => 'FILTER_DEFAULT',
94
- ),
95
- 'wcf-input-font-weight' => array(
96
- 'default' => '',
97
- 'sanitize' => 'FILTER_DEFAULT',
98
- ),
99
- 'wcf-heading-font-family' => array(
100
- 'default' => '',
101
- 'sanitize' => 'FILTER_DEFAULT',
102
- ),
103
- 'wcf-heading-font-weight' => array(
104
- 'default' => '',
105
- 'sanitize' => 'FILTER_DEFAULT',
106
- ),
107
- 'wcf-base-font-family' => array(
108
- 'default' => '',
109
- 'sanitize' => 'FILTER_DEFAULT',
110
- ),
111
- 'wcf-advance-options-fields' => array(
112
- 'default' => '',
113
- 'sanitize' => 'FILTER_DEFAULT',
114
- ),
115
- 'wcf-base-font-weight' => array(
116
- 'default' => '',
117
- 'sanitize' => 'FILTER_DEFAULT',
118
- ),
119
- 'wcf-button-font-family' => array(
120
- 'default' => '',
121
- 'sanitize' => 'FILTER_DEFAULT',
122
- ),
123
- 'wcf-button-font-weight' => array(
124
- 'default' => '',
125
- 'sanitize' => 'FILTER_DEFAULT',
126
- ),
127
- 'wcf-primary-color' => array(
128
- 'default' => '',
129
- 'sanitize' => 'FILTER_DEFAULT',
130
- ),
131
- 'wcf-heading-color' => array(
132
- 'default' => '',
133
- 'sanitize' => 'FILTER_DEFAULT',
134
- ),
135
- 'wcf-section-bg-color' => array(
136
- 'default' => '',
137
- 'sanitize' => 'FILTER_DEFAULT',
138
- ),
139
- 'wcf-hl-bg-color' => array(
140
- 'default' => '',
141
- 'sanitize' => 'FILTER_DEFAULT',
142
- ),
143
- 'wcf-field-tb-padding' => array(
144
- 'default' => '',
145
- 'sanitize' => 'FILTER_DEFAULT',
146
- ),
147
- 'wcf-field-lr-padding' => array(
148
- 'default' => '',
149
- 'sanitize' => 'FILTER_DEFAULT',
150
- ),
151
- 'wcf-fields-skins' => array(
152
- 'default' => '',
153
- 'sanitize' => 'FILTER_DEFAULT',
154
- ),
155
- 'wcf-input-field-size' => array(
156
- 'default' => '33px',
157
- 'sanitize' => 'FILTER_DEFAULT',
158
- ),
159
- 'wcf-field-color' => array(
160
- 'default' => '',
161
- 'sanitize' => 'FILTER_DEFAULT',
162
- ),
163
- 'wcf-field-bg-color' => array(
164
- 'default' => '',
165
- 'sanitize' => 'FILTER_DEFAULT',
166
- ),
167
- 'wcf-field-border-color' => array(
168
- 'default' => '',
169
- 'sanitize' => 'FILTER_DEFAULT',
170
- ),
171
- 'wcf-box-border-color' => array(
172
- 'default' => '',
173
- 'sanitize' => 'FILTER_DEFAULT',
174
- ),
175
- 'wcf-field-label-color' => array(
176
- 'default' => '',
177
- 'sanitize' => 'FILTER_DEFAULT',
178
- ),
179
- 'wcf-submit-tb-padding' => array(
180
- 'default' => '',
181
- 'sanitize' => 'FILTER_DEFAULT',
182
- ),
183
- 'wcf-submit-lr-padding' => array(
184
- 'default' => '',
185
- 'sanitize' => 'FILTER_DEFAULT',
186
- ),
187
- 'wcf-input-button-size' => array(
188
- 'default' => '33px',
189
- 'sanitize' => 'FILTER_DEFAULT',
190
- ),
191
- 'wcf-submit-color' => array(
192
- 'default' => '',
193
- 'sanitize' => 'FILTER_DEFAULT',
194
- ),
195
- 'wcf-submit-hover-color' => array(
196
- 'default' => '',
197
- 'sanitize' => 'FILTER_DEFAULT',
198
- ),
199
- 'wcf-submit-bg-color' => array(
200
- 'default' => '',
201
- 'sanitize' => 'FILTER_DEFAULT',
202
- ),
203
- 'wcf-submit-bg-hover-color' => array(
204
- 'default' => '',
205
- 'sanitize' => 'FILTER_DEFAULT',
206
- ),
207
- 'wcf-submit-border-color' => array(
208
- 'default' => '',
209
- 'sanitize' => 'FILTER_DEFAULT',
210
- ),
211
- 'wcf-submit-border-hover-color' => array(
212
- 'default' => '',
213
- 'sanitize' => 'FILTER_DEFAULT',
214
- ),
215
- 'wcf-active-tab' => array(
216
- 'default' => '',
217
- 'sanitize' => 'FILTER_DEFAULT',
218
- ),
219
- 'wcf-header-logo-image' => array(
220
- 'default' => '',
221
- 'sanitize' => 'FILTER_DEFAULT',
222
- ),
223
- 'wcf-header-logo-width' => array(
224
- 'default' => '',
225
- 'sanitize' => 'FILTER_DEFAULT',
226
- ),
227
- 'wcf-custom-script' => array(
228
- 'default' => '',
229
- 'sanitize' => 'FILTER_DEFAULT',
230
- ),
231
- );
232
-
233
- self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
234
- }
235
-
236
- return self::$checkout_fields;
237
- }
238
-
239
- /**
240
- * Save Checkout Meta fields.
241
- *
242
- * @param int $post_id post id.
243
- * @return void
244
- */
245
- function save_checkout_fields( $post_id ) {
246
-
247
- $post_meta = $this->get_checkout_fields( $post_id );
248
-
249
- $this->save_meta_fields( $post_id, $post_meta );
250
- }
251
-
252
- /**
253
- * Save Landing Meta fields.
254
- *
255
- * @param int $post_id post id.
256
- * @return void
257
- */
258
- function save_landing_fields( $post_id ) {
259
-
260
- $post_meta = $this->get_landing_fields( $post_id );
261
-
262
- $this->save_meta_fields( $post_id, $post_meta );
263
- }
264
-
265
- /**
266
- * Save ThankYou Meta fields.
267
- *
268
- * @param int $post_id post id.
269
- * @return void
270
- */
271
- function save_thankyou_fields( $post_id ) {
272
-
273
- $post_meta = $this->get_thankyou_fields( $post_id );
274
-
275
- $this->save_meta_fields( $post_id, $post_meta );
276
- }
277
-
278
- /**
279
- * Flow Default fields.
280
- *
281
- * @param int $post_id post id.
282
- * @return array
283
- */
284
- function get_flow_fields( $post_id ) {
285
-
286
- if ( null === self::$flow_fields ) {
287
-
288
- self::$flow_fields = array(
289
- 'wcf-steps' => array(
290
- 'default' => array(),
291
- 'sanitize' => 'FILTER_DEFAULT',
292
- ),
293
-
294
- 'wcf-testing' => array(
295
- 'default' => 'yes',
296
- 'sanitize' => 'FILTER_DEFAULT',
297
- ),
298
- );
299
- }
300
-
301
- return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
302
- }
303
-
304
- /**
305
- * Save Flow Meta fields.
306
- *
307
- * @param int $post_id post id.
308
- * @return void
309
- */
310
- function save_flow_fields( $post_id ) {
311
-
312
- $post_meta = $this->get_flow_fields( $post_id );
313
-
314
- if ( isset( $post_meta['wcf-steps'] ) ) {
315
- unset( $post_meta['wcf-steps'] );
316
- }
317
-
318
- $this->save_meta_fields( $post_id, $post_meta );
319
- }
320
-
321
- /**
322
- * Save Meta fields - Common Function.
323
- *
324
- * @param int $post_id post id.
325
- * @param array $post_meta options to store.
326
- * @return void
327
- */
328
- function save_meta_fields( $post_id, $post_meta ) {
329
-
330
- if ( ! ( $post_id && is_array( $post_meta ) ) ) {
331
-
332
- return;
333
- }
334
-
335
- foreach ( $post_meta as $key => $data ) {
336
-
337
- $meta_value = false;
338
-
339
- // Sanitize values.
340
- $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
341
-
342
- switch ( $sanitize_filter ) {
343
-
344
- case 'FILTER_SANITIZE_STRING':
345
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
346
- break;
347
-
348
- case 'FILTER_SANITIZE_URL':
349
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
350
- break;
351
-
352
- case 'FILTER_SANITIZE_NUMBER_INT':
353
- $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
354
- break;
355
-
356
- case 'FILTER_CARTFLOWS_ARRAY':
357
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
358
- $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
359
- }
360
- break;
361
-
362
- case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
363
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
364
-
365
- $i = 0;
366
- $q = 0;
367
-
368
- foreach ( $_POST[ $key ] as $p_index => $p_data ) {
369
-
370
- foreach ( $p_data as $i_key => $i_value ) {
371
-
372
- if ( is_array( $i_value ) ) {
373
-
374
- foreach ( $i_value as $q_key => $q_value ) {
375
-
376
- $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
377
-
378
- $q++;
379
- }
380
- } else {
381
- $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
382
- }
383
- }
384
-
385
- $i++;
386
- }
387
- }
388
- break;
389
- case 'FILTER_CARTFLOWS_CHECKOUT_FIELDS':
390
- $count = 10;
391
- $ordered_fields = array();
392
- $billing_fields = array();
393
-
394
- if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
395
- $post_data = $_POST[ $key ];
396
-
397
- if ( 'wcf_field_order_billing' == $key ) {
398
-
399
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
400
-
401
- foreach ( $post_data as $index => $value ) {
402
-
403
- if ( isset( $billing_fields[ $value ] ) ) {
404
- $ordered_fields[ $value ] = $billing_fields[ $value ];
405
- $ordered_fields[ $value ]['priority'] = $count;
406
- $count += 10;
407
- }
408
- }
409
-
410
- $meta_value = $ordered_fields;
411
- }
412
-
413
- if ( 'wcf_field_order_shipping' == $key ) {
414
-
415
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
416
- foreach ( $post_data as $index => $value ) {
417
-
418
- if ( isset( $shipping_fields[ $value ] ) ) {
419
- $ordered_fields[ $value ] = $shipping_fields[ $value ];
420
- $ordered_fields[ $value ]['priority'] = $count;
421
- $count += 10;
422
- }
423
- }
424
- $meta_value = $ordered_fields;
425
- }
426
-
427
- if ( 'wcf_label_text_field_billing' == $key ) {
428
-
429
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
430
-
431
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
432
- echo 'con 1';
433
- $billing_fields = $get_ordered_billing_fields;
434
- } else {
435
- echo 'con 2';
436
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
437
- }
438
-
439
- foreach ( $post_data as $index => $value ) {
440
-
441
- if ( isset( $billing_fields[ $index ] ) ) {
442
- $ordered_fields[ $index ] = $billing_fields[ $index ];
443
- $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
444
- }
445
- }
446
- $key = 'wcf_field_order_billing';
447
- $meta_value = $ordered_fields;
448
- }
449
-
450
- if ( 'wcf_label_text_field_shipping' == $key ) {
451
-
452
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
453
-
454
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
455
- $shipping_fields = $get_ordered_shipping_fields;
456
- } else {
457
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
458
- }
459
-
460
- foreach ( $post_data as $index => $value ) {
461
-
462
- if ( isset( $shipping_fields[ $index ] ) ) {
463
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
464
- $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
465
- }
466
- }
467
- $key = 'wcf_field_order_shipping';
468
- $meta_value = $ordered_fields;
469
- }
470
-
471
- if ( 'wcf_label_placeholder_field_billing' == $key ) {
472
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
473
-
474
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
475
- $billing_fields = $get_ordered_billing_fields;
476
- } else {
477
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
478
- }
479
- foreach ( $post_data as $index => $value ) {
480
-
481
- if ( isset( $billing_fields[ $index ] ) ) {
482
- $ordered_fields[ $index ] = $billing_fields[ $index ];
483
- $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
484
- }
485
- }
486
-
487
- $key = 'wcf_field_order_billing';
488
- $meta_value = $ordered_fields;
489
- }
490
-
491
- if ( 'wcf_label_placeholder_field_shipping' == $key ) {
492
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
493
-
494
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
495
- $shipping_fields = $get_ordered_shipping_fields;
496
- } else {
497
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
498
- }
499
-
500
- foreach ( $post_data as $index => $value ) {
501
-
502
- if ( isset( $shipping_fields[ $index ] ) ) {
503
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
504
- $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
505
- }
506
- }
507
-
508
- $key = 'wcf_field_order_shipping';
509
- $meta_value = $ordered_fields;
510
-
511
- }
512
-
513
- if ( 'wcf_label_default_field_billing' == $key ) {
514
-
515
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
516
-
517
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
518
- $billing_fields = $get_ordered_billing_fields;
519
- } else {
520
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
521
- }
522
-
523
- foreach ( $post_data as $index => $value ) {
524
-
525
- if ( isset( $billing_fields[ $index ] ) ) {
526
- $ordered_fields[ $index ] = $billing_fields[ $index ];
527
- $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
528
- }
529
- }
530
-
531
- $key = 'wcf_field_order_billing';
532
- $meta_value = $ordered_fields;
533
- }
534
-
535
- if ( 'wcf_label_default_field_shipping' == $key ) {
536
-
537
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
538
-
539
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
540
- $shipping_fields = $get_ordered_shipping_fields;
541
- } else {
542
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
543
- }
544
-
545
- foreach ( $post_data as $index => $value ) {
546
-
547
- if ( isset( $shipping_fields[ $index ] ) ) {
548
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
549
- $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
550
- }
551
- }
552
-
553
- $key = 'wcf_field_order_shipping';
554
- $meta_value = $ordered_fields;
555
- }
556
-
557
- if ( 'wcf_is_required_field_billing' == $key ) {
558
-
559
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
560
-
561
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
562
- $billing_fields = $get_ordered_billing_fields;
563
- } else {
564
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
565
- }
566
-
567
- foreach ( $post_data as $index => $value ) {
568
-
569
- if ( isset( $billing_fields[ $index ] ) ) {
570
- $ordered_fields[ $index ] = $billing_fields[ $index ];
571
- if ( 'yes' == $value ) {
572
-
573
- $ordered_fields[ $index ]['required'] = true;
574
- } else {
575
- $ordered_fields[ $index ]['required'] = false;
576
- }
577
- }
578
- }
579
-
580
- $key = 'wcf_field_order_billing';
581
- $meta_value = $ordered_fields;
582
- }
583
-
584
- if ( 'wcf_is_required_field_shipping' == $key ) {
585
-
586
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
587
-
588
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
589
- $shipping_fields = $get_ordered_shipping_fields;
590
- } else {
591
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
592
- }
593
-
594
- foreach ( $post_data as $index => $value ) {
595
-
596
- if ( isset( $shipping_fields[ $index ] ) ) {
597
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
598
-
599
- if ( 'yes' == $value ) {
600
-
601
- $ordered_fields[ $index ]['required'] = true;
602
- } else {
603
- $ordered_fields[ $index ]['required'] = false;
604
- }
605
- }
606
- }
607
-
608
- $key = 'wcf_field_order_shipping';
609
- $meta_value = $ordered_fields;
610
- }
611
-
612
- if ( 'wcf_select_option_field_billing' == $key ) {
613
-
614
- $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
615
-
616
- if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
617
- $billing_fields = $get_ordered_billing_fields;
618
- } else {
619
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
620
- }
621
-
622
- foreach ( $post_data as $index => $value ) {
623
-
624
- $options = explode( ',', $value );
625
-
626
- if ( isset( $billing_fields[ $index ] ) ) {
627
- $ordered_fields[ $index ] = $billing_fields[ $index ];
628
-
629
- $ordered_fields[ $index ]['options'] = array();
630
-
631
- foreach ( $options as $key => $option ) {
632
-
633
- $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
634
- }
635
- }
636
- }
637
-
638
- $key = 'wcf_field_order_billing';
639
- $meta_value = $ordered_fields;
640
- }
641
-
642
- if ( 'wcf_select_option_field_shipping' == $key ) {
643
-
644
- $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
645
-
646
- if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
647
- $shipping_fields = $get_ordered_shipping_fields;
648
- } else {
649
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
650
- }
651
-
652
- foreach ( $post_data as $index => $value ) {
653
-
654
- $options = explode( ',', $value );
655
-
656
- if ( isset( $shipping_fields[ $index ] ) ) {
657
-
658
- $ordered_fields[ $index ] = $shipping_fields[ $index ];
659
-
660
- $ordered_fields[ $index ]['options'] = array();
661
-
662
- foreach ( $options as $key => $option ) {
663
-
664
- $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
665
- }
666
- }
667
- }
668
-
669
- $key = 'wcf_field_order_shipping';
670
- $meta_value = $ordered_fields;
671
- }
672
- }
673
- break;
674
-
675
- default:
676
- $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
677
- break;
678
- }
679
-
680
- if ( false !== $meta_value ) {
681
- update_post_meta( $post_id, $key, $meta_value );
682
- } else {
683
- delete_post_meta( $post_id, $key );
684
- }
685
- }
686
- }
687
-
688
- /**
689
- * Get checkout meta.
690
- *
691
- * @param int $post_id post id.
692
- * @param string $key options key.
693
- * @param mix $default options default value.
694
- * @return string
695
- */
696
- function get_flow_meta_value( $post_id, $key, $default = false ) {
697
-
698
- $value = $this->get_save_meta( $post_id, $key );
699
-
700
- if ( ! $value ) {
701
-
702
- if ( $default ) {
703
-
704
- $value = $default;
705
- } else {
706
-
707
- $fields = $this->get_flow_fields( $post_id );
708
-
709
- if ( isset( $fields[ $key ]['default'] ) ) {
710
-
711
- $value = $fields[ $key ]['default'];
712
- }
713
- }
714
- }
715
-
716
- return $value;
717
- }
718
-
719
- /**
720
- * Get checkout meta.
721
- *
722
- * @param int $post_id post id.
723
- * @param string $key options key.
724
- * @param mix $default options default value.
725
- * @return string
726
- */
727
- function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
728
-
729
- $value = $this->get_save_meta( $post_id, $key );
730
-
731
- if ( ! $value ) {
732
-
733
- if ( $default ) {
734
-
735
- $value = $default;
736
- } else {
737
-
738
- $fields = $this->get_checkout_fields( $post_id );
739
-
740
- if ( isset( $fields[ $key ]['default'] ) ) {
741
-
742
- $value = $fields[ $key ]['default'];
743
- }
744
- }
745
- }
746
-
747
- return $value;
748
- }
749
-
750
- /**
751
- * Get post meta.
752
- *
753
- * @param int $post_id post id.
754
- * @param string $key options key.
755
- * @return string
756
- */
757
- function get_save_meta( $post_id, $key ) {
758
-
759
- $value = get_post_meta( $post_id, $key, true );
760
-
761
- return $value;
762
- }
763
-
764
- /**
765
- * Thank You Default fields.
766
- *
767
- * @param int $post_id post id.
768
- * @return array
769
- */
770
- function get_thankyou_fields( $post_id ) {
771
-
772
- if ( null === self::$thankyou_fields ) {
773
-
774
- self::$thankyou_fields = array(
775
- 'wcf-field-google-font-url' => array(
776
- 'default' => '',
777
- 'sanitize' => 'FILTER_DEFAULT',
778
- ),
779
- 'wcf-active-tab' => array(
780
- 'default' => '',
781
- 'sanitize' => 'FILTER_DEFAULT',
782
- ),
783
- 'wcf-tq-text-color' => array(
784
- 'default' => '',
785
- 'sanitize' => 'FILTER_DEFAULT',
786
- ),
787
- 'wcf-tq-font-family' => array(
788
- 'default' => '',
789
- 'sanitize' => 'FILTER_DEFAULT',
790
- ),
791
- 'wcf-tq-heading-color' => array(
792
- 'default' => '',
793
- 'sanitize' => 'FILTER_DEFAULT',
794
- ),
795
- 'wcf-tq-heading-font-family' => array(
796
- 'default' => '',
797
- 'sanitize' => 'FILTER_DEFAULT',
798
- ),
799
- 'wcf-tq-heading-font-wt' => array(
800
- 'default' => '',
801
- 'sanitize' => 'FILTER_DEFAULT',
802
- ),
803
- 'wcf-tq-container-width' => array(
804
- 'default' => '',
805
- 'sanitize' => 'FILTER_DEFAULT',
806
- ),
807
- 'wcf-tq-section-bg-color' => array(
808
- 'default' => '',
809
- 'sanitize' => 'FILTER_DEFAULT',
810
- ),
811
- 'wcf-tq-advance-options-fields' => array(
812
- 'default' => '',
813
- 'sanitize' => 'FILTER_DEFAULT',
814
- ),
815
- 'wcf-show-overview-section' => array(
816
- 'default' => 'yes',
817
- 'sanitize' => 'FILTER_DEFAULT',
818
- ),
819
- 'wcf-show-details-section' => array(
820
- 'default' => 'yes',
821
- 'sanitize' => 'FILTER_DEFAULT',
822
- ),
823
- 'wcf-show-billing-section' => array(
824
- 'default' => 'yes',
825
- 'sanitize' => 'FILTER_DEFAULT',
826
- ),
827
- 'wcf-show-shipping-section' => array(
828
- 'default' => 'yes',
829
- 'sanitize' => 'FILTER_DEFAULT',
830
- ),
831
- 'wcf-custom-script' => array(
832
- 'default' => '',
833
- 'sanitize' => 'FILTER_DEFAULT',
834
- ),
835
- );
836
-
837
- }
838
-
839
- return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
840
- }
841
-
842
- /**
843
- * Get Thank you section meta.
844
- *
845
- * @param int $post_id post id.
846
- * @param string $key options key.
847
- * @param mix $default options default value.
848
- * @return string
849
- */
850
- function get_thankyou_meta_value( $post_id, $key, $default = false ) {
851
-
852
- $value = $this->get_save_meta( $post_id, $key );
853
-
854
- if ( ! $value ) {
855
-
856
- if ( $default ) {
857
-
858
- $value = $default;
859
- } else {
860
-
861
- $fields = $this->get_thankyou_fields( $post_id );
862
-
863
- if ( isset( $fields[ $key ]['default'] ) ) {
864
-
865
- $value = $fields[ $key ]['default'];
866
- }
867
- }
868
- }
869
-
870
- return $value;
871
- }
872
-
873
- /**
874
- * Get Landing section meta.
875
- *
876
- * @param int $post_id post id.
877
- * @param string $key options key.
878
- * @param mix $default options default value.
879
- * @return string
880
- */
881
- function get_landing_meta_value( $post_id, $key, $default = false ) {
882
-
883
- $value = $this->get_save_meta( $post_id, $key );
884
- if ( ! $value ) {
885
-
886
- if ( $default ) {
887
-
888
- $value = $default;
889
- } else {
890
-
891
- $fields = $this->get_landing_fields( $post_id );
892
-
893
- if ( isset( $fields[ $key ]['default'] ) ) {
894
- $value = $fields[ $key ]['default'];
895
- }
896
- }
897
- }
898
-
899
- return $value;
900
- }
901
-
902
- /**
903
- * Thank You Default fields.
904
- *
905
- * @param int $post_id post id.
906
- * @return array
907
- */
908
- function get_landing_fields( $post_id ) {
909
-
910
- if ( null === self::$landing_fields ) {
911
-
912
- self::$landing_fields = array(
913
- 'wcf-custom-script' => array(
914
- 'default' => '',
915
- 'sanitize' => 'FILTER_DEFAULT',
916
- ),
917
- );
918
- }
919
- return apply_filters( 'cartflows_landing_meta_options', self::$landing_fields, $post_id );
920
- }
921
- }
922
-
923
- /**
924
- * Kicking this off by calling 'get_instance()' method
925
- */
926
- Cartflows_Default_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Cartflow default options.
4
+ *
5
+ * @package Cartflows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Default_Meta {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var checkout_fields
27
+ */
28
+ private static $checkout_fields = null;
29
+
30
+ /**
31
+ * Member Variable
32
+ *
33
+ * @var checkout_fields
34
+ */
35
+ private static $thankyou_fields = null;
36
+
37
+ /**
38
+ * Member Variable
39
+ *
40
+ * @var flow_fields
41
+ */
42
+ private static $flow_fields = null;
43
+
44
+ /**
45
+ * Member Variable
46
+ *
47
+ * @var landing_fields
48
+ */
49
+ private static $landing_fields = null;
50
+
51
+ /**
52
+ * Initiator
53
+ */
54
+ public static function get_instance() {
55
+ if ( ! isset( self::$instance ) ) {
56
+ self::$instance = new self;
57
+ }
58
+ return self::$instance;
59
+ }
60
+
61
+ /**
62
+ * Constructor
63
+ */
64
+ public function __construct() {
65
+
66
+ }
67
+
68
+ /**
69
+ * Checkout Default fields.
70
+ *
71
+ * @param int $post_id post id.
72
+ * @return array
73
+ */
74
+ function get_checkout_fields( $post_id ) {
75
+
76
+ if ( null === self::$checkout_fields ) {
77
+
78
+ self::$checkout_fields = array(
79
+ 'wcf-field-google-font-url' => array(
80
+ 'default' => '',
81
+ 'sanitize' => 'FILTER_DEFAULT',
82
+ ),
83
+ 'wcf-checkout-products' => array(
84
+ 'default' => array(),
85
+ 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
86
+ ),
87
+ 'wcf-checkout-layout' => array(
88
+ 'default' => 'two-column',
89
+ 'sanitize' => 'FILTER_DEFAULT',
90
+ ),
91
+ 'wcf-input-font-family' => array(
92
+ 'default' => '',
93
+ 'sanitize' => 'FILTER_DEFAULT',
94
+ ),
95
+ 'wcf-input-font-weight' => array(
96
+ 'default' => '',
97
+ 'sanitize' => 'FILTER_DEFAULT',
98
+ ),
99
+ 'wcf-heading-font-family' => array(
100
+ 'default' => '',
101
+ 'sanitize' => 'FILTER_DEFAULT',
102
+ ),
103
+ 'wcf-heading-font-weight' => array(
104
+ 'default' => '',
105
+ 'sanitize' => 'FILTER_DEFAULT',
106
+ ),
107
+ 'wcf-base-font-family' => array(
108
+ 'default' => '',
109
+ 'sanitize' => 'FILTER_DEFAULT',
110
+ ),
111
+ 'wcf-advance-options-fields' => array(
112
+ 'default' => '',
113
+ 'sanitize' => 'FILTER_DEFAULT',
114
+ ),
115
+ 'wcf-base-font-weight' => array(
116
+ 'default' => '',
117
+ 'sanitize' => 'FILTER_DEFAULT',
118
+ ),
119
+ 'wcf-button-font-family' => array(
120
+ 'default' => '',
121
+ 'sanitize' => 'FILTER_DEFAULT',
122
+ ),
123
+ 'wcf-button-font-weight' => array(
124
+ 'default' => '',
125
+ 'sanitize' => 'FILTER_DEFAULT',
126
+ ),
127
+ 'wcf-primary-color' => array(
128
+ 'default' => '',
129
+ 'sanitize' => 'FILTER_DEFAULT',
130
+ ),
131
+ 'wcf-heading-color' => array(
132
+ 'default' => '',
133
+ 'sanitize' => 'FILTER_DEFAULT',
134
+ ),
135
+ 'wcf-section-bg-color' => array(
136
+ 'default' => '',
137
+ 'sanitize' => 'FILTER_DEFAULT',
138
+ ),
139
+ 'wcf-hl-bg-color' => array(
140
+ 'default' => '',
141
+ 'sanitize' => 'FILTER_DEFAULT',
142
+ ),
143
+ 'wcf-field-tb-padding' => array(
144
+ 'default' => '',
145
+ 'sanitize' => 'FILTER_DEFAULT',
146
+ ),
147
+ 'wcf-field-lr-padding' => array(
148
+ 'default' => '',
149
+ 'sanitize' => 'FILTER_DEFAULT',
150
+ ),
151
+ 'wcf-fields-skins' => array(
152
+ 'default' => '',
153
+ 'sanitize' => 'FILTER_DEFAULT',
154
+ ),
155
+ 'wcf-input-field-size' => array(
156
+ 'default' => '33px',
157
+ 'sanitize' => 'FILTER_DEFAULT',
158
+ ),
159
+ 'wcf-field-color' => array(
160
+ 'default' => '',
161
+ 'sanitize' => 'FILTER_DEFAULT',
162
+ ),
163
+ 'wcf-field-bg-color' => array(
164
+ 'default' => '',
165
+ 'sanitize' => 'FILTER_DEFAULT',
166
+ ),
167
+ 'wcf-field-border-color' => array(
168
+ 'default' => '',
169
+ 'sanitize' => 'FILTER_DEFAULT',
170
+ ),
171
+ 'wcf-box-border-color' => array(
172
+ 'default' => '',
173
+ 'sanitize' => 'FILTER_DEFAULT',
174
+ ),
175
+ 'wcf-field-label-color' => array(
176
+ 'default' => '',
177
+ 'sanitize' => 'FILTER_DEFAULT',
178
+ ),
179
+ 'wcf-submit-tb-padding' => array(
180
+ 'default' => '',
181
+ 'sanitize' => 'FILTER_DEFAULT',
182
+ ),
183
+ 'wcf-submit-lr-padding' => array(
184
+ 'default' => '',
185
+ 'sanitize' => 'FILTER_DEFAULT',
186
+ ),
187
+ 'wcf-input-button-size' => array(
188
+ 'default' => '33px',
189
+ 'sanitize' => 'FILTER_DEFAULT',
190
+ ),
191
+ 'wcf-submit-color' => array(
192
+ 'default' => '',
193
+ 'sanitize' => 'FILTER_DEFAULT',
194
+ ),
195
+ 'wcf-submit-hover-color' => array(
196
+ 'default' => '',
197
+ 'sanitize' => 'FILTER_DEFAULT',
198
+ ),
199
+ 'wcf-submit-bg-color' => array(
200
+ 'default' => '',
201
+ 'sanitize' => 'FILTER_DEFAULT',
202
+ ),
203
+ 'wcf-submit-bg-hover-color' => array(
204
+ 'default' => '',
205
+ 'sanitize' => 'FILTER_DEFAULT',
206
+ ),
207
+ 'wcf-submit-border-color' => array(
208
+ 'default' => '',
209
+ 'sanitize' => 'FILTER_DEFAULT',
210
+ ),
211
+ 'wcf-submit-border-hover-color' => array(
212
+ 'default' => '',
213
+ 'sanitize' => 'FILTER_DEFAULT',
214
+ ),
215
+ 'wcf-active-tab' => array(
216
+ 'default' => '',
217
+ 'sanitize' => 'FILTER_DEFAULT',
218
+ ),
219
+ 'wcf-header-logo-image' => array(
220
+ 'default' => '',
221
+ 'sanitize' => 'FILTER_DEFAULT',
222
+ ),
223
+ 'wcf-header-logo-width' => array(
224
+ 'default' => '',
225
+ 'sanitize' => 'FILTER_DEFAULT',
226
+ ),
227
+ 'wcf-custom-script' => array(
228
+ 'default' => '',
229
+ 'sanitize' => 'FILTER_DEFAULT',
230
+ ),
231
+ );
232
+
233
+ self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
234
+ }
235
+
236
+ return self::$checkout_fields;
237
+ }
238
+
239
+ /**
240
+ * Save Checkout Meta fields.
241
+ *
242
+ * @param int $post_id post id.
243
+ * @return void
244
+ */
245
+ function save_checkout_fields( $post_id ) {
246
+
247
+ $post_meta = $this->get_checkout_fields( $post_id );
248
+
249
+ $this->save_meta_fields( $post_id, $post_meta );
250
+ }
251
+
252
+ /**
253
+ * Save Landing Meta fields.
254
+ *
255
+ * @param int $post_id post id.
256
+ * @return void
257
+ */
258
+ function save_landing_fields( $post_id ) {
259
+
260
+ $post_meta = $this->get_landing_fields( $post_id );
261
+
262
+ $this->save_meta_fields( $post_id, $post_meta );
263
+ }
264
+
265
+ /**
266
+ * Save ThankYou Meta fields.
267
+ *
268
+ * @param int $post_id post id.
269
+ * @return void
270
+ */
271
+ function save_thankyou_fields( $post_id ) {
272
+
273
+ $post_meta = $this->get_thankyou_fields( $post_id );
274
+
275
+ $this->save_meta_fields( $post_id, $post_meta );
276
+ }
277
+
278
+ /**
279
+ * Flow Default fields.
280
+ *
281
+ * @param int $post_id post id.
282
+ * @return array
283
+ */
284
+ function get_flow_fields( $post_id ) {
285
+
286
+ if ( null === self::$flow_fields ) {
287
+
288
+ self::$flow_fields = array(
289
+ 'wcf-steps' => array(
290
+ 'default' => array(),
291
+ 'sanitize' => 'FILTER_DEFAULT',
292
+ ),
293
+
294
+ 'wcf-testing' => array(
295
+ 'default' => 'yes',
296
+ 'sanitize' => 'FILTER_DEFAULT',
297
+ ),
298
+ );
299
+ }
300
+
301
+ return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
302
+ }
303
+
304
+ /**
305
+ * Save Flow Meta fields.
306
+ *
307
+ * @param int $post_id post id.
308
+ * @return void
309
+ */
310
+ function save_flow_fields( $post_id ) {
311
+
312
+ $post_meta = $this->get_flow_fields( $post_id );
313
+
314
+ if ( isset( $post_meta['wcf-steps'] ) ) {
315
+ unset( $post_meta['wcf-steps'] );
316
+ }
317
+
318
+ $this->save_meta_fields( $post_id, $post_meta );
319
+ }
320
+
321
+ /**
322
+ * Save Meta fields - Common Function.
323
+ *
324
+ * @param int $post_id post id.
325
+ * @param array $post_meta options to store.
326
+ * @return void
327
+ */
328
+ function save_meta_fields( $post_id, $post_meta ) {
329
+
330
+ if ( ! ( $post_id && is_array( $post_meta ) ) ) {
331
+
332
+ return;
333
+ }
334
+
335
+ foreach ( $post_meta as $key => $data ) {
336
+
337
+ $meta_value = false;
338
+
339
+ // Sanitize values.
340
+ $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
341
+
342
+ switch ( $sanitize_filter ) {
343
+
344
+ case 'FILTER_SANITIZE_STRING':
345
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
346
+ break;
347
+
348
+ case 'FILTER_SANITIZE_URL':
349
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
350
+ break;
351
+
352
+ case 'FILTER_SANITIZE_NUMBER_INT':
353
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
354
+ break;
355
+
356
+ case 'FILTER_CARTFLOWS_ARRAY':
357
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
358
+ $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
359
+ }
360
+ break;
361
+
362
+ case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
363
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
364
+
365
+ $i = 0;
366
+ $q = 0;
367
+
368
+ foreach ( $_POST[ $key ] as $p_index => $p_data ) {
369
+
370
+ foreach ( $p_data as $i_key => $i_value ) {
371
+
372
+ if ( is_array( $i_value ) ) {
373
+
374
+ foreach ( $i_value as $q_key => $q_value ) {
375
+
376
+ $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
377
+
378
+ $q++;
379
+ }
380
+ } else {
381
+ $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
382
+ }
383
+ }
384
+
385
+ $i++;
386
+ }
387
+ }
388
+ break;
389
+ case 'FILTER_CARTFLOWS_CHECKOUT_FIELDS':
390
+ $count = 10;
391
+ $ordered_fields = array();
392
+ $billing_fields = array();
393
+
394
+ if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
395
+ $post_data = $_POST[ $key ];
396
+
397
+ if ( 'wcf_field_order_billing' == $key ) {
398
+
399
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
400
+
401
+ foreach ( $post_data as $index => $value ) {
402
+
403
+ if ( isset( $billing_fields[ $value ] ) ) {
404
+ $ordered_fields[ $value ] = $billing_fields[ $value ];
405
+ $ordered_fields[ $value ]['priority'] = $count;
406
+ $count += 10;
407
+ }
408
+ }
409
+
410
+ $meta_value = $ordered_fields;
411
+ }
412
+
413
+ if ( 'wcf_field_order_shipping' == $key ) {
414
+
415
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
416
+ foreach ( $post_data as $index => $value ) {
417
+
418
+ if ( isset( $shipping_fields[ $value ] ) ) {
419
+ $ordered_fields[ $value ] = $shipping_fields[ $value ];
420
+ $ordered_fields[ $value ]['priority'] = $count;
421
+ $count += 10;
422
+ }
423
+ }
424
+ $meta_value = $ordered_fields;
425
+ }
426
+
427
+ if ( 'wcf_label_text_field_billing' == $key ) {
428
+
429
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
430
+
431
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
432
+ echo 'con 1';
433
+ $billing_fields = $get_ordered_billing_fields;
434
+ } else {
435
+ echo 'con 2';
436
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
437
+ }
438
+
439
+ foreach ( $post_data as $index => $value ) {
440
+
441
+ if ( isset( $billing_fields[ $index ] ) ) {
442
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
443
+ $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
444
+ }
445
+ }
446
+ $key = 'wcf_field_order_billing';
447
+ $meta_value = $ordered_fields;
448
+ }
449
+
450
+ if ( 'wcf_label_text_field_shipping' == $key ) {
451
+
452
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
453
+
454
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
455
+ $shipping_fields = $get_ordered_shipping_fields;
456
+ } else {
457
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
458
+ }
459
+
460
+ foreach ( $post_data as $index => $value ) {
461
+
462
+ if ( isset( $shipping_fields[ $index ] ) ) {
463
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
464
+ $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
465
+ }
466
+ }
467
+ $key = 'wcf_field_order_shipping';
468
+ $meta_value = $ordered_fields;
469
+ }
470
+
471
+ if ( 'wcf_label_placeholder_field_billing' == $key ) {
472
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
473
+
474
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
475
+ $billing_fields = $get_ordered_billing_fields;
476
+ } else {
477
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
478
+ }
479
+ foreach ( $post_data as $index => $value ) {
480
+
481
+ if ( isset( $billing_fields[ $index ] ) ) {
482
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
483
+ $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
484
+ }
485
+ }
486
+
487
+ $key = 'wcf_field_order_billing';
488
+ $meta_value = $ordered_fields;
489
+ }
490
+
491
+ if ( 'wcf_label_placeholder_field_shipping' == $key ) {
492
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
493
+
494
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
495
+ $shipping_fields = $get_ordered_shipping_fields;
496
+ } else {
497
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
498
+ }
499
+
500
+ foreach ( $post_data as $index => $value ) {
501
+
502
+ if ( isset( $shipping_fields[ $index ] ) ) {
503
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
504
+ $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
505
+ }
506
+ }
507
+
508
+ $key = 'wcf_field_order_shipping';
509
+ $meta_value = $ordered_fields;
510
+
511
+ }
512
+
513
+ if ( 'wcf_label_default_field_billing' == $key ) {
514
+
515
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
516
+
517
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
518
+ $billing_fields = $get_ordered_billing_fields;
519
+ } else {
520
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
521
+ }
522
+
523
+ foreach ( $post_data as $index => $value ) {
524
+
525
+ if ( isset( $billing_fields[ $index ] ) ) {
526
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
527
+ $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
528
+ }
529
+ }
530
+
531
+ $key = 'wcf_field_order_billing';
532
+ $meta_value = $ordered_fields;
533
+ }
534
+
535
+ if ( 'wcf_label_default_field_shipping' == $key ) {
536
+
537
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
538
+
539
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
540
+ $shipping_fields = $get_ordered_shipping_fields;
541
+ } else {
542
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
543
+ }
544
+
545
+ foreach ( $post_data as $index => $value ) {
546
+
547
+ if ( isset( $shipping_fields[ $index ] ) ) {
548
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
549
+ $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
550
+ }
551
+ }
552
+
553
+ $key = 'wcf_field_order_shipping';
554
+ $meta_value = $ordered_fields;
555
+ }
556
+
557
+ if ( 'wcf_is_required_field_billing' == $key ) {
558
+
559
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
560
+
561
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
562
+ $billing_fields = $get_ordered_billing_fields;
563
+ } else {
564
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
565
+ }
566
+
567
+ foreach ( $post_data as $index => $value ) {
568
+
569
+ if ( isset( $billing_fields[ $index ] ) ) {
570
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
571
+ if ( 'yes' == $value ) {
572
+
573
+ $ordered_fields[ $index ]['required'] = true;
574
+ } else {
575
+ $ordered_fields[ $index ]['required'] = false;
576
+ }
577
+ }
578
+ }
579
+
580
+ $key = 'wcf_field_order_billing';
581
+ $meta_value = $ordered_fields;
582
+ }
583
+
584
+ if ( 'wcf_is_required_field_shipping' == $key ) {
585
+
586
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
587
+
588
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
589
+ $shipping_fields = $get_ordered_shipping_fields;
590
+ } else {
591
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
592
+ }
593
+
594
+ foreach ( $post_data as $index => $value ) {
595
+
596
+ if ( isset( $shipping_fields[ $index ] ) ) {
597
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
598
+
599
+ if ( 'yes' == $value ) {
600
+
601
+ $ordered_fields[ $index ]['required'] = true;
602
+ } else {
603
+ $ordered_fields[ $index ]['required'] = false;
604
+ }
605
+ }
606
+ }
607
+
608
+ $key = 'wcf_field_order_shipping';
609
+ $meta_value = $ordered_fields;
610
+ }
611
+
612
+ if ( 'wcf_select_option_field_billing' == $key ) {
613
+
614
+ $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
615
+
616
+ if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
617
+ $billing_fields = $get_ordered_billing_fields;
618
+ } else {
619
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
620
+ }
621
+
622
+ foreach ( $post_data as $index => $value ) {
623
+
624
+ $options = explode( ',', $value );
625
+
626
+ if ( isset( $billing_fields[ $index ] ) ) {
627
+ $ordered_fields[ $index ] = $billing_fields[ $index ];
628
+
629
+ $ordered_fields[ $index ]['options'] = array();
630
+
631
+ foreach ( $options as $key => $option ) {
632
+
633
+ $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
634
+ }
635
+ }
636
+ }
637
+
638
+ $key = 'wcf_field_order_billing';
639
+ $meta_value = $ordered_fields;
640
+ }
641
+
642
+ if ( 'wcf_select_option_field_shipping' == $key ) {
643
+
644
+ $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
645
+
646
+ if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
647
+ $shipping_fields = $get_ordered_shipping_fields;
648
+ } else {
649
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
650
+ }
651
+
652
+ foreach ( $post_data as $index => $value ) {
653
+
654
+ $options = explode( ',', $value );
655
+
656
+ if ( isset( $shipping_fields[ $index ] ) ) {
657
+
658
+ $ordered_fields[ $index ] = $shipping_fields[ $index ];
659
+
660
+ $ordered_fields[ $index ]['options'] = array();
661
+
662
+ foreach ( $options as $key => $option ) {
663
+
664
+ $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
665
+ }
666
+ }
667
+ }
668
+
669
+ $key = 'wcf_field_order_shipping';
670
+ $meta_value = $ordered_fields;
671
+ }
672
+ }
673
+ break;
674
+
675
+ default:
676
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
677
+ break;
678
+ }
679
+
680
+ if ( false !== $meta_value ) {
681
+ update_post_meta( $post_id, $key, $meta_value );
682
+ } else {
683
+ delete_post_meta( $post_id, $key );
684
+ }
685
+ }
686
+ }
687
+
688
+ /**
689
+ * Get checkout meta.
690
+ *
691
+ * @param int $post_id post id.
692
+ * @param string $key options key.
693
+ * @param mix $default options default value.
694
+ * @return string
695
+ */
696
+ function get_flow_meta_value( $post_id, $key, $default = false ) {
697
+
698
+ $value = $this->get_save_meta( $post_id, $key );
699
+
700
+ if ( ! $value ) {
701
+
702
+ if ( $default ) {
703
+
704
+ $value = $default;
705
+ } else {
706
+
707
+ $fields = $this->get_flow_fields( $post_id );
708
+
709
+ if ( isset( $fields[ $key ]['default'] ) ) {
710
+
711
+ $value = $fields[ $key ]['default'];
712
+ }
713
+ }
714
+ }
715
+
716
+ return $value;
717
+ }
718
+
719
+ /**
720
+ * Get checkout meta.
721
+ *
722
+ * @param int $post_id post id.
723
+ * @param string $key options key.
724
+ * @param mix $default options default value.
725
+ * @return string
726
+ */
727
+ function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
728
+
729
+ $value = $this->get_save_meta( $post_id, $key );
730
+
731
+ if ( ! $value ) {
732
+
733
+ if ( $default ) {
734
+
735
+ $value = $default;
736
+ } else {
737
+
738
+ $fields = $this->get_checkout_fields( $post_id );
739
+
740
+ if ( isset( $fields[ $key ]['default'] ) ) {
741
+
742
+ $value = $fields[ $key ]['default'];
743
+ }
744
+ }
745
+ }
746
+
747
+ return $value;
748
+ }
749
+
750
+ /**
751
+ * Get post meta.
752
+ *
753
+ * @param int $post_id post id.
754
+ * @param string $key options key.
755
+ * @return string
756
+ */
757
+ function get_save_meta( $post_id, $key ) {
758
+
759
+ $value = get_post_meta( $post_id, $key, true );
760
+
761
+ return $value;
762
+ }
763
+
764
+ /**
765
+ * Thank You Default fields.
766
+ *
767
+ * @param int $post_id post id.
768
+ * @return array
769
+ */
770
+ function get_thankyou_fields( $post_id ) {
771
+
772
+ if ( null === self::$thankyou_fields ) {
773
+
774
+ self::$thankyou_fields = array(
775
+ 'wcf-field-google-font-url' => array(
776
+ 'default' => '',
777
+ 'sanitize' => 'FILTER_DEFAULT',
778
+ ),
779
+ 'wcf-active-tab' => array(
780
+ 'default' => '',
781
+ 'sanitize' => 'FILTER_DEFAULT',
782
+ ),
783
+ 'wcf-tq-text-color' => array(
784
+ 'default' => '',
785
+ 'sanitize' => 'FILTER_DEFAULT',
786
+ ),
787
+ 'wcf-tq-font-family' => array(
788
+ 'default' => '',
789
+ 'sanitize' => 'FILTER_DEFAULT',
790
+ ),
791
+ 'wcf-tq-heading-color' => array(
792
+ 'default' => '',
793
+ 'sanitize' => 'FILTER_DEFAULT',
794
+ ),
795
+ 'wcf-tq-heading-font-family' => array(
796
+ 'default' => '',
797
+ 'sanitize' => 'FILTER_DEFAULT',
798
+ ),
799
+ 'wcf-tq-heading-font-wt' => array(
800
+ 'default' => '',
801
+ 'sanitize' => 'FILTER_DEFAULT',
802
+ ),
803
+ 'wcf-tq-container-width' => array(
804
+ 'default' => '',
805
+ 'sanitize' => 'FILTER_DEFAULT',
806
+ ),
807
+ 'wcf-tq-section-bg-color' => array(
808
+ 'default' => '',
809
+ 'sanitize' => 'FILTER_DEFAULT',
810
+ ),
811
+ 'wcf-tq-advance-options-fields' => array(
812
+ 'default' => '',
813
+ 'sanitize' => 'FILTER_DEFAULT',
814
+ ),
815
+ 'wcf-show-overview-section' => array(
816
+ 'default' => 'yes',
817
+ 'sanitize' => 'FILTER_DEFAULT',
818
+ ),
819
+ 'wcf-show-details-section' => array(
820
+ 'default' => 'yes',
821
+ 'sanitize' => 'FILTER_DEFAULT',
822
+ ),
823
+ 'wcf-show-billing-section' => array(
824
+ 'default' => 'yes',
825
+ 'sanitize' => 'FILTER_DEFAULT',
826
+ ),
827
+ 'wcf-show-shipping-section' => array(
828
+ 'default' => 'yes',
829
+ 'sanitize' => 'FILTER_DEFAULT',
830
+ ),
831
+ 'wcf-custom-script' => array(
832
+ 'default' => '',
833
+ 'sanitize' => 'FILTER_DEFAULT',
834
+ ),
835
+ );
836
+
837
+ }
838
+
839
+ return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
840
+ }
841
+
842
+ /**
843
+ * Get Thank you section meta.
844
+ *
845
+ * @param int $post_id post id.
846
+ * @param string $key options key.
847
+ * @param mix $default options default value.
848
+ * @return string
849
+ */
850
+ function get_thankyou_meta_value( $post_id, $key, $default = false ) {
851
+
852
+ $value = $this->get_save_meta( $post_id, $key );
853
+
854
+ if ( ! $value ) {
855
+
856
+ if ( $default ) {
857
+
858
+ $value = $default;
859
+ } else {
860
+
861
+ $fields = $this->get_thankyou_fields( $post_id );
862
+
863
+ if ( isset( $fields[ $key ]['default'] ) ) {
864
+
865
+ $value = $fields[ $key ]['default'];
866
+ }
867
+ }
868
+ }
869
+
870
+ return $value;
871
+ }
872
+
873
+ /**
874
+ * Get Landing section meta.
875
+ *
876
+ * @param int $post_id post id.
877
+ * @param string $key options key.
878
+ * @param mix $default options default value.
879
+ * @return string
880
+ */
881
+ function get_landing_meta_value( $post_id, $key, $default = false ) {
882
+
883
+ $value = $this->get_save_meta( $post_id, $key );
884
+ if ( ! $value ) {
885
+
886
+ if ( $default ) {
887
+
888
+ $value = $default;
889
+ } else {
890
+
891
+ $fields = $this->get_landing_fields( $post_id );
892
+
893
+ if ( isset( $fields[ $key ]['default'] ) ) {
894
+ $value = $fields[ $key ]['default'];
895
+ }
896
+ }
897
+ }
898
+
899
+ return $value;
900
+ }
901
+
902
+ /**
903
+ * Thank You Default fields.
904
+ *
905
+ * @param int $post_id post id.
906
+ * @return array
907
+ */
908
+ function get_landing_fields( $post_id ) {
909
+
910
+ if ( null === self::$landing_fields ) {
911
+
912
+ self::$landing_fields = array(
913
+ 'wcf-custom-script' => array(
914
+ 'default' => '',
915
+ 'sanitize' => 'FILTER_DEFAULT',
916
+ ),
917
+ );
918
+ }
919
+ return apply_filters( 'cartflows_landing_meta_options', self::$landing_fields, $post_id );
920
+ }
921
+ }
922
+
923
+ /**
924
+ * Kicking this off by calling 'get_instance()' method
925
+ */
926
+ Cartflows_Default_Meta::get_instance();
classes/class-cartflows-frontend.php CHANGED
@@ -290,6 +290,9 @@ class Cartflows_Frontend {
290
  /* Add version class to body in frontend. */
291
  add_filter( 'body_class', array( $this, 'add_cartflows_lite_version_to_body' ) );
292
 
 
 
 
293
  /* Remove the action applied by the Flatsome theme */
294
  if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
295
  $this->remove_flatsome_action();
@@ -338,18 +341,24 @@ class Cartflows_Frontend {
338
  CARTFLOWS_VER,
339
  true
340
  );
 
 
 
 
 
 
 
 
341
 
342
  /* Add custom script to header in frontend. */
343
  $script = $this->get_custom_script();
344
-
345
  if ( '' !== $script ) {
346
-
347
- $script = str_replace( '<script>', '', $script );
348
- $script = str_replace( '</script>', '', $script );
349
-
350
- wp_register_script( 'wcf-custom-script-head', '' );
351
- wp_enqueue_script( 'wcf-custom-script-head' );
352
- wp_add_inline_script( 'wcf-custom-script-head', $script );
353
  }
354
  }
355
 
290
  /* Add version class to body in frontend. */
291
  add_filter( 'body_class', array( $this, 'add_cartflows_lite_version_to_body' ) );
292
 
293
+ /* Custom Script Option */
294
+ add_action( 'wp_head', array( $this, 'custom_script_option' ) );
295
+
296
  /* Remove the action applied by the Flatsome theme */
297
  if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
298
  $this->remove_flatsome_action();
341
  CARTFLOWS_VER,
342
  true
343
  );
344
+ }
345
+
346
+ /**
347
+ * Custom Script in head.
348
+ *
349
+ * @since 1.0.0
350
+ */
351
+ function custom_script_option() {
352
 
353
  /* Add custom script to header in frontend. */
354
  $script = $this->get_custom_script();
 
355
  if ( '' !== $script ) {
356
+ if ( false === strpos( $script, '<script' ) ) {
357
+ $script = '<script>' . $script . '</script>';
358
+ }
359
+ echo '<!-- Custom CartFlows Script -->';
360
+ echo $script;
361
+ echo '<!-- End Custom CartFlows Script -->';
 
362
  }
363
  }
364
 
classes/class-cartflows-importer.php CHANGED
@@ -1,1569 +1,1569 @@
1
- <?php
2
- /**
3
- * CartFlows Admin
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'CartFlows_Importer' ) ) :
10
-
11
- /**
12
- * CartFlows Import
13
- *
14
- * @since 1.0.0
15
- */
16
- class CartFlows_Importer {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
-
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.0.0
45
- */
46
- public function __construct() {
47
- add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
48
- add_action( 'wp_ajax_cartflows_load_steps', array( $this, 'load_templates' ) );
49
- add_action( 'wp_ajax_cartflows_step_import', array( $this, 'import_step' ) );
50
- add_action( 'wp_ajax_cartflows_create_flow', array( $this, 'create_flow' ) );
51
- add_action( 'wp_ajax_cartflows_default_flow', array( $this, 'create_default_flow' ) );
52
- add_action( 'wp_ajax_cartflows_step_create_blank', array( $this, 'step_create_blank' ) );
53
- add_action( 'wp_ajax_cartflows_import_flow_step', array( $this, 'import_flow' ) );
54
- add_action( 'admin_footer', array( $this, 'js_templates' ) );
55
- add_action( 'cartflows_import_complete', array( $this, 'clear_cache' ) );
56
-
57
- add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
58
-
59
- add_action( 'wp_ajax_cartflows_activate_plugin', array( $this, 'activate_plugin' ) );
60
-
61
- add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
62
- add_action( 'admin_init', array( $this, 'export_json' ) );
63
- add_action( 'admin_init', array( $this, 'import_json' ) );
64
- add_filter( 'post_row_actions', array( $this, 'export_link' ), 10, 2 );
65
- add_action( 'admin_action_cartflows_export_flow', array( $this, 'export_flow' ) );
66
- }
67
-
68
- /**
69
- * Add the export link to action list for flows row actions
70
- *
71
- * @since 1.1.4
72
- *
73
- * @param array $actions Actions array.
74
- * @param object $post Post object.
75
- *
76
- * @return array
77
- */
78
- function export_link( $actions, $post ) {
79
- if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
80
- $actions['export'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_export_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_export_nonce' ) . '" title="' . __( 'Export this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Export', 'cartflows' ) . '</a>';
81
- }
82
- return $actions;
83
- }
84
-
85
- /**
86
- * Add menus
87
- *
88
- * @since 1.1.4
89
- */
90
- function add_to_menus() {
91
- add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Export', 'cartflows' ), __( 'Flow Export', 'cartflows' ), 'export', 'flow_exporter', array( $this, 'exporter_markup' ) );
92
- add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Import', 'cartflows' ), __( 'Flow Import', 'cartflows' ), 'import', 'flow_importer', array( $this, 'importer_markup' ) );
93
- }
94
-
95
- /**
96
- * Export flow with steps and its meta
97
- *
98
- * @since 1.1.4
99
- */
100
- function export_flow() {
101
-
102
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
- wp_die( __( 'No post to export has been supplied!', 'cartflows' ) );
104
- }
105
-
106
- if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( $_GET['flow_export_nonce'], basename( __FILE__ ) ) ) {
107
- return;
108
- }
109
-
110
- // Get the original post id.
111
- $flow_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
112
-
113
- $flows = array();
114
- $flows[] = $this->get_flow_export_data( $flow_id );
115
- $flows = apply_filters( 'cartflows_export_data', $flows );
116
-
117
- nocache_headers();
118
- header( 'Content-Type: application/json; charset=utf-8' );
119
- header( 'Content-Disposition: attachment; filename=cartflows-flow-' . $flow_id . '-' . date( 'm-d-Y' ) . '.json' );
120
- header( 'Expires: 0' );
121
-
122
- echo json_encode( $flows );
123
- exit;
124
- }
125
-
126
- /**
127
- * Export flow markup
128
- *
129
- * @since 1.1.4
130
- */
131
- function exporter_markup() {
132
- include_once CARTFLOWS_DIR . 'includes/exporter.php';
133
- }
134
-
135
- /**
136
- * Import flow markup
137
- *
138
- * @since 1.1.4
139
- */
140
- function importer_markup() {
141
- include_once CARTFLOWS_DIR . 'includes/importer.php';
142
- }
143
-
144
- /**
145
- * Export flow
146
- *
147
- * @since 1.1.4
148
- */
149
- function export_json() {
150
- if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
- return;
152
- }
153
-
154
- if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
155
- return;
156
- }
157
-
158
- if ( ! current_user_can( 'manage_options' ) ) {
159
- return;
160
- }
161
-
162
- $flows = $this->get_all_flow_export_data();
163
- $flows = apply_filters( 'cartflows_export_data', $flows );
164
-
165
- nocache_headers();
166
- header( 'Content-Type: application/json; charset=utf-8' );
167
- header( 'Content-Disposition: attachment; filename=cartflows-flow-export-' . date( 'm-d-Y' ) . '.json' );
168
- header( 'Expires: 0' );
169
-
170
- echo json_encode( $flows );
171
- exit;
172
- }
173
-
174
- /**
175
- * Get flow export data
176
- *
177
- * @since 1.1.4
178
- *
179
- * @param integer $flow_id Flow ID.
180
- * @return array
181
- */
182
- function get_flow_export_data( $flow_id ) {
183
-
184
- $export_all = apply_filters( 'cartflows_export_all', false );
185
-
186
- $valid_step_meta_keys = array(
187
- '_wp_page_template',
188
- '_thumbnail_id',
189
- 'classic-editor-remember',
190
- );
191
-
192
- $new_steps = array();
193
- $steps = get_post_meta( $flow_id, 'wcf-steps', true );
194
- if ( $steps ) {
195
- foreach ( $steps as $key => $step ) {
196
-
197
- // Add step post meta.
198
- $new_all_meta = array();
199
- $all_meta = get_post_meta( $step['id'] );
200
- if ( is_array( $all_meta ) ) {
201
-
202
- if ( $export_all ) {
203
- foreach ( $all_meta as $meta_key => $value ) {
204
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
205
- }
206
- } else {
207
-
208
- foreach ( $all_meta as $meta_key => $value ) {
209
- if ( substr( $meta_key, 0, strlen( 'wcf' ) ) === 'wcf' ) {
210
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
211
- } elseif ( in_array( $meta_key, $valid_step_meta_keys ) ) {
212
- $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
213
- }
214
- }
215
- }
216
- }
217
-
218
- // Add single step.
219
- $step_data_arr = array(
220
- 'title' => get_the_title( $step['id'] ),
221
- 'type' => $step['type'],
222
- 'meta' => $new_all_meta,
223
- 'post_content' => '',
224
- );
225
-
226
- if ( $export_all ) {
227
-
228
- $step_post_obj = get_post( $step['id'] );
229
-
230
- $step_data_arr['post_content'] = $step_post_obj->post_content;
231
- }
232
-
233
- $new_steps[] = $step_data_arr;
234
- }
235
- }
236
-
237
- // Add single flow.
238
- return array(
239
- 'title' => get_the_title( $flow_id ),
240
- 'steps' => $new_steps,
241
- );
242
- }
243
-
244
- /**
245
- * Get all flow export data
246
- *
247
- * @since 1.1.4
248
- */
249
- function get_all_flow_export_data() {
250
-
251
- $query_args = array(
252
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
253
-
254
- // Query performance optimization.
255
- 'fields' => 'ids',
256
- 'no_found_rows' => true,
257
- 'posts_per_page' => -1,
258
- );
259
-
260
- $query = new WP_Query( $query_args );
261
- $flows = array();
262
- if ( $query->posts ) {
263
- foreach ( $query->posts as $key => $post_id ) {
264
- $flows[] = $this->get_flow_export_data( $post_id );
265
- }
266
- }
267
-
268
- return $flows;
269
- }
270
-
271
- /**
272
- * Import our exported file
273
- *
274
- * @since 1.1.4
275
- */
276
- function import_json() {
277
- if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
- return;
279
- }
280
-
281
- if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
282
- return;
283
- }
284
-
285
- if ( ! current_user_can( 'manage_options' ) ) {
286
- return;
287
- }
288
-
289
- $filename = $_FILES['file']['name'];
290
- $file_info = explode( '.', $filename );
291
- $extension = end( $file_info );
292
-
293
- if ( 'json' != $extension ) {
294
- wp_die( __( 'Please upload a valid .json file', 'cartflows' ) );
295
- }
296
-
297
- $file = $_FILES['file']['tmp_name'];
298
-
299
- if ( empty( $file ) ) {
300
- wp_die( __( 'Please upload a file to import', 'cartflows' ) );
301
- }
302
-
303
- // Retrieve the settings from the file and convert the JSON object to an array.
304
- $flows = json_decode( file_get_contents( $file ), true );
305
-
306
- if ( $flows ) {
307
-
308
- foreach ( $flows as $key => $flow ) {
309
-
310
- $flow_title = $flow['title'];
311
- if ( post_exists( $flow['title'] ) ) {
312
- $flow_title = $flow['title'] . ' Copy';
313
- }
314
-
315
- // Create post object.
316
- $new_flow_args = array(
317
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
318
- 'post_title' => $flow_title,
319
- 'post_status' => 'draft',
320
- );
321
-
322
- // Insert the post into the database.
323
- $flow_id = wp_insert_post( $new_flow_args );
324
-
325
- if ( $flow['steps'] ) {
326
- foreach ( $flow['steps'] as $key => $step ) {
327
-
328
- $new_step_id = wp_insert_post(
329
- array(
330
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
331
- 'post_title' => $step['title'],
332
- 'post_status' => 'publish',
333
- 'meta_input' => $step['meta'],
334
- 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
335
- )
336
- );
337
-
338
- // Insert post meta.
339
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
340
-
341
- $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
342
- $current_term = term_exists( $step['type'], $step_taxonomy );
343
-
344
- // // Set type object.
345
- $data = get_term( $current_term['term_id'], $step_taxonomy );
346
- $step_slug = $data->slug;
347
- wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
348
-
349
- // Set type.
350
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
351
-
352
- // Set flow.
353
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
354
-
355
- CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
356
-
357
- if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
358
-
359
- // Download and replace images.
360
- $content = $this->get_content( $step['post_content'] );
361
-
362
- // Update post content.
363
- wp_update_post(
364
- array(
365
- 'ID' => $new_step_id,
366
- 'post_content' => $content,
367
- )
368
- );
369
- }
370
- }
371
- }
372
- }
373
- }
374
-
375
- add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
376
- }
377
-
378
- /**
379
- * Download and Replace hotlink images
380
- *
381
- * @since x.x.x
382
- *
383
- * @param string $content Mixed post content.
384
- * @return array Hotlink image array.
385
- */
386
- function get_content( $content = '' ) {
387
-
388
- $all_links = wp_extract_urls( $content );
389
- $image_links = array();
390
- $image_map = array();
391
-
392
- // Not have any link.
393
- if ( empty( $all_links ) ) {
394
- return $content;
395
- }
396
-
397
- foreach ( $all_links as $key => $link ) {
398
- if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
399
- $image_links[] = $link;
400
- }
401
- }
402
-
403
- // Not have any image link.
404
- if ( empty( $image_links ) ) {
405
- return $content;
406
- }
407
-
408
- foreach ( $image_links as $key => $image_url ) {
409
-
410
- // Download remote image.
411
- $image = array(
412
- 'url' => $image_url,
413
- 'id' => rand( 000, 999 ),
414
- );
415
- $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
416
-
417
- // Old and New image mapping links.
418
- $image_map[ $image_url ] = $downloaded_image['url'];
419
- }
420
-
421
- // Replace old image links with new image links.
422
- foreach ( $image_map as $old_url => $new_url ) {
423
- $content = str_replace( $old_url, $new_url, $content );
424
- }
425
-
426
- return $content;
427
-
428
- }
429
-
430
- /**
431
- * Imported notice
432
- *
433
- * @since 1.1.4
434
- */
435
- function imported_successfully() {
436
- ?>
437
- <div class="notice notice-success">
438
- <p><?php _e( 'Successfully imported flows.', 'cartflows' ); ?></p>
439
- </div>
440
- <?php
441
- }
442
-
443
- /**
444
- * Clear Cache.
445
- *
446
- * @since 1.0.0
447
- */
448
- public function clear_cache() {
449
- // Clear 'Elementor' file cache.
450
- if ( class_exists( '\Elementor\Plugin' ) ) {
451
- Elementor\Plugin::$instance->files_manager->clear_cache();
452
- }
453
- }
454
-
455
- /**
456
- * JS Templates
457
- *
458
- * @since 1.0.0
459
- *
460
- * @return void
461
- */
462
- function js_templates() {
463
-
464
- // Loading Templates.
465
- ?>
466
- <script type="text/template" id="tmpl-cartflows-step-loading">
467
- <div class="template-message-block cartflows-step-loading">
468
- <h2>
469
- <span class="spinner"></span>
470
- <?php _e( 'Loading Steps', 'cartflows' ); ?>
471
- </h2>
472
- <p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
473
- </div>
474
- </script>
475
-
476
- <?php
477
- // Search Templates.
478
- ?>
479
- <script type="text/template" id="tmpl-cartflows-searching-templates">
480
- <div class="template-message-block cartflows-searching-templates">
481
- <h2>
482
- <span class="spinner"></span>
483
- <?php _e( 'Searching Template..', 'cartflows' ); ?>
484
- </h2>
485
- <p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
486
- </div>
487
- </script>
488
-
489
- <?php
490
- // CartFlows Importing Template.
491
- ?>
492
- <script type="text/template" id="tmpl-cartflows-step-importing">
493
- <div class="template-message-block cartflows-step-importing">
494
- <h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
495
- </div>
496
- </script>
497
-
498
- <?php
499
- // CartFlows Imported.
500
- ?>
501
- <script type="text/template" id="tmpl-cartflows-step-imported">
502
- <div class="template-message-block cartflows-step-imported">
503
- <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
504
- <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
505
- </script>
506
-
507
- <?php
508
- // No templates.
509
- ?>
510
- <script type="text/template" id="tmpl-cartflows-no-steps">
511
- <div class="cartflows-no-steps">
512
- <div class="template-message-block">
513
- <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
514
- <p class="description"></p>
515
- </div>
516
- </div>
517
- </script>
518
-
519
- <?php
520
- // No templates.
521
- ?>
522
- <script type="text/template" id="tmpl-cartflows-no-flows">
523
- <div class="cartflows-no-flows">
524
- <div class="template-message-block">
525
- <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
526
- <p class="description"></p>
527
- </div>
528
- </div>
529
- </script>
530
-
531
- <?php
532
- // Error handling.
533
- ?>
534
- <script type="text/template" id="tmpl-templator-error">
535
- <div class="notice notice-error"><p>{{ data }}</p></div>
536
- </script>
537
-
538
- <?php
539
- // Redirect to Elementor.
540
- ?>
541
- <script type="text/template" id="tmpl-templator-redirect-to-elementor">
542
- <div class="template-message-block templator-redirect-to-elementor">
543
- <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
544
- <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
545
- </script>
546
-
547
- <?php
548
- /**
549
- * Responsive Buttons
550
- */
551
- ?>
552
- <script type="text/template" id="tmpl-cartflows-responsive-view">
553
- <span class="responsive-view">
554
- <span class="actions">
555
- <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
556
- <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
557
- <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
558
- </span>
559
- </span>
560
- </script>
561
-
562
- <?php
563
- // Templates data.
564
- ?>
565
- <script type="text/template" id="tmpl-cartflows-flows-list">
566
-
567
- <# console.log( data.items.length ) #>
568
- <# console.log( data.items ) #>
569
- <# if ( data.items.length ) { #>
570
- <# for ( key in data.items ) { #>
571
- <#
572
- var flow_steps = [];
573
- if( data.items[ key ].flow_steps ) {
574
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
575
- return value['id'];
576
- });
577
- }
578
- #>
579
- <div class="inner">
580
- <div class="template">
581
- <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
582
- <div class="template-screenshot">
583
- <# if( data.items[ key ].featured_image_url ) { #>
584
- <img src="{{ data.items[ key ].featured_image_url }}" />
585
- <# } else { #>
586
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
587
- <# } #>
588
- </div>
589
- <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>flow={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
590
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
591
- <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
592
- <# } #>
593
- </span>
594
- <div class="template-id-container">
595
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
596
- <div class="template-actions">
597
-
598
- <#
599
- if( data.items[ key ].page_builder.slug ) {
600
- required_plugin_group = data.items[ key ].page_builder.slug;
601
- } else {
602
- required_plugin_group = '';
603
- }
604
-
605
- if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
606
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
607
- } else {
608
- import_btn_title = 'Import';
609
- } #>
610
-
611
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
612
- <a data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
613
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
614
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
615
- <# } else { #>
616
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
617
- <# } #>
618
- </div>
619
- </div>
620
- </div>
621
- </div>
622
- <# } #>
623
- <# } #>
624
- </script>
625
-
626
- <?php
627
- // Empty Step.
628
- ?>
629
- <script type="text/template" id="tmpl-cartflows-create-blank-step">
630
- <div class="inner">
631
- <div class="template">
632
- <span class="thumbnail site-preview cartflows-flow-preview">
633
- <div class="template-screenshot">
634
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
635
- </div>
636
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
637
- </span>
638
- <div class="template-id-container">
639
- <h3 class="template-name"> Blank </h3>
640
- <div class="template-actions">
641
- <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
642
- </div>
643
- </div>
644
- </div>
645
- </div>
646
- </script>
647
-
648
- <?php
649
- // Templates data.
650
- ?>
651
- <script type="text/template" id="tmpl-cartflows-steps-list">
652
- <# if ( data.items.length ) { #>
653
- <# for ( key in data.items ) { #>
654
- <#
655
- var flow_steps = [];
656
- if( data.items[ key ].flow_steps ) {
657
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
658
- return value['id'];
659
- });
660
- }
661
- #>
662
- <div class="inner">
663
- <div class="template">
664
- <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
665
- <div class="template-screenshot">
666
- <# if( data.items[ key ].featured_image_url ) { #>
667
- <img src="{{ data.items[ key ].featured_image_url }}" />
668
- <# } else { #>
669
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
670
- <# } #>
671
- </div>
672
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
673
- <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>step={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
674
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
675
- <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
676
- <# } #>
677
- </span>
678
- <div class="template-id-container">
679
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
680
- <div class="template-actions">
681
-
682
- <#
683
-
684
- var step_slug = data.items[ key ].step_type.slug || '';
685
- var step_title = data.items[ key ].step_type.name || '';
686
- var import_btn_title = 'Import';
687
-
688
- var required_plugin_group = '';
689
- if( data.items[ key ].page_builder ) {
690
- required_plugin_group = data.items[ key ].page_builder.slug;
691
-
692
- if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
693
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
694
- }
695
- }
696
- #>
697
-
698
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
699
- <a data-slug="{{step_slug}}" data-title="{{step_title}}" data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
700
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
701
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
702
- <# } else { #>
703
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
704
- <# } #>
705
- </div>
706
- </div>
707
- </div>
708
- </div>
709
- <# } #>
710
- <# } #>
711
- </script>
712
-
713
- <?php
714
- /**
715
- * TMPL - Website Unreachable
716
- */
717
- ?>
718
- <script type="text/template" id="tmpl-cartflows-website-unreachable">
719
- <div class="postbox cartflows-website-unreachable">
720
- <h2><?php _e( 'Under Maintenance..', 'cartflows' ); ?></h2>
721
- <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
722
- <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website..', 'cartflows' ); ?></p>
723
- </div>
724
- </script>
725
-
726
- <?php
727
- /**
728
- * TMPL - Filters
729
- */
730
- ?>
731
- <script type="text/template" id="tmpl-cartflows-page-builder-notice">
732
- <?php
733
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
734
- $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
735
- $title = $page_builder['title'];
736
-
737
- $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
738
- $theme_status = '';
739
- if ( 'divi' === $default_page_builder ) {
740
-
741
- $theme_status = $page_builder['theme-status'];
742
- $plugin_status = $page_builder['plugin-status'];
743
-
744
- if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
745
- $plugin_string = 'Please activate ' . esc_html( $title );
746
- } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
747
- $plugin_string = 'Please install and activate ' . esc_html( $title );
748
- }
749
- }
750
- ?>
751
- <div class="wcf-page-builder-message">
752
- <p><?php /* translators: %s: Plugin string */ printf( __( '%1$s to see CartFlows templates. If you prefer another page builder tool, you can <a href="%2$s" target="blank">select it here</a>.', 'cartflows' ), $plugin_string, admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS . '&action=common-settings#form-field-wcf_default_page_builder' ) ); ?></p>
753
- <p>If your preferred page builder is not available, feel free to <a href="#" data-slug="canvas" class="wcf-create-from-scratch-link">create your own</a> pages using page builder of your choice as CartFlows works with all major page builders.</p>
754
- <p>We plan to add design templates made with more page builder shortly!</p>
755
- </div>
756
- </script>
757
-
758
- <?php
759
- /**
760
- * TMPL - Filters
761
- */
762
- ?>
763
- <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
764
- <# if ( data ) { #>
765
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
766
- <# if ( data.args.show_all ) { #>
767
- <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
768
- <# } #>
769
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
770
- <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
771
- <# } #>
772
- <# for ( key in data.items ) { #>
773
- <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
774
- <# } #>
775
- </select>
776
- <# } #>
777
- </script>
778
-
779
- <script type="text/template" id="tmpl-cartflows-term-filters">
780
-
781
- <# if ( data ) { #>
782
-
783
- <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
784
- <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
785
-
786
- <# if ( data.args.show_all ) { #>
787
- <li>
788
- <a href="#" data-group="all"> All </a>
789
- </li>
790
- <# } #>
791
-
792
- <# for ( key in data.items ) { #>
793
- <li>
794
- <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</a>
795
- </li>
796
- <# } #>
797
-
798
- </ul>
799
-
800
- <?php
801
-
802
- /*
803
- <# } else { #>
804
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
805
-
806
- <# if ( data.args.show_all ) { #>
807
- <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
808
- <# } #>
809
-
810
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
811
- <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
812
- <# } #>
813
-
814
- <# for ( key in data.items ) { #>
815
- <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
816
- <# } #>
817
-
818
- </select>
819
- */
820
- ?>
821
-
822
- <?php /* <# } #> */ ?>
823
-
824
- <# } #>
825
- </script>
826
-
827
- <?php
828
- // Step Type.
829
- ?>
830
- <script type="text/template" id="tmpl-cartflows-step-types">
831
- <ul class="wcf-tab nav-tabs">
832
- <# if( data.items_count ) { #>
833
- <# for( key in data.items ) { #>
834
- <# console.log( data.items[ key ].id ) #>
835
- <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
836
- <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
837
- </li>
838
- <# } #>
839
- <# } #>
840
- </ul>
841
- </script>
842
-
843
- <?php
844
- // Add to library button.
845
- ?>
846
- <script type="text/template" id="tmpl-templator-add-to-library">
847
- <a class="templator-add-to-library page-title-action cartflows-load-steps-library"><i class="dashicons dashicons-cloud"></i><?php esc_attr_e( 'Import from Cloud', 'cartflows' ); ?></a>
848
- </script>
849
- <?php
850
- }
851
-
852
- /**
853
- * Enqueue scripts
854
- *
855
- * @since 1.0.0
856
- *
857
- * @hook admin_enqueue_scripts
858
- * @param string $hook Current page hook.
859
- */
860
- function scripts( $hook = '' ) {
861
-
862
- if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
863
- return;
864
- }
865
-
866
- wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
867
- wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
868
- wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
869
- wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
870
-
871
- $localize_vars = array(
872
- '_is_pro_active' => _is_cartflows_pro(),
873
-
874
- // Flow and its rest fields.
875
- 'flow' => CARTFLOWS_FLOW_POST_TYPE,
876
- 'flow_fields' => array(
877
- 'id',
878
- 'title',
879
- 'flow_type',
880
- 'page_builder',
881
- 'flow_steps',
882
- 'licence_status',
883
- 'featured_image_url',
884
- 'featured_media', // @required for field `featured_image_url`.
885
- ),
886
-
887
- // Flow type and rest fields.
888
- 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
889
- 'flow_type_fields' => array(
890
- 'id',
891
- 'name',
892
- 'slug',
893
- ),
894
-
895
- // Flow page builder and rest fields.
896
- 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
897
- 'flow_page_builder_fields' => array(
898
- 'id',
899
- 'name',
900
- 'slug',
901
- ),
902
-
903
- // Step page builder and rest fields.
904
- 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
905
- 'step_page_builder_fields' => array(
906
- 'id',
907
- 'name',
908
- 'slug',
909
- ),
910
-
911
- // Step and its rest fields.
912
- 'step' => CARTFLOWS_STEP_POST_TYPE,
913
- 'step_fields' => array(
914
- 'title',
915
- 'featured_image_url',
916
- 'featured_media', // @required for field `featured_image_url`.
917
- 'id',
918
- 'flow_type',
919
- 'step_type',
920
- 'page_builder',
921
- 'licence_status',
922
- ),
923
-
924
- // Step type and its rest fields.
925
- 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
926
- 'step_type_fields' => array(
927
- 'id',
928
- 'name',
929
- 'slug',
930
- ),
931
-
932
- 'domain_url' => CARTFLOWS_DOMAIN_URL,
933
- 'server_url' => CARTFLOWS_TEMPLATES_URL,
934
- 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
935
- 'site_url' => site_url(),
936
- 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
937
- 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
938
- 'admin_url' => admin_url(),
939
- 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
940
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
941
- 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
942
-
943
- 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
944
-
945
- 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
946
- );
947
-
948
- // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
949
- // wp_die( );
950
- // Add thickbox.
951
- add_thickbox();
952
-
953
- wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
954
- wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
955
- }
956
-
957
- /**
958
- * Load Template
959
- *
960
- * @since 1.0.0
961
- *
962
- * @hook cartflows_load_steps
963
- * @return void
964
- */
965
- function load_templates() {
966
-
967
- check_ajax_referer( 'cf-load-steps', 'security' );
968
-
969
- $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
970
- $templates = CartFlows_API::get_instance()->get_templates( $args );
971
-
972
- if ( $templates['templates_count'] ) {
973
- wp_send_json_success( $templates );
974
- } else {
975
- wp_send_json_error( $templates );
976
- }
977
- wp_die();
978
- }
979
-
980
- /**
981
- * Import.
982
- *
983
- * @since 1.0.0
984
- *
985
- * @hook wp_ajax_cartflows_import_flow_step
986
- * @return void
987
- */
988
- function import_flow() {
989
-
990
- check_ajax_referer( 'cf-import-flow-step', 'security' );
991
-
992
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
993
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
994
-
995
- wcf()->logger->import_log( '------------------------------------' );
996
- wcf()->logger->import_log( 'STARTED! Importing FLOW' );
997
- wcf()->logger->import_log( '------------------------------------' );
998
- wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
999
-
1000
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1001
-
1002
- $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1003
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1004
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1005
- $post_content = $response['data']['divi_content'];
1006
- }
1007
- }
1008
-
1009
- if ( false === $response['success'] ) {
1010
- wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1011
- wp_send_json_error( $response );
1012
- }
1013
-
1014
- wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
1015
-
1016
- $new_step_id = wp_insert_post(
1017
- array(
1018
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1019
- 'post_title' => $response['title'],
1020
- 'post_content' => $post_content,
1021
- 'post_status' => 'publish',
1022
- )
1023
- );
1024
-
1025
- if ( is_wp_error( $new_step_id ) ) {
1026
- wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1027
- wp_send_json_error( $new_step_id );
1028
- }
1029
-
1030
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1031
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1032
- update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1033
- }
1034
- }
1035
-
1036
- /* Imported Step */
1037
- update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1038
-
1039
- wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
1040
- // insert post meta.
1041
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1042
- wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1043
-
1044
- /**
1045
- * Import & Set type.
1046
- */
1047
- $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1048
- $term_slug = '';
1049
- if ( $term ) {
1050
-
1051
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1052
- $term_exist = term_exists( $term->name, $taxonomy );
1053
-
1054
- if ( empty( $term_exist ) ) {
1055
- $terms = array(
1056
- array(
1057
- 'name' => $term->name,
1058
- ),
1059
- );
1060
-
1061
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1062
- wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
1063
- }
1064
-
1065
- $current_term = term_exists( $term->name, $taxonomy );
1066
-
1067
- // Set type object.
1068
- $data = get_term( $current_term['term_id'], $taxonomy );
1069
- $term_slug = $data->slug;
1070
- $term_name = $data->name;
1071
- wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1072
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1073
-
1074
- // Set type.
1075
- update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1076
- wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1077
- }
1078
-
1079
- // Set flow.
1080
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1081
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1082
-
1083
- /**
1084
- * Update steps for the current flow.
1085
- */
1086
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1087
-
1088
- if ( ! is_array( $flow_steps ) ) {
1089
- $flow_steps = array();
1090
- }
1091
-
1092
- $flow_steps[] = array(
1093
- 'id' => $new_step_id,
1094
- 'title' => $response['title'],
1095
- 'type' => $term_slug,
1096
- );
1097
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1098
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1099
-
1100
- // Import Post Meta.
1101
- self::import_post_meta( $new_step_id, $response );
1102
-
1103
- wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1104
- wcf()->logger->import_log( '------------------------------------' );
1105
- wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1106
- wcf()->logger->import_log( '------------------------------------' );
1107
-
1108
- do_action( 'cartflows_import_complete' );
1109
- wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1110
-
1111
- // Batch Process.
1112
- do_action( 'cartflows_after_template_import', $new_step_id, $response );
1113
-
1114
- /**
1115
- * End
1116
- */
1117
- wp_send_json_success( $new_step_id );
1118
- }
1119
-
1120
- /**
1121
- * Import Step.
1122
- *
1123
- * @since 1.0.0
1124
- * @hook wp_ajax_cartflows_step_import
1125
- *
1126
- * @return void
1127
- */
1128
- function create_default_flow() {
1129
-
1130
- check_ajax_referer( 'cf-default-flow', 'security' );
1131
-
1132
- // Create post object.
1133
- $new_flow_post = array(
1134
- 'post_content' => '',
1135
- 'post_status' => 'publish',
1136
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1137
- );
1138
-
1139
- // Insert the post into the database.
1140
- $flow_id = wp_insert_post( $new_flow_post );
1141
-
1142
- if ( is_wp_error( $flow_id ) ) {
1143
- wp_send_json_error( $flow_id->get_error_message() );
1144
- }
1145
-
1146
- $flow_steps = array();
1147
-
1148
- $steps_data = array(
1149
- 'landing' => __( 'Landing Page', 'cartflows' ),
1150
- 'checkout' => __( 'Checkout Page', 'cartflows' ),
1151
- 'thankyou' => __( 'Thank You Page', 'cartflows' ),
1152
- );
1153
-
1154
- foreach ( $steps_data as $slug => $title ) {
1155
-
1156
- $post_content = '';
1157
-
1158
- switch ( $slug ) {
1159
- case 'checkout':
1160
- $post_content = '';
1161
- break;
1162
- case 'thankyou':
1163
- $post_content = '';
1164
- break;
1165
- default:
1166
- $post_content = '';
1167
- break;
1168
- }
1169
-
1170
- $step_id = wp_insert_post(
1171
- array(
1172
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1173
- 'post_title' => $title,
1174
- 'post_content' => $post_content,
1175
- 'post_status' => 'publish',
1176
- )
1177
- );
1178
-
1179
- if ( is_wp_error( $step_id ) ) {
1180
- wp_send_json_error( $step_id->get_error_message() );
1181
- }
1182
-
1183
- if ( $step_id ) {
1184
-
1185
- $flow_steps[] = array(
1186
- 'id' => $step_id,
1187
- 'title' => $title,
1188
- 'type' => $slug,
1189
- );
1190
-
1191
- // insert post meta.
1192
- update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1193
- update_post_meta( $step_id, 'wcf-step-type', $slug );
1194
-
1195
- wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1196
- wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1197
- }
1198
- }
1199
-
1200
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1201
-
1202
- wp_send_json_success( $flow_id );
1203
- }
1204
-
1205
- /**
1206
- * Create Flow
1207
- *
1208
- * @return void
1209
- */
1210
- function create_flow() {
1211
-
1212
- check_ajax_referer( 'cf-create-flow', 'security' );
1213
-
1214
- // Create post object.
1215
- $new_flow_post = array(
1216
- 'post_content' => '',
1217
- 'post_status' => 'publish',
1218
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1219
- );
1220
-
1221
- // Insert the post into the database.
1222
- $flow_id = wp_insert_post( $new_flow_post );
1223
-
1224
- if ( is_wp_error( $flow_id ) ) {
1225
- wp_send_json_error( $flow_id->get_error_message() );
1226
- }
1227
-
1228
- /* Imported Flow */
1229
- update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1230
-
1231
- wp_send_json_success( $flow_id );
1232
- }
1233
-
1234
- /**
1235
- * Create Step
1236
- *
1237
- * @return void
1238
- */
1239
- function import_step() {
1240
-
1241
- check_ajax_referer( 'cf-step-import', 'security' );
1242
-
1243
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1244
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1245
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1246
- $step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
1247
- $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
1248
-
1249
- $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1250
-
1251
- $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1252
-
1253
- wcf()->logger->import_log( '------------------------------------' );
1254
- wcf()->logger->import_log( 'STARTED! Importing STEP' );
1255
- wcf()->logger->import_log( '------------------------------------' );
1256
-
1257
- if ( empty( $template_id ) || empty( $post_id ) ) {
1258
- /* translators: %s: template ID */
1259
- $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1260
- wcf()->logger->import_log( $data );
1261
- wp_send_json_error( $data );
1262
- }
1263
-
1264
- wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1265
-
1266
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1267
-
1268
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1269
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1270
- update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1271
-
1272
- wp_update_post(
1273
- array(
1274
- 'ID' => $post_id,
1275
- 'post_content' => $response['data']['divi_content'],
1276
- )
1277
- );
1278
- }
1279
- }
1280
-
1281
- /* Imported Step */
1282
- update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1283
-
1284
- // Import Post Meta.
1285
- self::import_post_meta( $post_id, $response );
1286
-
1287
- do_action( 'cartflows_import_complete' );
1288
-
1289
- // Batch Process.
1290
- do_action( 'cartflows_after_template_import', $post_id, $response );
1291
-
1292
- wcf()->logger->import_log( '------------------------------------' );
1293
- wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1294
- wcf()->logger->import_log( '------------------------------------' );
1295
-
1296
- wp_send_json_success( $post_id );
1297
- }
1298
-
1299
- /**
1300
- * Import Step.
1301
- *
1302
- * @since 1.0.0
1303
- * @hook wp_ajax_cartflows_step_create_blank
1304
- *
1305
- * @return void
1306
- */
1307
- function step_create_blank() {
1308
-
1309
- check_ajax_referer( 'cf-step-create-blank', 'security' );
1310
-
1311
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1312
- $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
1313
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1314
-
1315
- if ( empty( $flow_id ) || empty( $step_type ) ) {
1316
- /* translators: %s: flow ID */
1317
- $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1318
- wcf()->logger->import_log( $data );
1319
- wp_send_json_error( $data );
1320
- }
1321
-
1322
- wcf()->logger->import_log( '------------------------------------' );
1323
- wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1324
-
1325
- $step_type_title = str_replace( '-', ' ', $step_type );
1326
- $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1327
-
1328
- $new_step_id = wp_insert_post(
1329
- array(
1330
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1331
- 'post_title' => $step_title,
1332
- 'post_content' => '',
1333
- 'post_status' => 'publish',
1334
- )
1335
- );
1336
-
1337
- // insert post meta.
1338
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1339
-
1340
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1341
- $term_exist = term_exists( $step_type_title, $taxonomy );
1342
-
1343
- if ( empty( $term_exist ) ) {
1344
- $terms = array(
1345
- array(
1346
- 'name' => $step_type_title,
1347
- ),
1348
- );
1349
-
1350
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1351
- wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
1352
- }
1353
-
1354
- $current_term = term_exists( $step_type_title, $taxonomy );
1355
-
1356
- // Set type object.
1357
- $data = get_term( $current_term['term_id'], $taxonomy );
1358
- $step_slug = $data->slug;
1359
- wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1360
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1361
-
1362
- // Set type.
1363
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1364
- wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1365
-
1366
- // Set flow.
1367
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1368
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1369
-
1370
- CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1371
-
1372
- wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1373
- wcf()->logger->import_log( '------------------------------------' );
1374
-
1375
- wp_send_json_success( $new_step_id );
1376
- }
1377
-
1378
- /**
1379
- * Import Post Meta
1380
- *
1381
- * @since 1.0.0
1382
- *
1383
- * @param integer $post_id Post ID.
1384
- * @param array $response Post meta.
1385
- * @return void
1386
- */
1387
- public static function import_post_meta( $post_id, $response ) {
1388
-
1389
- $metadata = (array) $response['post_meta'];
1390
-
1391
- foreach ( $metadata as $meta_key => $meta_value ) {
1392
- $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1393
-
1394
- if ( $meta_value ) {
1395
-
1396
- if ( is_serialized( $meta_value, true ) ) {
1397
- $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1398
- } elseif ( is_array( $meta_value ) ) {
1399
- $raw_data = json_decode( stripslashes( $meta_value ), true );
1400
- } else {
1401
- $raw_data = $meta_value;
1402
- }
1403
-
1404
- if ( '_elementor_data' === $meta_key ) {
1405
- if ( is_array( $raw_data ) ) {
1406
- $raw_data = wp_slash( json_encode( $raw_data ) );
1407
- } else {
1408
- $raw_data = wp_slash( $raw_data );
1409
- }
1410
- }
1411
- if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1412
- if ( is_array( $raw_data ) ) {
1413
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
1414
- } else {
1415
- if ( ! is_object( $raw_data ) ) {
1416
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1417
- }
1418
- }
1419
- }
1420
-
1421
- update_post_meta( $post_id, $meta_key, $raw_data );
1422
- }
1423
- }
1424
- }
1425
-
1426
- /**
1427
- * Import Template for Elementor
1428
- *
1429
- * @since 1.0.0
1430
- *
1431
- * @param integer $post_id Post ID.
1432
- * @param array $response Post meta.
1433
- * @param array $page_build_data Page build data.
1434
- * @return void
1435
- */
1436
- public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1437
- if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1438
- $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1439
- wcf()->logger->import_log( $data );
1440
- wp_send_json_error( $data );
1441
- }
1442
-
1443
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1444
-
1445
- wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1446
-
1447
- $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1448
- $obj->import_single_template( $post_id );
1449
-
1450
- wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1451
- }
1452
-
1453
- /**
1454
- * Supported post types
1455
- *
1456
- * @since 1.0.0
1457
- *
1458
- * @return array Supported post types.
1459
- */
1460
- public static function supported_post_types() {
1461
- return apply_filters(
1462
- 'cartflows_supported_post_types',
1463
- array(
1464
- CARTFLOWS_FLOW_POST_TYPE,
1465
- )
1466
- );
1467
- }
1468
-
1469
- /**
1470
- * Check supported post type
1471
- *
1472
- * @since 1.0.0
1473
- *
1474
- * @param string $post_type Post type.
1475
- * @return boolean Supported post type status.
1476
- */
1477
- public static function is_supported_post( $post_type = '' ) {
1478
- if ( in_array( $post_type, self::supported_post_types() ) ) {
1479
- return true;
1480
- }
1481
-
1482
- return false;
1483
- }
1484
-
1485
- /**
1486
- * Set steps to the flow
1487
- *
1488
- * @param integer $flow_id Flow ID.
1489
- * @param integer $new_step_id New step ID.
1490
- * @param string $step_title Flow Type.
1491
- * @param string $step_slug Flow Type.
1492
- */
1493
- function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1494
- // Update steps for the current flow.
1495
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1496
-
1497
- if ( ! is_array( $flow_steps ) ) {
1498
- $flow_steps = array();
1499
- }
1500
-
1501
- $flow_steps[] = array(
1502
- 'id' => $new_step_id,
1503
- 'title' => $step_title,
1504
- 'type' => $step_slug,
1505
- );
1506
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1507
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1508
- }
1509
-
1510
- /**
1511
- * Localize variables in admin
1512
- *
1513
- * @param array $vars variables.
1514
- */
1515
- function localize_vars( $vars ) {
1516
-
1517
- $ajax_actions = array(
1518
- 'cf_step_import',
1519
- 'cf_load_steps',
1520
- 'cf_create_flow',
1521
- 'cf_default_flow',
1522
- 'cf_step_create_blank',
1523
- 'cf_import_flow_step',
1524
- );
1525
-
1526
- foreach ( $ajax_actions as $action ) {
1527
-
1528
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1529
- }
1530
-
1531
- return $vars;
1532
- }
1533
-
1534
- /**
1535
- * Ajax action to activate plugin
1536
- */
1537
- public function activate_plugin() {
1538
-
1539
- $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
1540
-
1541
- $activate = activate_plugin( $plugin_init, '', false, true );
1542
-
1543
- if ( is_wp_error( $activate ) ) {
1544
- wp_send_json_error(
1545
- array(
1546
- 'success' => false,
1547
- 'message' => $activate->get_error_message(),
1548
- 'init' => $plugin_init,
1549
- )
1550
- );
1551
- }
1552
-
1553
- wp_send_json_success(
1554
- array(
1555
- 'success' => true,
1556
- 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1557
- 'init' => $plugin_init,
1558
- )
1559
- );
1560
- }
1561
-
1562
- }
1563
-
1564
- /**
1565
- * Initialize class object with 'get_instance()' method
1566
- */
1567
- CartFlows_Importer::get_instance();
1568
-
1569
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows Admin
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'CartFlows_Importer' ) ) :
10
+
11
+ /**
12
+ * CartFlows Import
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class CartFlows_Importer {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.0.0
45
+ */
46
+ public function __construct() {
47
+ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
48
+ add_action( 'wp_ajax_cartflows_load_steps', array( $this, 'load_templates' ) );
49
+ add_action( 'wp_ajax_cartflows_step_import', array( $this, 'import_step' ) );
50
+ add_action( 'wp_ajax_cartflows_create_flow', array( $this, 'create_flow' ) );
51
+ add_action( 'wp_ajax_cartflows_default_flow', array( $this, 'create_default_flow' ) );
52
+ add_action( 'wp_ajax_cartflows_step_create_blank', array( $this, 'step_create_blank' ) );
53
+ add_action( 'wp_ajax_cartflows_import_flow_step', array( $this, 'import_flow' ) );
54
+ add_action( 'admin_footer', array( $this, 'js_templates' ) );
55
+ add_action( 'cartflows_import_complete', array( $this, 'clear_cache' ) );
56
+
57
+ add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
58
+
59
+ add_action( 'wp_ajax_cartflows_activate_plugin', array( $this, 'activate_plugin' ) );
60
+
61
+ add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
62
+ add_action( 'admin_init', array( $this, 'export_json' ) );
63
+ add_action( 'admin_init', array( $this, 'import_json' ) );
64
+ add_filter( 'post_row_actions', array( $this, 'export_link' ), 10, 2 );
65
+ add_action( 'admin_action_cartflows_export_flow', array( $this, 'export_flow' ) );
66
+ }
67
+
68
+ /**
69
+ * Add the export link to action list for flows row actions
70
+ *
71
+ * @since 1.1.4
72
+ *
73
+ * @param array $actions Actions array.
74
+ * @param object $post Post object.
75
+ *
76
+ * @return array
77
+ */
78
+ function export_link( $actions, $post ) {
79
+ if ( current_user_can( 'edit_posts' ) && isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) {
80
+ $actions['export'] = '<a href="' . wp_nonce_url( 'admin.php?action=cartflows_export_flow&post=' . $post->ID, basename( __FILE__ ), 'flow_export_nonce' ) . '" title="' . __( 'Export this flow', 'cartflows' ) . '" rel="permalink">' . __( 'Export', 'cartflows' ) . '</a>';
81
+ }
82
+ return $actions;
83
+ }
84
+
85
+ /**
86
+ * Add menus
87
+ *
88
+ * @since 1.1.4
89
+ */
90
+ function add_to_menus() {
91
+ add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Export', 'cartflows' ), __( 'Flow Export', 'cartflows' ), 'export', 'flow_exporter', array( $this, 'exporter_markup' ) );
92
+ add_submenu_page( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, __( 'Flow Import', 'cartflows' ), __( 'Flow Import', 'cartflows' ), 'import', 'flow_importer', array( $this, 'importer_markup' ) );
93
+ }
94
+
95
+ /**
96
+ * Export flow with steps and its meta
97
+ *
98
+ * @since 1.1.4
99
+ */
100
+ function export_flow() {
101
+
102
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
+ wp_die( __( 'No post to export has been supplied!', 'cartflows' ) );
104
+ }
105
+
106
+ if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( $_GET['flow_export_nonce'], basename( __FILE__ ) ) ) {
107
+ return;
108
+ }
109
+
110
+ // Get the original post id.
111
+ $flow_id = ( isset( $_GET['post'] ) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
112
+
113
+ $flows = array();
114
+ $flows[] = $this->get_flow_export_data( $flow_id );
115
+ $flows = apply_filters( 'cartflows_export_data', $flows );
116
+
117
+ nocache_headers();
118
+ header( 'Content-Type: application/json; charset=utf-8' );
119
+ header( 'Content-Disposition: attachment; filename=cartflows-flow-' . $flow_id . '-' . date( 'm-d-Y' ) . '.json' );
120
+ header( 'Expires: 0' );
121
+
122
+ echo json_encode( $flows );
123
+ exit;
124
+ }
125
+
126
+ /**
127
+ * Export flow markup
128
+ *
129
+ * @since 1.1.4
130
+ */
131
+ function exporter_markup() {
132
+ include_once CARTFLOWS_DIR . 'includes/exporter.php';
133
+ }
134
+
135
+ /**
136
+ * Import flow markup
137
+ *
138
+ * @since 1.1.4
139
+ */
140
+ function importer_markup() {
141
+ include_once CARTFLOWS_DIR . 'includes/importer.php';
142
+ }
143
+
144
+ /**
145
+ * Export flow
146
+ *
147
+ * @since 1.1.4
148
+ */
149
+ function export_json() {
150
+ if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
+ return;
152
+ }
153
+
154
+ if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
155
+ return;
156
+ }
157
+
158
+ if ( ! current_user_can( 'manage_options' ) ) {
159
+ return;
160
+ }
161
+
162
+ $flows = $this->get_all_flow_export_data();
163
+ $flows = apply_filters( 'cartflows_export_data', $flows );
164
+
165
+ nocache_headers();
166
+ header( 'Content-Type: application/json; charset=utf-8' );
167
+ header( 'Content-Disposition: attachment; filename=cartflows-flow-export-' . date( 'm-d-Y' ) . '.json' );
168
+ header( 'Expires: 0' );
169
+
170
+ echo json_encode( $flows );
171
+ exit;
172
+ }
173
+
174
+ /**
175
+ * Get flow export data
176
+ *
177
+ * @since 1.1.4
178
+ *
179
+ * @param integer $flow_id Flow ID.
180
+ * @return array
181
+ */
182
+ function get_flow_export_data( $flow_id ) {
183
+
184
+ $export_all = apply_filters( 'cartflows_export_all', false );
185
+
186
+ $valid_step_meta_keys = array(
187
+ '_wp_page_template',
188
+ '_thumbnail_id',
189
+ 'classic-editor-remember',
190
+ );
191
+
192
+ $new_steps = array();
193
+ $steps = get_post_meta( $flow_id, 'wcf-steps', true );
194
+ if ( $steps ) {
195
+ foreach ( $steps as $key => $step ) {
196
+
197
+ // Add step post meta.
198
+ $new_all_meta = array();
199
+ $all_meta = get_post_meta( $step['id'] );
200
+ if ( is_array( $all_meta ) ) {
201
+
202
+ if ( $export_all ) {
203
+ foreach ( $all_meta as $meta_key => $value ) {
204
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
205
+ }
206
+ } else {
207
+
208
+ foreach ( $all_meta as $meta_key => $value ) {
209
+ if ( substr( $meta_key, 0, strlen( 'wcf' ) ) === 'wcf' ) {
210
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
211
+ } elseif ( in_array( $meta_key, $valid_step_meta_keys ) ) {
212
+ $new_all_meta[ $meta_key ] = maybe_unserialize( $value[0] );
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // Add single step.
219
+ $step_data_arr = array(
220
+ 'title' => get_the_title( $step['id'] ),
221
+ 'type' => $step['type'],
222
+ 'meta' => $new_all_meta,
223
+ 'post_content' => '',
224
+ );
225
+
226
+ if ( $export_all ) {
227
+
228
+ $step_post_obj = get_post( $step['id'] );
229
+
230
+ $step_data_arr['post_content'] = $step_post_obj->post_content;
231
+ }
232
+
233
+ $new_steps[] = $step_data_arr;
234
+ }
235
+ }
236
+
237
+ // Add single flow.
238
+ return array(
239
+ 'title' => get_the_title( $flow_id ),
240
+ 'steps' => $new_steps,
241
+ );
242
+ }
243
+
244
+ /**
245
+ * Get all flow export data
246
+ *
247
+ * @since 1.1.4
248
+ */
249
+ function get_all_flow_export_data() {
250
+
251
+ $query_args = array(
252
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
253
+
254
+ // Query performance optimization.
255
+ 'fields' => 'ids',
256
+ 'no_found_rows' => true,
257
+ 'posts_per_page' => -1,
258
+ );
259
+
260
+ $query = new WP_Query( $query_args );
261
+ $flows = array();
262
+ if ( $query->posts ) {
263
+ foreach ( $query->posts as $key => $post_id ) {
264
+ $flows[] = $this->get_flow_export_data( $post_id );
265
+ }
266
+ }
267
+
268
+ return $flows;
269
+ }
270
+
271
+ /**
272
+ * Import our exported file
273
+ *
274
+ * @since 1.1.4
275
+ */
276
+ function import_json() {
277
+ if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
+ return;
279
+ }
280
+
281
+ if ( ! wp_verify_nonce( $_POST['cartflows-action-nonce'], 'cartflows-action-nonce' ) ) {
282
+ return;
283
+ }
284
+
285
+ if ( ! current_user_can( 'manage_options' ) ) {
286
+ return;
287
+ }
288
+
289
+ $filename = $_FILES['file']['name'];
290
+ $file_info = explode( '.', $filename );
291
+ $extension = end( $file_info );
292
+
293
+ if ( 'json' != $extension ) {
294
+ wp_die( __( 'Please upload a valid .json file', 'cartflows' ) );
295
+ }
296
+
297
+ $file = $_FILES['file']['tmp_name'];
298
+
299
+ if ( empty( $file ) ) {
300
+ wp_die( __( 'Please upload a file to import', 'cartflows' ) );
301
+ }
302
+
303
+ // Retrieve the settings from the file and convert the JSON object to an array.
304
+ $flows = json_decode( file_get_contents( $file ), true );
305
+
306
+ if ( $flows ) {
307
+
308
+ foreach ( $flows as $key => $flow ) {
309
+
310
+ $flow_title = $flow['title'];
311
+ if ( post_exists( $flow['title'] ) ) {
312
+ $flow_title = $flow['title'] . ' Copy';
313
+ }
314
+
315
+ // Create post object.
316
+ $new_flow_args = array(
317
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
318
+ 'post_title' => $flow_title,
319
+ 'post_status' => 'draft',
320
+ );
321
+
322
+ // Insert the post into the database.
323
+ $flow_id = wp_insert_post( $new_flow_args );
324
+
325
+ if ( $flow['steps'] ) {
326
+ foreach ( $flow['steps'] as $key => $step ) {
327
+
328
+ $new_step_id = wp_insert_post(
329
+ array(
330
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
331
+ 'post_title' => $step['title'],
332
+ 'post_status' => 'publish',
333
+ 'meta_input' => $step['meta'],
334
+ 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
335
+ )
336
+ );
337
+
338
+ // Insert post meta.
339
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
340
+
341
+ $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
342
+ $current_term = term_exists( $step['type'], $step_taxonomy );
343
+
344
+ // // Set type object.
345
+ $data = get_term( $current_term['term_id'], $step_taxonomy );
346
+ $step_slug = $data->slug;
347
+ wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
348
+
349
+ // Set type.
350
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
351
+
352
+ // Set flow.
353
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
354
+
355
+ CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
356
+
357
+ if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
358
+
359
+ // Download and replace images.
360
+ $content = $this->get_content( $step['post_content'] );
361
+
362
+ // Update post content.
363
+ wp_update_post(
364
+ array(
365
+ 'ID' => $new_step_id,
366
+ 'post_content' => $content,
367
+ )
368
+ );
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+
375
+ add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
376
+ }
377
+
378
+ /**
379
+ * Download and Replace hotlink images
380
+ *
381
+ * @since x.x.x
382
+ *
383
+ * @param string $content Mixed post content.
384
+ * @return array Hotlink image array.
385
+ */
386
+ function get_content( $content = '' ) {
387
+
388
+ $all_links = wp_extract_urls( $content );
389
+ $image_links = array();
390
+ $image_map = array();
391
+
392
+ // Not have any link.
393
+ if ( empty( $all_links ) ) {
394
+ return $content;
395
+ }
396
+
397
+ foreach ( $all_links as $key => $link ) {
398
+ if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
399
+ $image_links[] = $link;
400
+ }
401
+ }
402
+
403
+ // Not have any image link.
404
+ if ( empty( $image_links ) ) {
405
+ return $content;
406
+ }
407
+
408
+ foreach ( $image_links as $key => $image_url ) {
409
+
410
+ // Download remote image.
411
+ $image = array(
412
+ 'url' => $image_url,
413
+ 'id' => rand( 000, 999 ),
414
+ );
415
+ $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
416
+
417
+ // Old and New image mapping links.
418
+ $image_map[ $image_url ] = $downloaded_image['url'];
419
+ }
420
+
421
+ // Replace old image links with new image links.
422
+ foreach ( $image_map as $old_url => $new_url ) {
423
+ $content = str_replace( $old_url, $new_url, $content );
424
+ }
425
+
426
+ return $content;
427
+
428
+ }
429
+
430
+ /**
431
+ * Imported notice
432
+ *
433
+ * @since 1.1.4
434
+ */
435
+ function imported_successfully() {
436
+ ?>
437
+ <div class="notice notice-success">
438
+ <p><?php _e( 'Successfully imported flows.', 'cartflows' ); ?></p>
439
+ </div>
440
+ <?php
441
+ }
442
+
443
+ /**
444
+ * Clear Cache.
445
+ *
446
+ * @since 1.0.0
447
+ */
448
+ public function clear_cache() {
449
+ // Clear 'Elementor' file cache.
450
+ if ( class_exists( '\Elementor\Plugin' ) ) {
451
+ Elementor\Plugin::$instance->files_manager->clear_cache();
452
+ }
453
+ }
454
+
455
+ /**
456
+ * JS Templates
457
+ *
458
+ * @since 1.0.0
459
+ *
460
+ * @return void
461
+ */
462
+ function js_templates() {
463
+
464
+ // Loading Templates.
465
+ ?>
466
+ <script type="text/template" id="tmpl-cartflows-step-loading">
467
+ <div class="template-message-block cartflows-step-loading">
468
+ <h2>
469
+ <span class="spinner"></span>
470
+ <?php _e( 'Loading Steps', 'cartflows' ); ?>
471
+ </h2>
472
+ <p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
473
+ </div>
474
+ </script>
475
+
476
+ <?php
477
+ // Search Templates.
478
+ ?>
479
+ <script type="text/template" id="tmpl-cartflows-searching-templates">
480
+ <div class="template-message-block cartflows-searching-templates">
481
+ <h2>
482
+ <span class="spinner"></span>
483
+ <?php _e( 'Searching Template..', 'cartflows' ); ?>
484
+ </h2>
485
+ <p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
486
+ </div>
487
+ </script>
488
+
489
+ <?php
490
+ // CartFlows Importing Template.
491
+ ?>
492
+ <script type="text/template" id="tmpl-cartflows-step-importing">
493
+ <div class="template-message-block cartflows-step-importing">
494
+ <h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
495
+ </div>
496
+ </script>
497
+
498
+ <?php
499
+ // CartFlows Imported.
500
+ ?>
501
+ <script type="text/template" id="tmpl-cartflows-step-imported">
502
+ <div class="template-message-block cartflows-step-imported">
503
+ <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
504
+ <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
505
+ </script>
506
+
507
+ <?php
508
+ // No templates.
509
+ ?>
510
+ <script type="text/template" id="tmpl-cartflows-no-steps">
511
+ <div class="cartflows-no-steps">
512
+ <div class="template-message-block">
513
+ <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
514
+ <p class="description"></p>
515
+ </div>
516
+ </div>
517
+ </script>
518
+
519
+ <?php
520
+ // No templates.
521
+ ?>
522
+ <script type="text/template" id="tmpl-cartflows-no-flows">
523
+ <div class="cartflows-no-flows">
524
+ <div class="template-message-block">
525
+ <h2><?php _e( 'Coming Soon!', 'cartflows' ); ?></h2>
526
+ <p class="description"></p>
527
+ </div>
528
+ </div>
529
+ </script>
530
+
531
+ <?php
532
+ // Error handling.
533
+ ?>
534
+ <script type="text/template" id="tmpl-templator-error">
535
+ <div class="notice notice-error"><p>{{ data }}</p></div>
536
+ </script>
537
+
538
+ <?php
539
+ // Redirect to Elementor.
540
+ ?>
541
+ <script type="text/template" id="tmpl-templator-redirect-to-elementor">
542
+ <div class="template-message-block templator-redirect-to-elementor">
543
+ <h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
544
+ <p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
545
+ </script>
546
+
547
+ <?php
548
+ /**
549
+ * Responsive Buttons
550
+ */
551
+ ?>
552
+ <script type="text/template" id="tmpl-cartflows-responsive-view">
553
+ <span class="responsive-view">
554
+ <span class="actions">
555
+ <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
556
+ <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
557
+ <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
558
+ </span>
559
+ </span>
560
+ </script>
561
+
562
+ <?php
563
+ // Templates data.
564
+ ?>
565
+ <script type="text/template" id="tmpl-cartflows-flows-list">
566
+
567
+ <# console.log( data.items.length ) #>
568
+ <# console.log( data.items ) #>
569
+ <# if ( data.items.length ) { #>
570
+ <# for ( key in data.items ) { #>
571
+ <#
572
+ var flow_steps = [];
573
+ if( data.items[ key ].flow_steps ) {
574
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
575
+ return value['id'];
576
+ });
577
+ }
578
+ #>
579
+ <div class="inner">
580
+ <div class="template">
581
+ <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
582
+ <div class="template-screenshot">
583
+ <# if( data.items[ key ].featured_image_url ) { #>
584
+ <img src="{{ data.items[ key ].featured_image_url }}" />
585
+ <# } else { #>
586
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
587
+ <# } #>
588
+ </div>
589
+ <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>flow={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
590
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
591
+ <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
592
+ <# } #>
593
+ </span>
594
+ <div class="template-id-container">
595
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
596
+ <div class="template-actions">
597
+
598
+ <#
599
+ if( data.items[ key ].page_builder.slug ) {
600
+ required_plugin_group = data.items[ key ].page_builder.slug;
601
+ } else {
602
+ required_plugin_group = '';
603
+ }
604
+
605
+ if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
606
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
607
+ } else {
608
+ import_btn_title = 'Import';
609
+ } #>
610
+
611
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
612
+ <a data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
613
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
614
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
615
+ <# } else { #>
616
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
617
+ <# } #>
618
+ </div>
619
+ </div>
620
+ </div>
621
+ </div>
622
+ <# } #>
623
+ <# } #>
624
+ </script>
625
+
626
+ <?php
627
+ // Empty Step.
628
+ ?>
629
+ <script type="text/template" id="tmpl-cartflows-create-blank-step">
630
+ <div class="inner">
631
+ <div class="template">
632
+ <span class="thumbnail site-preview cartflows-flow-preview">
633
+ <div class="template-screenshot">
634
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
635
+ </div>
636
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
637
+ </span>
638
+ <div class="template-id-container">
639
+ <h3 class="template-name"> Blank </h3>
640
+ <div class="template-actions">
641
+ <a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
642
+ </div>
643
+ </div>
644
+ </div>
645
+ </div>
646
+ </script>
647
+
648
+ <?php
649
+ // Templates data.
650
+ ?>
651
+ <script type="text/template" id="tmpl-cartflows-steps-list">
652
+ <# if ( data.items.length ) { #>
653
+ <# for ( key in data.items ) { #>
654
+ <#
655
+ var flow_steps = [];
656
+ if( data.items[ key ].flow_steps ) {
657
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
658
+ return value['id'];
659
+ });
660
+ }
661
+ #>
662
+ <div class="inner">
663
+ <div class="template">
664
+ <span class="thumbnail site-preview cartflows-preview-flow-steps" data-flow-steps="{{ JSON.stringify( data.items[ key ].flow_steps ) }}" data-title="{{ data.items[ key ].title.rendered }}">
665
+ <div class="template-screenshot">
666
+ <# if( data.items[ key ].featured_image_url ) { #>
667
+ <img src="{{ data.items[ key ].featured_image_url }}" />
668
+ <# } else { #>
669
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
670
+ <# } #>
671
+ </div>
672
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
673
+ <a href="<?php echo CARTFLOWS_TEMPLATES_URL . 'preview/?'; ?>step={{ data.items[ key ].id }}&title={{{ data.items[ key ].title.rendered }}}" class="preview" target="_blank">Preview <i class="dashicons dashicons-external"></i></a>
674
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
675
+ <span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
676
+ <# } #>
677
+ </span>
678
+ <div class="template-id-container">
679
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
680
+ <div class="template-actions">
681
+
682
+ <#
683
+
684
+ var step_slug = data.items[ key ].step_type.slug || '';
685
+ var step_title = data.items[ key ].step_type.name || '';
686
+ var import_btn_title = 'Import';
687
+
688
+ var required_plugin_group = '';
689
+ if( data.items[ key ].page_builder ) {
690
+ required_plugin_group = data.items[ key ].page_builder.slug;
691
+
692
+ if( data.items[ key ].page_builder.slug && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug] && CartFlowsImportVars.required_plugins[data.items[ key ].page_builder.slug].button_title ) {
693
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
694
+ }
695
+ }
696
+ #>
697
+
698
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
699
+ <a data-slug="{{step_slug}}" data-title="{{step_title}}" data-flow-steps="{{ flow_steps }}" data-required-plugin-group="{{required_plugin_group}}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}">{{ import_btn_title }}</a>
700
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
701
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
702
+ <# } else { #>
703
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
704
+ <# } #>
705
+ </div>
706
+ </div>
707
+ </div>
708
+ </div>
709
+ <# } #>
710
+ <# } #>
711
+ </script>
712
+
713
+ <?php
714
+ /**
715
+ * TMPL - Website Unreachable
716
+ */
717
+ ?>
718
+ <script type="text/template" id="tmpl-cartflows-website-unreachable">
719
+ <div class="postbox cartflows-website-unreachable">
720
+ <h2><?php _e( 'Under Maintenance..', 'cartflows' ); ?></h2>
721
+ <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
722
+ <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website..', 'cartflows' ); ?></p>
723
+ </div>
724
+ </script>
725
+
726
+ <?php
727
+ /**
728
+ * TMPL - Filters
729
+ */
730
+ ?>
731
+ <script type="text/template" id="tmpl-cartflows-page-builder-notice">
732
+ <?php
733
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
734
+ $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
735
+ $title = $page_builder['title'];
736
+
737
+ $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
738
+ $theme_status = '';
739
+ if ( 'divi' === $default_page_builder ) {
740
+
741
+ $theme_status = $page_builder['theme-status'];
742
+ $plugin_status = $page_builder['plugin-status'];
743
+
744
+ if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
745
+ $plugin_string = 'Please activate ' . esc_html( $title );
746
+ } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
747
+ $plugin_string = 'Please install and activate ' . esc_html( $title );
748
+ }
749
+ }
750
+ ?>
751
+ <div class="wcf-page-builder-message">
752
+ <p><?php /* translators: %s: Plugin string */ printf( __( '%1$s to see CartFlows templates. If you prefer another page builder tool, you can <a href="%2$s" target="blank">select it here</a>.', 'cartflows' ), $plugin_string, admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS . '&action=common-settings#form-field-wcf_default_page_builder' ) ); ?></p>
753
+ <p>If your preferred page builder is not available, feel free to <a href="#" data-slug="canvas" class="wcf-create-from-scratch-link">create your own</a> pages using page builder of your choice as CartFlows works with all major page builders.</p>
754
+ <p>We plan to add design templates made with more page builder shortly!</p>
755
+ </div>
756
+ </script>
757
+
758
+ <?php
759
+ /**
760
+ * TMPL - Filters
761
+ */
762
+ ?>
763
+ <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
764
+ <# if ( data ) { #>
765
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
766
+ <# if ( data.args.show_all ) { #>
767
+ <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
768
+ <# } #>
769
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
770
+ <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
771
+ <# } #>
772
+ <# for ( key in data.items ) { #>
773
+ <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
774
+ <# } #>
775
+ </select>
776
+ <# } #>
777
+ </script>
778
+
779
+ <script type="text/template" id="tmpl-cartflows-term-filters">
780
+
781
+ <# if ( data ) { #>
782
+
783
+ <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
784
+ <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
785
+
786
+ <# if ( data.args.show_all ) { #>
787
+ <li>
788
+ <a href="#" data-group="all"> All </a>
789
+ </li>
790
+ <# } #>
791
+
792
+ <# for ( key in data.items ) { #>
793
+ <li>
794
+ <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</a>
795
+ </li>
796
+ <# } #>
797
+
798
+ </ul>
799
+
800
+ <?php
801
+
802
+ /*
803
+ <# } else { #>
804
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
805
+
806
+ <# if ( data.args.show_all ) { #>
807
+ <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
808
+ <# } #>
809
+
810
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
811
+ <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
812
+ <# } #>
813
+
814
+ <# for ( key in data.items ) { #>
815
+ <option value='{{ data.items[ key ].id }}' data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}" data-slug="{{ data.items[ key ].slug }}" data-title="{{ data.items[ key ].name }}">{{ data.items[ key ].name }}</option>
816
+ <# } #>
817
+
818
+ </select>
819
+ */
820
+ ?>
821
+
822
+ <?php /* <# } #> */ ?>
823
+
824
+ <# } #>
825
+ </script>
826
+
827
+ <?php
828
+ // Step Type.
829
+ ?>
830
+ <script type="text/template" id="tmpl-cartflows-step-types">
831
+ <ul class="wcf-tab nav-tabs">
832
+ <# if( data.items_count ) { #>
833
+ <# for( key in data.items ) { #>
834
+ <# console.log( data.items[ key ].id ) #>
835
+ <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
836
+ <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
837
+ </li>
838
+ <# } #>
839
+ <# } #>
840
+ </ul>
841
+ </script>
842
+
843
+ <?php
844
+ // Add to library button.
845
+ ?>
846
+ <script type="text/template" id="tmpl-templator-add-to-library">
847
+ <a class="templator-add-to-library page-title-action cartflows-load-steps-library"><i class="dashicons dashicons-cloud"></i><?php esc_attr_e( 'Import from Cloud', 'cartflows' ); ?></a>
848
+ </script>
849
+ <?php
850
+ }
851
+
852
+ /**
853
+ * Enqueue scripts
854
+ *
855
+ * @since 1.0.0
856
+ *
857
+ * @hook admin_enqueue_scripts
858
+ * @param string $hook Current page hook.
859
+ */
860
+ function scripts( $hook = '' ) {
861
+
862
+ if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
863
+ return;
864
+ }
865
+
866
+ wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
867
+ wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
868
+ wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
869
+ wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
870
+
871
+ $localize_vars = array(
872
+ '_is_pro_active' => _is_cartflows_pro(),
873
+
874
+ // Flow and its rest fields.
875
+ 'flow' => CARTFLOWS_FLOW_POST_TYPE,
876
+ 'flow_fields' => array(
877
+ 'id',
878
+ 'title',
879
+ 'flow_type',
880
+ 'page_builder',
881
+ 'flow_steps',
882
+ 'licence_status',
883
+ 'featured_image_url',
884
+ 'featured_media', // @required for field `featured_image_url`.
885
+ ),
886
+
887
+ // Flow type and rest fields.
888
+ 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
889
+ 'flow_type_fields' => array(
890
+ 'id',
891
+ 'name',
892
+ 'slug',
893
+ ),
894
+
895
+ // Flow page builder and rest fields.
896
+ 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
897
+ 'flow_page_builder_fields' => array(
898
+ 'id',
899
+ 'name',
900
+ 'slug',
901
+ ),
902
+
903
+ // Step page builder and rest fields.
904
+ 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
905
+ 'step_page_builder_fields' => array(
906
+ 'id',
907
+ 'name',
908
+ 'slug',
909
+ ),
910
+
911
+ // Step and its rest fields.
912
+ 'step' => CARTFLOWS_STEP_POST_TYPE,
913
+ 'step_fields' => array(
914
+ 'title',
915
+ 'featured_image_url',
916
+ 'featured_media', // @required for field `featured_image_url`.
917
+ 'id',
918
+ 'flow_type',
919
+ 'step_type',
920
+ 'page_builder',
921
+ 'licence_status',
922
+ ),
923
+
924
+ // Step type and its rest fields.
925
+ 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
926
+ 'step_type_fields' => array(
927
+ 'id',
928
+ 'name',
929
+ 'slug',
930
+ ),
931
+
932
+ 'domain_url' => CARTFLOWS_DOMAIN_URL,
933
+ 'server_url' => CARTFLOWS_TEMPLATES_URL,
934
+ 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
935
+ 'site_url' => site_url(),
936
+ 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
937
+ 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
938
+ 'admin_url' => admin_url(),
939
+ 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
940
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
941
+ 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
942
+
943
+ 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
944
+
945
+ 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
946
+ );
947
+
948
+ // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
949
+ // wp_die( );
950
+ // Add thickbox.
951
+ add_thickbox();
952
+
953
+ wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
954
+ wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
955
+ }
956
+
957
+ /**
958
+ * Load Template
959
+ *
960
+ * @since 1.0.0
961
+ *
962
+ * @hook cartflows_load_steps
963
+ * @return void
964
+ */
965
+ function load_templates() {
966
+
967
+ check_ajax_referer( 'cf-load-steps', 'security' );
968
+
969
+ $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
970
+ $templates = CartFlows_API::get_instance()->get_templates( $args );
971
+
972
+ if ( $templates['templates_count'] ) {
973
+ wp_send_json_success( $templates );
974
+ } else {
975
+ wp_send_json_error( $templates );
976
+ }
977
+ wp_die();
978
+ }
979
+
980
+ /**
981
+ * Import.
982
+ *
983
+ * @since 1.0.0
984
+ *
985
+ * @hook wp_ajax_cartflows_import_flow_step
986
+ * @return void
987
+ */
988
+ function import_flow() {
989
+
990
+ check_ajax_referer( 'cf-import-flow-step', 'security' );
991
+
992
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
993
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
994
+
995
+ wcf()->logger->import_log( '------------------------------------' );
996
+ wcf()->logger->import_log( 'STARTED! Importing FLOW' );
997
+ wcf()->logger->import_log( '------------------------------------' );
998
+ wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
999
+
1000
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1001
+
1002
+ $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1003
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1004
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1005
+ $post_content = $response['data']['divi_content'];
1006
+ }
1007
+ }
1008
+
1009
+ if ( false === $response['success'] ) {
1010
+ wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1011
+ wp_send_json_error( $response );
1012
+ }
1013
+
1014
+ wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
1015
+
1016
+ $new_step_id = wp_insert_post(
1017
+ array(
1018
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1019
+ 'post_title' => $response['title'],
1020
+ 'post_content' => $post_content,
1021
+ 'post_status' => 'publish',
1022
+ )
1023
+ );
1024
+
1025
+ if ( is_wp_error( $new_step_id ) ) {
1026
+ wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1027
+ wp_send_json_error( $new_step_id );
1028
+ }
1029
+
1030
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1031
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1032
+ update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1033
+ }
1034
+ }
1035
+
1036
+ /* Imported Step */
1037
+ update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1038
+
1039
+ wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
1040
+ // insert post meta.
1041
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1042
+ wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1043
+
1044
+ /**
1045
+ * Import & Set type.
1046
+ */
1047
+ $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1048
+ $term_slug = '';
1049
+ if ( $term ) {
1050
+
1051
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1052
+ $term_exist = term_exists( $term->name, $taxonomy );
1053
+
1054
+ if ( empty( $term_exist ) ) {
1055
+ $terms = array(
1056
+ array(
1057
+ 'name' => $term->name,
1058
+ ),
1059
+ );
1060
+
1061
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1062
+ wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
1063
+ }
1064
+
1065
+ $current_term = term_exists( $term->name, $taxonomy );
1066
+
1067
+ // Set type object.
1068
+ $data = get_term( $current_term['term_id'], $taxonomy );
1069
+ $term_slug = $data->slug;
1070
+ $term_name = $data->name;
1071
+ wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1072
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1073
+
1074
+ // Set type.
1075
+ update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1076
+ wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1077
+ }
1078
+
1079
+ // Set flow.
1080
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1081
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1082
+
1083
+ /**
1084
+ * Update steps for the current flow.
1085
+ */
1086
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1087
+
1088
+ if ( ! is_array( $flow_steps ) ) {
1089
+ $flow_steps = array();
1090
+ }
1091
+
1092
+ $flow_steps[] = array(
1093
+ 'id' => $new_step_id,
1094
+ 'title' => $response['title'],
1095
+ 'type' => $term_slug,
1096
+ );
1097
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1098
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1099
+
1100
+ // Import Post Meta.
1101
+ self::import_post_meta( $new_step_id, $response );
1102
+
1103
+ wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1104
+ wcf()->logger->import_log( '------------------------------------' );
1105
+ wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1106
+ wcf()->logger->import_log( '------------------------------------' );
1107
+
1108
+ do_action( 'cartflows_import_complete' );
1109
+ wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1110
+
1111
+ // Batch Process.
1112
+ do_action( 'cartflows_after_template_import', $new_step_id, $response );
1113
+
1114
+ /**
1115
+ * End
1116
+ */
1117
+ wp_send_json_success( $new_step_id );
1118
+ }
1119
+
1120
+ /**
1121
+ * Import Step.
1122
+ *
1123
+ * @since 1.0.0
1124
+ * @hook wp_ajax_cartflows_step_import
1125
+ *
1126
+ * @return void
1127
+ */
1128
+ function create_default_flow() {
1129
+
1130
+ check_ajax_referer( 'cf-default-flow', 'security' );
1131
+
1132
+ // Create post object.
1133
+ $new_flow_post = array(
1134
+ 'post_content' => '',
1135
+ 'post_status' => 'publish',
1136
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1137
+ );
1138
+
1139
+ // Insert the post into the database.
1140
+ $flow_id = wp_insert_post( $new_flow_post );
1141
+
1142
+ if ( is_wp_error( $flow_id ) ) {
1143
+ wp_send_json_error( $flow_id->get_error_message() );
1144
+ }
1145
+
1146
+ $flow_steps = array();
1147
+
1148
+ $steps_data = array(
1149
+ 'landing' => __( 'Landing Page', 'cartflows' ),
1150
+ 'checkout' => __( 'Checkout Page', 'cartflows' ),
1151
+ 'thankyou' => __( 'Thank You Page', 'cartflows' ),
1152
+ );
1153
+
1154
+ foreach ( $steps_data as $slug => $title ) {
1155
+
1156
+ $post_content = '';
1157
+
1158
+ switch ( $slug ) {
1159
+ case 'checkout':
1160
+ $post_content = '';
1161
+ break;
1162
+ case 'thankyou':
1163
+ $post_content = '';
1164
+ break;
1165
+ default:
1166
+ $post_content = '';
1167
+ break;
1168
+ }
1169
+
1170
+ $step_id = wp_insert_post(
1171
+ array(
1172
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1173
+ 'post_title' => $title,
1174
+ 'post_content' => $post_content,
1175
+ 'post_status' => 'publish',
1176
+ )
1177
+ );
1178
+
1179
+ if ( is_wp_error( $step_id ) ) {
1180
+ wp_send_json_error( $step_id->get_error_message() );
1181
+ }
1182
+
1183
+ if ( $step_id ) {
1184
+
1185
+ $flow_steps[] = array(
1186
+ 'id' => $step_id,
1187
+ 'title' => $title,
1188
+ 'type' => $slug,
1189
+ );
1190
+
1191
+ // insert post meta.
1192
+ update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1193
+ update_post_meta( $step_id, 'wcf-step-type', $slug );
1194
+
1195
+ wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1196
+ wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1197
+ }
1198
+ }
1199
+
1200
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1201
+
1202
+ wp_send_json_success( $flow_id );
1203
+ }
1204
+
1205
+ /**
1206
+ * Create Flow
1207
+ *
1208
+ * @return void
1209
+ */
1210
+ function create_flow() {
1211
+
1212
+ check_ajax_referer( 'cf-create-flow', 'security' );
1213
+
1214
+ // Create post object.
1215
+ $new_flow_post = array(
1216
+ 'post_content' => '',
1217
+ 'post_status' => 'publish',
1218
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1219
+ );
1220
+
1221
+ // Insert the post into the database.
1222
+ $flow_id = wp_insert_post( $new_flow_post );
1223
+
1224
+ if ( is_wp_error( $flow_id ) ) {
1225
+ wp_send_json_error( $flow_id->get_error_message() );
1226
+ }
1227
+
1228
+ /* Imported Flow */
1229
+ update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1230
+
1231
+ wp_send_json_success( $flow_id );
1232
+ }
1233
+
1234
+ /**
1235
+ * Create Step
1236
+ *
1237
+ * @return void
1238
+ */
1239
+ function import_step() {
1240
+
1241
+ check_ajax_referer( 'cf-step-import', 'security' );
1242
+
1243
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1244
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1245
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1246
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
1247
+ $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
1248
+
1249
+ $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1250
+
1251
+ $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1252
+
1253
+ wcf()->logger->import_log( '------------------------------------' );
1254
+ wcf()->logger->import_log( 'STARTED! Importing STEP' );
1255
+ wcf()->logger->import_log( '------------------------------------' );
1256
+
1257
+ if ( empty( $template_id ) || empty( $post_id ) ) {
1258
+ /* translators: %s: template ID */
1259
+ $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1260
+ wcf()->logger->import_log( $data );
1261
+ wp_send_json_error( $data );
1262
+ }
1263
+
1264
+ wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1265
+
1266
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1267
+
1268
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1269
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1270
+ update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1271
+
1272
+ wp_update_post(
1273
+ array(
1274
+ 'ID' => $post_id,
1275
+ 'post_content' => $response['data']['divi_content'],
1276
+ )
1277
+ );
1278
+ }
1279
+ }
1280
+
1281
+ /* Imported Step */
1282
+ update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1283
+
1284
+ // Import Post Meta.
1285
+ self::import_post_meta( $post_id, $response );
1286
+
1287
+ do_action( 'cartflows_import_complete' );
1288
+
1289
+ // Batch Process.
1290
+ do_action( 'cartflows_after_template_import', $post_id, $response );
1291
+
1292
+ wcf()->logger->import_log( '------------------------------------' );
1293
+ wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1294
+ wcf()->logger->import_log( '------------------------------------' );
1295
+
1296
+ wp_send_json_success( $post_id );
1297
+ }
1298
+
1299
+ /**
1300
+ * Import Step.
1301
+ *
1302
+ * @since 1.0.0
1303
+ * @hook wp_ajax_cartflows_step_create_blank
1304
+ *
1305
+ * @return void
1306
+ */
1307
+ function step_create_blank() {
1308
+
1309
+ check_ajax_referer( 'cf-step-create-blank', 'security' );
1310
+
1311
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1312
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
1313
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
1314
+
1315
+ if ( empty( $flow_id ) || empty( $step_type ) ) {
1316
+ /* translators: %s: flow ID */
1317
+ $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1318
+ wcf()->logger->import_log( $data );
1319
+ wp_send_json_error( $data );
1320
+ }
1321
+
1322
+ wcf()->logger->import_log( '------------------------------------' );
1323
+ wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1324
+
1325
+ $step_type_title = str_replace( '-', ' ', $step_type );
1326
+ $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1327
+
1328
+ $new_step_id = wp_insert_post(
1329
+ array(
1330
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1331
+ 'post_title' => $step_title,
1332
+ 'post_content' => '',
1333
+ 'post_status' => 'publish',
1334
+ )
1335
+ );
1336
+
1337
+ // insert post meta.
1338
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1339
+
1340
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1341
+ $term_exist = term_exists( $step_type_title, $taxonomy );
1342
+
1343
+ if ( empty( $term_exist ) ) {
1344
+ $terms = array(
1345
+ array(
1346
+ 'name' => $step_type_title,
1347
+ ),
1348
+ );
1349
+
1350
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1351
+ wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
1352
+ }
1353
+
1354
+ $current_term = term_exists( $step_type_title, $taxonomy );
1355
+
1356
+ // Set type object.
1357
+ $data = get_term( $current_term['term_id'], $taxonomy );
1358
+ $step_slug = $data->slug;
1359
+ wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1360
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1361
+
1362
+ // Set type.
1363
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1364
+ wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1365
+
1366
+ // Set flow.
1367
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1368
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1369
+
1370
+ CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1371
+
1372
+ wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1373
+ wcf()->logger->import_log( '------------------------------------' );
1374
+
1375
+ wp_send_json_success( $new_step_id );
1376
+ }
1377
+
1378
+ /**
1379
+ * Import Post Meta
1380
+ *
1381
+ * @since 1.0.0
1382
+ *
1383
+ * @param integer $post_id Post ID.
1384
+ * @param array $response Post meta.
1385
+ * @return void
1386
+ */
1387
+ public static function import_post_meta( $post_id, $response ) {
1388
+
1389
+ $metadata = (array) $response['post_meta'];
1390
+
1391
+ foreach ( $metadata as $meta_key => $meta_value ) {
1392
+ $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1393
+
1394
+ if ( $meta_value ) {
1395
+
1396
+ if ( is_serialized( $meta_value, true ) ) {
1397
+ $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1398
+ } elseif ( is_array( $meta_value ) ) {
1399
+ $raw_data = json_decode( stripslashes( $meta_value ), true );
1400
+ } else {
1401
+ $raw_data = $meta_value;
1402
+ }
1403
+
1404
+ if ( '_elementor_data' === $meta_key ) {
1405
+ if ( is_array( $raw_data ) ) {
1406
+ $raw_data = wp_slash( json_encode( $raw_data ) );
1407
+ } else {
1408
+ $raw_data = wp_slash( $raw_data );
1409
+ }
1410
+ }
1411
+ if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1412
+ if ( is_array( $raw_data ) ) {
1413
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
1414
+ } else {
1415
+ if ( ! is_object( $raw_data ) ) {
1416
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1417
+ }
1418
+ }
1419
+ }
1420
+
1421
+ update_post_meta( $post_id, $meta_key, $raw_data );
1422
+ }
1423
+ }
1424
+ }
1425
+
1426
+ /**
1427
+ * Import Template for Elementor
1428
+ *
1429
+ * @since 1.0.0
1430
+ *
1431
+ * @param integer $post_id Post ID.
1432
+ * @param array $response Post meta.
1433
+ * @param array $page_build_data Page build data.
1434
+ * @return void
1435
+ */
1436
+ public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1437
+ if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1438
+ $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1439
+ wcf()->logger->import_log( $data );
1440
+ wp_send_json_error( $data );
1441
+ }
1442
+
1443
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1444
+
1445
+ wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1446
+
1447
+ $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1448
+ $obj->import_single_template( $post_id );
1449
+
1450
+ wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1451
+ }
1452
+
1453
+ /**
1454
+ * Supported post types
1455
+ *
1456
+ * @since 1.0.0
1457
+ *
1458
+ * @return array Supported post types.
1459
+ */
1460
+ public static function supported_post_types() {
1461
+ return apply_filters(
1462
+ 'cartflows_supported_post_types',
1463
+ array(
1464
+ CARTFLOWS_FLOW_POST_TYPE,
1465
+ )
1466
+ );
1467
+ }
1468
+
1469
+ /**
1470
+ * Check supported post type
1471
+ *
1472
+ * @since 1.0.0
1473
+ *
1474
+ * @param string $post_type Post type.
1475
+ * @return boolean Supported post type status.
1476
+ */
1477
+ public static function is_supported_post( $post_type = '' ) {
1478
+ if ( in_array( $post_type, self::supported_post_types() ) ) {
1479
+ return true;
1480
+ }
1481
+
1482
+ return false;
1483
+ }
1484
+
1485
+ /**
1486
+ * Set steps to the flow
1487
+ *
1488
+ * @param integer $flow_id Flow ID.
1489
+ * @param integer $new_step_id New step ID.
1490
+ * @param string $step_title Flow Type.
1491
+ * @param string $step_slug Flow Type.
1492
+ */
1493
+ function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1494
+ // Update steps for the current flow.
1495
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1496
+
1497
+ if ( ! is_array( $flow_steps ) ) {
1498
+ $flow_steps = array();
1499
+ }
1500
+
1501
+ $flow_steps[] = array(
1502
+ 'id' => $new_step_id,
1503
+ 'title' => $step_title,
1504
+ 'type' => $step_slug,
1505
+ );
1506
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1507
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
1508
+ }
1509
+
1510
+ /**
1511
+ * Localize variables in admin
1512
+ *
1513
+ * @param array $vars variables.
1514
+ */
1515
+ function localize_vars( $vars ) {
1516
+
1517
+ $ajax_actions = array(
1518
+ 'cf_step_import',
1519
+ 'cf_load_steps',
1520
+ 'cf_create_flow',
1521
+ 'cf_default_flow',
1522
+ 'cf_step_create_blank',
1523
+ 'cf_import_flow_step',
1524
+ );
1525
+
1526
+ foreach ( $ajax_actions as $action ) {
1527
+
1528
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1529
+ }
1530
+
1531
+ return $vars;
1532
+ }
1533
+
1534
+ /**
1535
+ * Ajax action to activate plugin
1536
+ */
1537
+ public function activate_plugin() {
1538
+
1539
+ $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( $_POST['plugin_init'] ) : '';
1540
+
1541
+ $activate = activate_plugin( $plugin_init, '', false, true );
1542
+
1543
+ if ( is_wp_error( $activate ) ) {
1544
+ wp_send_json_error(
1545
+ array(
1546
+ 'success' => false,
1547
+ 'message' => $activate->get_error_message(),
1548
+ 'init' => $plugin_init,
1549
+ )
1550
+ );
1551
+ }
1552
+
1553
+ wp_send_json_success(
1554
+ array(
1555
+ 'success' => true,
1556
+ 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1557
+ 'init' => $plugin_init,
1558
+ )
1559
+ );
1560
+ }
1561
+
1562
+ }
1563
+
1564
+ /**
1565
+ * Initialize class object with 'get_instance()' method
1566
+ */
1567
+ CartFlows_Importer::get_instance();
1568
+
1569
+ endif;
classes/class-cartflows-loader.php CHANGED
@@ -115,7 +115,7 @@ if ( ! class_exists( 'Cartflows_Loader' ) ) {
115
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
116
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
117
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
118
- define( 'CARTFLOWS_VER', '1.1.8' );
119
  define( 'CARTFLOWS_SLUG', 'cartflows' );
120
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
121
 
115
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
116
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
117
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
118
+ define( 'CARTFLOWS_VER', '1.1.9' );
119
  define( 'CARTFLOWS_SLUG', 'cartflows' );
120
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
121
 
classes/class-cartflows-meta.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /**
3
- * CartFlows Meta
4
- *
5
- * @package CartFlows
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! class_exists( 'Cartflows_Meta' ) ) :
10
-
11
- /**
12
- * CartFlows_Meta
13
- *
14
- * @since 1.0.0
15
- */
16
- class Cartflows_Meta {
17
- /**
18
- * Constructor
19
- *
20
- * @since 1.0.0
21
- */
22
- public function __construct() {
23
- }
24
-
25
- /**
26
- * Flow & Step Actions
27
- *
28
- * @param array $options options.
29
- * @param int $post_id post ID.
30
- */
31
- function right_column_footer( $options, $post_id ) {
32
- ?>
33
- <div class="wcf-column-right-footer">
34
- <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'save', false ); ?>
35
-
36
- <?php
37
- $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
38
- if ( $flow_id ) {
39
- ?>
40
- <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button pull-right wcf-back-to-flow-edit">
41
- <i class="dashicons dashicons-arrow-left-alt"></i>
42
- <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
43
- </a>
44
- <?php } ?>
45
-
46
- </div>
47
- <?php
48
- }
49
-
50
- /**
51
- * Script Header (Used for add script into header)
52
- *
53
- * @param array $options options.
54
- * @param int $post_id post ID.
55
- */
56
- function tab_custom_script( $options, $post_id ) {
57
- ?>
58
- <div class="wcf-<?php echo wcf()->utils->get_step_type( $post_id ); ?>-custom-script-header wcf-tab-content widefat">
59
- <?php
60
- /* Script added onto the header */
61
- echo wcf()->meta->get_area_field(
62
- array(
63
- 'label' => __( 'Custom Script', 'cartflows' ),
64
- 'name' => 'wcf-custom-script',
65
- 'value' => htmlspecialchars( $options['wcf-custom-script'] ),
66
- 'help' => __( 'Custom script lets you add your own custom script on front end of this flow page.', 'cartflows' ),
67
- )
68
- );
69
- ?>
70
- </div>
71
- <?php
72
- }
73
- }
74
-
75
- endif;
1
+ <?php
2
+ /**
3
+ * CartFlows Meta
4
+ *
5
+ * @package CartFlows
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! class_exists( 'Cartflows_Meta' ) ) :
10
+
11
+ /**
12
+ * CartFlows_Meta
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Cartflows_Meta {
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @since 1.0.0
21
+ */
22
+ public function __construct() {
23
+ }
24
+
25
+ /**
26
+ * Flow & Step Actions
27
+ *
28
+ * @param array $options options.
29
+ * @param int $post_id post ID.
30
+ */
31
+ function right_column_footer( $options, $post_id ) {
32
+ ?>
33
+ <div class="wcf-column-right-footer">
34
+ <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'save', false ); ?>
35
+
36
+ <?php
37
+ $flow_id = get_post_meta( $post_id, 'wcf-flow-id', true );
38
+ if ( $flow_id ) {
39
+ ?>
40
+ <a href="<?php echo esc_url( get_edit_post_link( $flow_id ) ); ?>" class="button pull-right wcf-back-to-flow-edit">
41
+ <i class="dashicons dashicons-arrow-left-alt"></i>
42
+ <?php _e( 'Back to edit Flow', 'cartflows' ); ?>
43
+ </a>
44
+ <?php } ?>
45
+
46
+ </div>
47
+ <?php
48
+ }
49
+
50
+ /**
51
+ * Script Header (Used for add script into header)
52
+ *
53
+ * @param array $options options.
54
+ * @param int $post_id post ID.
55
+ */
56
+ function tab_custom_script( $options, $post_id ) {
57
+ ?>
58
+ <div class="wcf-<?php echo wcf()->utils->get_step_type( $post_id ); ?>-custom-script-header wcf-tab-content widefat">
59
+ <?php
60
+ /* Script added onto the header */
61
+ echo wcf()->meta->get_area_field(
62
+ array(
63
+ 'label' => __( 'Custom Script', 'cartflows' ),
64
+ 'name' => 'wcf-custom-script',
65
+ 'value' => htmlspecialchars( $options['wcf-custom-script'] ),
66
+ 'help' => __( 'Custom script lets you add your own custom script on front end of this flow page.', 'cartflows' ),
67
+ )
68
+ );
69
+ ?>
70
+ </div>
71
+ <?php
72
+ }
73
+ }
74
+
75
+ 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.8\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
- "POT-Creation-Date: 2019-02-27 12:39:28+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: CartFlows 1.1.9\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
+ "POT-Creation-Date: 2019-03-05 11:22:02+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
modules/checkout/classes/class-cartflows-checkout-markup.php CHANGED
@@ -1,1111 +1,1111 @@
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_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64
- add_action( 'wp_ajax_nopriv_cf_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
- }
72
-
73
- /**
74
- * Display all WooCommerce notices.
75
- *
76
- * @since 1.1.5
77
- */
78
- function display_woo_notices() {
79
-
80
- if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
81
- woocommerce_output_all_notices();
82
- }
83
- }
84
-
85
-
86
- /**
87
- * Redirect from default to the global checkout page
88
- *
89
- * @since 1.0.0
90
- */
91
- function global_checkout_template_redirect() {
92
-
93
- if ( ! is_checkout() ) {
94
- return;
95
- }
96
-
97
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
98
- return;
99
- }
100
-
101
- // redirect only from any non HC checkout pages.
102
- $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
103
- $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
104
-
105
- $common = Cartflows_Helper::get_common_settings();
106
-
107
- $global_checkout = $common['global_checkout'];
108
-
109
- if (
110
- // ignore on order-pay.
111
- false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
112
- // ignore on TY page.
113
- false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
114
- ) {
115
-
116
- if ( '' !== $global_checkout ) {
117
-
118
- $link = get_permalink( $global_checkout );
119
-
120
- if ( ! empty( $link ) ) {
121
-
122
- wp_redirect( $link );
123
- die();
124
- }
125
- }
126
- }
127
- }
128
-
129
- /**
130
- * Check for checkout flag
131
- *
132
- * @param bool $is_checkout is checkout.
133
- *
134
- * @return bool
135
- */
136
- function woo_checkout_flag( $is_checkout ) {
137
-
138
- if ( ! is_admin() ) {
139
-
140
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
141
-
142
- $is_checkout = true;
143
- }
144
- }
145
-
146
- return $is_checkout;
147
- }
148
-
149
- /**
150
- * Render checkout shortcode markup.
151
- *
152
- * @param array $atts attributes.
153
- * @return string
154
- */
155
- function checkout_shortcode_markup( $atts ) {
156
-
157
- if ( ! function_exists( 'wc_print_notices' ) ) {
158
- return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
159
- }
160
-
161
- $atts = shortcode_atts(
162
- array(
163
- 'id' => 0,
164
- ),
165
- $atts
166
- );
167
-
168
- $checkout_id = intval( $atts['id'] );
169
-
170
- if ( empty( $checkout_id ) ) {
171
-
172
- if ( ! _is_wcf_checkout_type() ) {
173
-
174
- return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
175
- }
176
-
177
- global $post;
178
-
179
- $checkout_id = intval( $post->ID );
180
- }
181
-
182
- $output = '';
183
-
184
- ob_start();
185
-
186
- do_action( 'cartflows_checkout_form_before', $checkout_id );
187
-
188
- $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
189
-
190
- $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
191
-
192
- $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
193
-
194
- if ( file_exists( $template_layout ) ) {
195
- include $template_layout;
196
- } else {
197
- include $template_default;
198
- }
199
-
200
- $output .= ob_get_clean();
201
-
202
- return $output;
203
- }
204
-
205
- /**
206
- * Configure Cart Data.
207
- *
208
- * @since 1.0.0
209
- *
210
- * @return void
211
- */
212
- function preconfigured_cart_data() {
213
-
214
- if ( is_admin() ) {
215
- return;
216
- }
217
-
218
- global $post;
219
-
220
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
221
-
222
- if ( wp_doing_ajax() ) {
223
-
224
- return;
225
- } else {
226
-
227
- if ( _is_wcf_checkout_type() ) {
228
- $checkout_id = $post->ID;
229
- } else {
230
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
231
- }
232
-
233
- do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
234
-
235
- $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
236
-
237
- if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
238
- $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
239
- } else {
240
- $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
241
- }
242
-
243
- if ( ! is_array( $products ) ) {
244
-
245
- if ( 'dummy' === $products ) {
246
-
247
- $args = array(
248
- 'posts_per_page' => 1,
249
- 'orderby' => 'rand',
250
- 'post_type' => 'product',
251
- 'meta_query' => array(
252
- // Exclude out of stock products.
253
- array(
254
- 'key' => '_stock_status',
255
- 'value' => 'outofstock',
256
- 'compare' => 'NOT IN',
257
- ),
258
- ),
259
- 'tax_query' => array(
260
- array(
261
- 'taxonomy' => 'product_type',
262
- 'field' => 'slug',
263
- 'terms' => 'simple',
264
- ),
265
- ),
266
- );
267
-
268
- $random_product = get_posts( $args );
269
-
270
- if ( isset( $random_product[0]->ID ) ) {
271
- $products = array(
272
- array(
273
- 'product' => $random_product[0]->ID,
274
- ),
275
- );
276
- } else {
277
- return;
278
- }
279
- } else {
280
- return;
281
- }
282
- }
283
-
284
- if ( is_array( $products ) && count( $products ) < 1 ) {
285
-
286
- return;
287
- }
288
- /* Empty the current cart */
289
- WC()->cart->empty_cart();
290
-
291
- /* Set customer session if not set */
292
- if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
293
- WC()->session->set_customer_session_cookie( true );
294
- }
295
-
296
- $cart_product_count = 0;
297
-
298
- foreach ( $products as $index => $data ) {
299
-
300
- if ( ! isset( $data['product'] ) ) {
301
- return;
302
- }
303
-
304
- if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
305
- break;
306
- }
307
-
308
- $product_id = $data['product'];
309
- $_product = wc_get_product( $product_id );
310
-
311
- if ( ! empty( $_product ) ) {
312
-
313
- $quantity = 1;
314
-
315
- if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
316
-
317
- if ( $_product->is_type( 'variable' ) ) {
318
-
319
- $default_attributes = $_product->get_default_attributes();
320
-
321
- if ( ! empty( $default_attributes ) ) {
322
-
323
- foreach ( $_product->get_children() as $variation_id ) {
324
-
325
- $single_variation = new WC_Product_Variation( $variation_id );
326
-
327
- if ( $default_attributes == $single_variation->get_attributes() ) {
328
- WC()->cart->add_to_cart( $variation_id, $quantity );
329
- $cart_product_count++;
330
- }
331
- }
332
- } else {
333
-
334
- $product_childrens = $_product->get_children();
335
-
336
- if ( isset( $product_childrens[0] ) ) {
337
- WC()->cart->add_to_cart( $product_childrens[0], $quantity );
338
- $cart_product_count++;
339
- } else {
340
- echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
341
- }
342
- }
343
- } else {
344
- WC()->cart->add_to_cart( $product_id, $quantity );
345
- $cart_product_count++;
346
- }
347
- } else {
348
-
349
- echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
350
- // WC()->cart->add_to_cart( $product_id, $quantity );.
351
- }
352
- }
353
- }
354
-
355
- do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
356
- do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
357
- }
358
- }
359
- }
360
-
361
- /**
362
- * Load shortcode data.
363
- *
364
- * @return void
365
- */
366
- function shortcode_load_data() {
367
-
368
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
369
-
370
- add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
371
-
372
- add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
373
-
374
- /* Show notices if cart has errors */
375
- add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
376
-
377
- add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
378
-
379
- add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
380
-
381
- // Outputting the hidden field in checkout page.
382
- add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
383
- add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
384
-
385
- remove_all_actions( 'woocommerce_checkout_billing' );
386
- remove_all_actions( 'woocommerce_checkout_shipping' );
387
-
388
- // Hook in actions once.
389
- add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
390
- add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
391
-
392
- remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
393
-
394
- add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
395
-
396
- add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
397
-
398
- global $post;
399
-
400
- if ( _is_wcf_checkout_type() ) {
401
- $checkout_id = $post->ID;
402
- } else {
403
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
404
- }
405
-
406
- do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
407
- }
408
- }
409
-
410
- /**
411
- * Render checkout ID hidden field.
412
- *
413
- * @param array $checkout checkout session data.
414
- * @return void
415
- */
416
- function checkout_shortcode_post_id( $checkout ) {
417
-
418
- global $post;
419
-
420
- if ( _is_wcf_checkout_type() ) {
421
- $checkout_id = $post->ID;
422
- } else {
423
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
424
- }
425
-
426
- $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
427
-
428
- echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
429
- echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
430
- }
431
-
432
- /**
433
- * Load shortcode scripts.
434
- *
435
- * @return void
436
- */
437
- function shortcode_scripts() {
438
-
439
- wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
440
- wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
441
-
442
- wp_enqueue_script(
443
- 'wcf-checkout-template',
444
- CARTFLOWS_URL . 'assets/js/checkout-template.js',
445
- array( 'jquery' ),
446
- CARTFLOWS_VER,
447
- true
448
- );
449
-
450
- do_action( 'cartflows_checkout_scripts' );
451
-
452
- $style = $this->generate_style();
453
-
454
- wp_add_inline_style( 'wcf-checkout-template', $style );
455
-
456
- }
457
-
458
- /**
459
- * Load compatibility scripts.
460
- *
461
- * @return void
462
- */
463
- function compatibility_scripts() {
464
-
465
- global $post;
466
-
467
- if ( _is_wcf_checkout_type() ) {
468
- $checkout_id = $post->ID;
469
- } else {
470
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
471
- }
472
-
473
- // Add DIVI Compatibility css if DIVI theme is enabled.
474
- if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
475
- Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
476
- ) {
477
- wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
478
- wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
479
- }
480
-
481
- // Add Flatsome Compatibility css if Flatsome theme is enabled.
482
- if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
483
- wp_enqueue_style( 'wcf-checkout-template-flatsome', CARTFLOWS_URL . 'assets/css/checkout-template-flatsome.css', '', CARTFLOWS_VER );
484
- wp_style_add_data( 'wcf-checkout-template-flatsome', 'rtl', 'replace' );
485
- }
486
-
487
- // Add The7 Compatibility css if The7 theme is enabled.
488
- if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
489
- wp_enqueue_style( 'wcf-checkout-template-the-seven', CARTFLOWS_URL . 'assets/css/checkout-template-the-seven.css', '', CARTFLOWS_VER );
490
- wp_style_add_data( 'wcf-checkout-template-the-seven', 'rtl', 'replace' );
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-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
-
774
- return $output;
775
- }
776
-
777
- /**
778
- * Get ajax end points.
779
- *
780
- * @param string $endpoint_url end point URL.
781
- * @return string
782
- */
783
- function get_ajax_endpoint( $endpoint_url ) {
784
-
785
- global $post;
786
-
787
- if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
788
-
789
- if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
790
-
791
- if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
792
-
793
- $query_args = array(
794
- 'wc-ajax' => '%%endpoint%%',
795
- );
796
-
797
- $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
798
- $uri = $uri[0];
799
-
800
- $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
801
- }
802
- }
803
- }
804
-
805
- return $endpoint_url;
806
- }
807
-
808
-
809
- /**
810
- * Save checkout fields.
811
- *
812
- * @param int $order_id order id.
813
- * @param array $posted posted data.
814
- * @return void
815
- */
816
- function save_checkout_fields( $order_id, $posted ) {
817
-
818
- if ( isset( $_POST['_wcf_checkout_id'] ) ) {
819
-
820
- $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
821
-
822
- update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
823
-
824
- /*
825
- Custom Field To Do
826
- $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
827
-
828
- if ( 'yes' === $custom_fields ) {
829
-
830
- $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
831
-
832
- foreach ( $billing_fields as $field => $data ) {
833
-
834
- if ( isset( $data['custom'] ) && $data['custom'] ) {
835
-
836
- if ( isset( $_POST[ $field ] ) ) {
837
- update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
838
- }
839
- }
840
- }
841
-
842
- $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
843
-
844
- foreach ( $shipping_fields as $field => $data ) {
845
-
846
- if ( isset( $data['custom'] ) && $data['custom'] ) {
847
-
848
- if ( isset( $_POST[ $field ] ) ) {
849
- update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
850
- }
851
- }
852
- }
853
- }
854
- */
855
- if ( isset( $_POST['_wcf_flow_id'] ) ) {
856
-
857
- $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
858
-
859
- update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
860
- }
861
- }
862
-
863
- }
864
-
865
- /**
866
- * Enable Logo In Header Of Checkout Page
867
- *
868
- * @return void
869
- */
870
- function enable_logo_in_header() {
871
- global $post;
872
-
873
- if ( _is_wcf_checkout_type() ) {
874
- $checkout_id = $post->ID;
875
- } else {
876
- $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
877
- }
878
-
879
- $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
880
- $add_image_markup = '';
881
-
882
- if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
883
- $add_image_markup = '<div class="wcf-checkout-header-image">';
884
- $add_image_markup .= '<img src="' . $header_logo_image . '" />';
885
- $add_image_markup .= '</div>';
886
- }
887
-
888
- echo $add_image_markup;
889
- }
890
-
891
- /**
892
- * Add text to the bootom of the checkout page.
893
- *
894
- * @return void
895
- */
896
- function show_cartflows_copyright_message() {
897
- $output_string = '';
898
-
899
- $output_string .= '<div class="wcf-footer-primary">';
900
- $output_string .= '<div class="wcf-footer-content">';
901
- $output_string .= '<p class="wcf-footer-message">';
902
- $output_string .= 'Checkout powered by CartFlows';
903
- $output_string .= '</p>';
904
- $output_string .= '</div>';
905
- $output_string .= '</div>';
906
-
907
- echo $output_string;
908
- }
909
-
910
- /**
911
- * Redirect users to our checkout if hidden param
912
- *
913
- * @param string $redirect redirect url.
914
- * @param object $user user.
915
- * @return string
916
- */
917
- function after_login_redirect( $redirect, $user ) {
918
-
919
- if ( isset( $_POST['_wcf_checkout_id'] ) ) {
920
-
921
- $checkout_id = intval( $_POST['_wcf_checkout_id'] );
922
-
923
- $redirect = get_permalink( $checkout_id );
924
- }
925
-
926
- return $redirect;
927
- }
928
-
929
- /**
930
- * Display coupon code field after review order fields.
931
- */
932
- function display_custom_coupon_field() {
933
-
934
- $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
935
- $cf_show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
936
-
937
- if ( ! ( $coupon_enabled && $cf_show_coupon ) ) {
938
- return;
939
-
940
- }
941
-
942
- ob_start();
943
- ?>
944
- <div class="wcf-custom-coupon-field">
945
- <div class="wcf-coupon-col-1">
946
- <span>
947
- <input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
948
- </span>
949
- </div>
950
- <div class="wcf-coupon-col-2">
951
- <span>
952
- <button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
953
- </span>
954
- </div>
955
- </div>
956
- <?php
957
- echo ob_get_clean();
958
- }
959
-
960
- /**
961
- * Apply filter to change the placeholder text of coupon field.
962
- *
963
- * @return string
964
- */
965
- function coupon_field_placeholder() {
966
- return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
967
- }
968
-
969
- /**
970
- * Apply filter to change the button text of coupon field.
971
- *
972
- * @return string
973
- */
974
- function coupon_button_text() {
975
- return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
976
- }
977
-
978
- /**
979
- * Apply coupon on submit of custom coupon form.
980
- */
981
- function apply_coupon() {
982
-
983
- check_ajax_referer( 'cf-apply-coupon', 'security' );
984
-
985
- $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
986
-
987
- echo json_encode( $result );
988
- die();
989
- }
990
-
991
- /**
992
- * Added ajax nonce to localize variable.
993
- *
994
- * @param array $vars localize variables.
995
- */
996
- function add_localize_vars( $vars ) {
997
-
998
- $vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
999
-
1000
- $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1001
-
1002
- return $vars;
1003
- }
1004
-
1005
- /**
1006
- * Add custom class to the fields to change the UI to three column.
1007
- *
1008
- * @param array $fields fields.
1009
- */
1010
- function add_three_column_layout_fields( $fields ) {
1011
-
1012
- if ( empty( $fields['billing']['billing_address_2'] ) ) {
1013
-
1014
- if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1015
- $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1016
- }
1017
- }
1018
-
1019
- if ( ! empty( $fields['billing']['billing_company'] ) ) {
1020
-
1021
- if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1022
- $fields['billing']['billing_company']['class'][] = 'form-row-full';
1023
- }
1024
- }
1025
-
1026
- if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1027
-
1028
- if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1029
- $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1030
- }
1031
- }
1032
-
1033
- if ( ! empty( $fields['billing']['billing_country'] ) ) {
1034
-
1035
- if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1036
- $fields['billing']['billing_country']['class'][] = 'form-row-full';
1037
- }
1038
- }
1039
-
1040
- if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1041
-
1042
- if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1043
- $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1044
- }
1045
- }
1046
-
1047
- if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1048
-
1049
- if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1050
- $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1051
- }
1052
- }
1053
-
1054
- if ( ! empty( $fields['billing']['billing_email'] ) ) {
1055
-
1056
- if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1057
- $fields['billing']['billing_email']['class'][] = 'form-row-full';
1058
- }
1059
- }
1060
-
1061
- if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1062
-
1063
- if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1064
- $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1065
- }
1066
- }
1067
-
1068
- if ( isset( $fields['billing']['billing_city'] ) &&
1069
- isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1070
-
1071
- $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1072
- $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1073
- $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1074
- }
1075
-
1076
- if ( isset( $fields['shipping']['shipping_city'] ) &&
1077
- isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1078
-
1079
- $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1080
- $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1081
- $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1082
- }
1083
-
1084
- return $fields;
1085
- }
1086
-
1087
- /**
1088
- * Add opening dev
1089
- *
1090
- * @since 1.0.0
1091
- */
1092
- function order_wrap_div_start() {
1093
-
1094
- echo "<div class='wcf-order-wrap'> ";
1095
- }
1096
-
1097
- /**
1098
- * Add closing dev
1099
- *
1100
- * @since 1.0.0
1101
- */
1102
- function order_wrap_div_end() {
1103
-
1104
- echo '</div> ';
1105
- }
1106
- }
1107
-
1108
- /**
1109
- * Kicking this off by calling 'get_instance()' method
1110
- */
1111
- 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_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64
+ add_action( 'wp_ajax_nopriv_cf_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
+ }
72
+
73
+ /**
74
+ * Display all WooCommerce notices.
75
+ *
76
+ * @since 1.1.5
77
+ */
78
+ function display_woo_notices() {
79
+
80
+ if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
81
+ woocommerce_output_all_notices();
82
+ }
83
+ }
84
+
85
+
86
+ /**
87
+ * Redirect from default to the global checkout page
88
+ *
89
+ * @since 1.0.0
90
+ */
91
+ function global_checkout_template_redirect() {
92
+
93
+ if ( ! is_checkout() ) {
94
+ return;
95
+ }
96
+
97
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
98
+ return;
99
+ }
100
+
101
+ // redirect only from any non HC checkout pages.
102
+ $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
103
+ $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
104
+
105
+ $common = Cartflows_Helper::get_common_settings();
106
+
107
+ $global_checkout = $common['global_checkout'];
108
+
109
+ if (
110
+ // ignore on order-pay.
111
+ false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
112
+ // ignore on TY page.
113
+ false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
114
+ ) {
115
+
116
+ if ( '' !== $global_checkout ) {
117
+
118
+ $link = get_permalink( $global_checkout );
119
+
120
+ if ( ! empty( $link ) ) {
121
+
122
+ wp_redirect( $link );
123
+ die();
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Check for checkout flag
131
+ *
132
+ * @param bool $is_checkout is checkout.
133
+ *
134
+ * @return bool
135
+ */
136
+ function woo_checkout_flag( $is_checkout ) {
137
+
138
+ if ( ! is_admin() ) {
139
+
140
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
141
+
142
+ $is_checkout = true;
143
+ }
144
+ }
145
+
146
+ return $is_checkout;
147
+ }
148
+
149
+ /**
150
+ * Render checkout shortcode markup.
151
+ *
152
+ * @param array $atts attributes.
153
+ * @return string
154
+ */
155
+ function checkout_shortcode_markup( $atts ) {
156
+
157
+ if ( ! function_exists( 'wc_print_notices' ) ) {
158
+ return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
159
+ }
160
+
161
+ $atts = shortcode_atts(
162
+ array(
163
+ 'id' => 0,
164
+ ),
165
+ $atts
166
+ );
167
+
168
+ $checkout_id = intval( $atts['id'] );
169
+
170
+ if ( empty( $checkout_id ) ) {
171
+
172
+ if ( ! _is_wcf_checkout_type() ) {
173
+
174
+ return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
175
+ }
176
+
177
+ global $post;
178
+
179
+ $checkout_id = intval( $post->ID );
180
+ }
181
+
182
+ $output = '';
183
+
184
+ ob_start();
185
+
186
+ do_action( 'cartflows_checkout_form_before', $checkout_id );
187
+
188
+ $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
189
+
190
+ $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
191
+
192
+ $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
193
+
194
+ if ( file_exists( $template_layout ) ) {
195
+ include $template_layout;
196
+ } else {
197
+ include $template_default;
198
+ }
199
+
200
+ $output .= ob_get_clean();
201
+
202
+ return $output;
203
+ }
204
+
205
+ /**
206
+ * Configure Cart Data.
207
+ *
208
+ * @since 1.0.0
209
+ *
210
+ * @return void
211
+ */
212
+ function preconfigured_cart_data() {
213
+
214
+ if ( is_admin() ) {
215
+ return;
216
+ }
217
+
218
+ global $post;
219
+
220
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
221
+
222
+ if ( wp_doing_ajax() ) {
223
+
224
+ return;
225
+ } else {
226
+
227
+ if ( _is_wcf_checkout_type() ) {
228
+ $checkout_id = $post->ID;
229
+ } else {
230
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
231
+ }
232
+
233
+ do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
234
+
235
+ $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
236
+
237
+ if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
238
+ $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
239
+ } else {
240
+ $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
241
+ }
242
+
243
+ if ( ! is_array( $products ) ) {
244
+
245
+ if ( 'dummy' === $products ) {
246
+
247
+ $args = array(
248
+ 'posts_per_page' => 1,
249
+ 'orderby' => 'rand',
250
+ 'post_type' => 'product',
251
+ 'meta_query' => array(
252
+ // Exclude out of stock products.
253
+ array(
254
+ 'key' => '_stock_status',
255
+ 'value' => 'outofstock',
256
+ 'compare' => 'NOT IN',
257
+ ),
258
+ ),
259
+ 'tax_query' => array(
260
+ array(
261
+ 'taxonomy' => 'product_type',
262
+ 'field' => 'slug',
263
+ 'terms' => 'simple',
264
+ ),
265
+ ),
266
+ );
267
+
268
+ $random_product = get_posts( $args );
269
+
270
+ if ( isset( $random_product[0]->ID ) ) {
271
+ $products = array(
272
+ array(
273
+ 'product' => $random_product[0]->ID,
274
+ ),
275
+ );
276
+ } else {
277
+ return;
278
+ }
279
+ } else {
280
+ return;
281
+ }
282
+ }
283
+
284
+ if ( is_array( $products ) && count( $products ) < 1 ) {
285
+
286
+ return;
287
+ }
288
+ /* Empty the current cart */
289
+ WC()->cart->empty_cart();
290
+
291
+ /* Set customer session if not set */
292
+ if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
293
+ WC()->session->set_customer_session_cookie( true );
294
+ }
295
+
296
+ $cart_product_count = 0;
297
+
298
+ foreach ( $products as $index => $data ) {
299
+
300
+ if ( ! isset( $data['product'] ) ) {
301
+ return;
302
+ }
303
+
304
+ if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
305
+ break;
306
+ }
307
+
308
+ $product_id = $data['product'];
309
+ $_product = wc_get_product( $product_id );
310
+
311
+ if ( ! empty( $_product ) ) {
312
+
313
+ $quantity = 1;
314
+
315
+ if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
316
+
317
+ if ( $_product->is_type( 'variable' ) ) {
318
+
319
+ $default_attributes = $_product->get_default_attributes();
320
+
321
+ if ( ! empty( $default_attributes ) ) {
322
+
323
+ foreach ( $_product->get_children() as $variation_id ) {
324
+
325
+ $single_variation = new WC_Product_Variation( $variation_id );
326
+
327
+ if ( $default_attributes == $single_variation->get_attributes() ) {
328
+ WC()->cart->add_to_cart( $variation_id, $quantity );
329
+ $cart_product_count++;
330
+ }
331
+ }
332
+ } else {
333
+
334
+ $product_childrens = $_product->get_children();
335
+
336
+ if ( isset( $product_childrens[0] ) ) {
337
+ WC()->cart->add_to_cart( $product_childrens[0], $quantity );
338
+ $cart_product_count++;
339
+ } else {
340
+ echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
341
+ }
342
+ }
343
+ } else {
344
+ WC()->cart->add_to_cart( $product_id, $quantity );
345
+ $cart_product_count++;
346
+ }
347
+ } else {
348
+
349
+ echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
350
+ // WC()->cart->add_to_cart( $product_id, $quantity );.
351
+ }
352
+ }
353
+ }
354
+
355
+ do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
356
+ do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
357
+ }
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Load shortcode data.
363
+ *
364
+ * @return void
365
+ */
366
+ function shortcode_load_data() {
367
+
368
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
369
+
370
+ add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
371
+
372
+ add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
373
+
374
+ /* Show notices if cart has errors */
375
+ add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
376
+
377
+ add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
378
+
379
+ add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
380
+
381
+ // Outputting the hidden field in checkout page.
382
+ add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
383
+ add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
384
+
385
+ remove_all_actions( 'woocommerce_checkout_billing' );
386
+ remove_all_actions( 'woocommerce_checkout_shipping' );
387
+
388
+ // Hook in actions once.
389
+ add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
390
+ add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
391
+
392
+ remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
393
+
394
+ add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
395
+
396
+ add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
397
+
398
+ global $post;
399
+
400
+ if ( _is_wcf_checkout_type() ) {
401
+ $checkout_id = $post->ID;
402
+ } else {
403
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
404
+ }
405
+
406
+ do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
407
+ }
408
+ }
409
+
410
+ /**
411
+ * Render checkout ID hidden field.
412
+ *
413
+ * @param array $checkout checkout session data.
414
+ * @return void
415
+ */
416
+ function checkout_shortcode_post_id( $checkout ) {
417
+
418
+ global $post;
419
+
420
+ if ( _is_wcf_checkout_type() ) {
421
+ $checkout_id = $post->ID;
422
+ } else {
423
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
424
+ }
425
+
426
+ $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
427
+
428
+ echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
429
+ echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
430
+ }
431
+
432
+ /**
433
+ * Load shortcode scripts.
434
+ *
435
+ * @return void
436
+ */
437
+ function shortcode_scripts() {
438
+
439
+ wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
440
+ wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
441
+
442
+ wp_enqueue_script(
443
+ 'wcf-checkout-template',
444
+ CARTFLOWS_URL . 'assets/js/checkout-template.js',
445
+ array( 'jquery' ),
446
+ CARTFLOWS_VER,
447
+ true
448
+ );
449
+
450
+ do_action( 'cartflows_checkout_scripts' );
451
+
452
+ $style = $this->generate_style();
453
+
454
+ wp_add_inline_style( 'wcf-checkout-template', $style );
455
+
456
+ }
457
+
458
+ /**
459
+ * Load compatibility scripts.
460
+ *
461
+ * @return void
462
+ */
463
+ function compatibility_scripts() {
464
+
465
+ global $post;
466
+
467
+ if ( _is_wcf_checkout_type() ) {
468
+ $checkout_id = $post->ID;
469
+ } else {
470
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
471
+ }
472
+
473
+ // Add DIVI Compatibility css if DIVI theme is enabled.
474
+ if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
475
+ Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
476
+ ) {
477
+ wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
478
+ wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
479
+ }
480
+
481
+ // Add Flatsome Compatibility css if Flatsome theme is enabled.
482
+ if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
483
+ wp_enqueue_style( 'wcf-checkout-template-flatsome', CARTFLOWS_URL . 'assets/css/checkout-template-flatsome.css', '', CARTFLOWS_VER );
484
+ wp_style_add_data( 'wcf-checkout-template-flatsome', 'rtl', 'replace' );
485
+ }
486
+
487
+ // Add The7 Compatibility css if The7 theme is enabled.
488
+ if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
489
+ wp_enqueue_style( 'wcf-checkout-template-the-seven', CARTFLOWS_URL . 'assets/css/checkout-template-the-seven.css', '', CARTFLOWS_VER );
490
+ wp_style_add_data( 'wcf-checkout-template-the-seven', 'rtl', 'replace' );
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-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
+
774
+ return $output;
775
+ }
776
+
777
+ /**
778
+ * Get ajax end points.
779
+ *
780
+ * @param string $endpoint_url end point URL.
781
+ * @return string
782
+ */
783
+ function get_ajax_endpoint( $endpoint_url ) {
784
+
785
+ global $post;
786
+
787
+ if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
788
+
789
+ if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
790
+
791
+ if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
792
+
793
+ $query_args = array(
794
+ 'wc-ajax' => '%%endpoint%%',
795
+ );
796
+
797
+ $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
798
+ $uri = $uri[0];
799
+
800
+ $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
801
+ }
802
+ }
803
+ }
804
+
805
+ return $endpoint_url;
806
+ }
807
+
808
+
809
+ /**
810
+ * Save checkout fields.
811
+ *
812
+ * @param int $order_id order id.
813
+ * @param array $posted posted data.
814
+ * @return void
815
+ */
816
+ function save_checkout_fields( $order_id, $posted ) {
817
+
818
+ if ( isset( $_POST['_wcf_checkout_id'] ) ) {
819
+
820
+ $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
821
+
822
+ update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
823
+
824
+ /*
825
+ Custom Field To Do
826
+ $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
827
+
828
+ if ( 'yes' === $custom_fields ) {
829
+
830
+ $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
831
+
832
+ foreach ( $billing_fields as $field => $data ) {
833
+
834
+ if ( isset( $data['custom'] ) && $data['custom'] ) {
835
+
836
+ if ( isset( $_POST[ $field ] ) ) {
837
+ update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
838
+ }
839
+ }
840
+ }
841
+
842
+ $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
843
+
844
+ foreach ( $shipping_fields as $field => $data ) {
845
+
846
+ if ( isset( $data['custom'] ) && $data['custom'] ) {
847
+
848
+ if ( isset( $_POST[ $field ] ) ) {
849
+ update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
850
+ }
851
+ }
852
+ }
853
+ }
854
+ */
855
+ if ( isset( $_POST['_wcf_flow_id'] ) ) {
856
+
857
+ $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
858
+
859
+ update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
860
+ }
861
+ }
862
+
863
+ }
864
+
865
+ /**
866
+ * Enable Logo In Header Of Checkout Page
867
+ *
868
+ * @return void
869
+ */
870
+ function enable_logo_in_header() {
871
+ global $post;
872
+
873
+ if ( _is_wcf_checkout_type() ) {
874
+ $checkout_id = $post->ID;
875
+ } else {
876
+ $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
877
+ }
878
+
879
+ $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
880
+ $add_image_markup = '';
881
+
882
+ if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
883
+ $add_image_markup = '<div class="wcf-checkout-header-image">';
884
+ $add_image_markup .= '<img src="' . $header_logo_image . '" />';
885
+ $add_image_markup .= '</div>';
886
+ }
887
+
888
+ echo $add_image_markup;
889
+ }
890
+
891
+ /**
892
+ * Add text to the bootom of the checkout page.
893
+ *
894
+ * @return void
895
+ */
896
+ function show_cartflows_copyright_message() {
897
+ $output_string = '';
898
+
899
+ $output_string .= '<div class="wcf-footer-primary">';
900
+ $output_string .= '<div class="wcf-footer-content">';
901
+ $output_string .= '<p class="wcf-footer-message">';
902
+ $output_string .= 'Checkout powered by CartFlows';
903
+ $output_string .= '</p>';
904
+ $output_string .= '</div>';
905
+ $output_string .= '</div>';
906
+
907
+ echo $output_string;
908
+ }
909
+
910
+ /**
911
+ * Redirect users to our checkout if hidden param
912
+ *
913
+ * @param string $redirect redirect url.
914
+ * @param object $user user.
915
+ * @return string
916
+ */
917
+ function after_login_redirect( $redirect, $user ) {
918
+
919
+ if ( isset( $_POST['_wcf_checkout_id'] ) ) {
920
+
921
+ $checkout_id = intval( $_POST['_wcf_checkout_id'] );
922
+
923
+ $redirect = get_permalink( $checkout_id );
924
+ }
925
+
926
+ return $redirect;
927
+ }
928
+
929
+ /**
930
+ * Display coupon code field after review order fields.
931
+ */
932
+ function display_custom_coupon_field() {
933
+
934
+ $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
935
+ $cf_show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
936
+
937
+ if ( ! ( $coupon_enabled && $cf_show_coupon ) ) {
938
+ return;
939
+
940
+ }
941
+
942
+ ob_start();
943
+ ?>
944
+ <div class="wcf-custom-coupon-field">
945
+ <div class="wcf-coupon-col-1">
946
+ <span>
947
+ <input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
948
+ </span>
949
+ </div>
950
+ <div class="wcf-coupon-col-2">
951
+ <span>
952
+ <button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
953
+ </span>
954
+ </div>
955
+ </div>
956
+ <?php
957
+ echo ob_get_clean();
958
+ }
959
+
960
+ /**
961
+ * Apply filter to change the placeholder text of coupon field.
962
+ *
963
+ * @return string
964
+ */
965
+ function coupon_field_placeholder() {
966
+ return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
967
+ }
968
+
969
+ /**
970
+ * Apply filter to change the button text of coupon field.
971
+ *
972
+ * @return string
973
+ */
974
+ function coupon_button_text() {
975
+ return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
976
+ }
977
+
978
+ /**
979
+ * Apply coupon on submit of custom coupon form.
980
+ */
981
+ function apply_coupon() {
982
+
983
+ check_ajax_referer( 'cf-apply-coupon', 'security' );
984
+
985
+ $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
986
+
987
+ echo json_encode( $result );
988
+ die();
989
+ }
990
+
991
+ /**
992
+ * Added ajax nonce to localize variable.
993
+ *
994
+ * @param array $vars localize variables.
995
+ */
996
+ function add_localize_vars( $vars ) {
997
+
998
+ $vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
999
+
1000
+ $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1001
+
1002
+ return $vars;
1003
+ }
1004
+
1005
+ /**
1006
+ * Add custom class to the fields to change the UI to three column.
1007
+ *
1008
+ * @param array $fields fields.
1009
+ */
1010
+ function add_three_column_layout_fields( $fields ) {
1011
+
1012
+ if ( empty( $fields['billing']['billing_address_2'] ) ) {
1013
+
1014
+ if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1015
+ $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1016
+ }
1017
+ }
1018
+
1019
+ if ( ! empty( $fields['billing']['billing_company'] ) ) {
1020
+
1021
+ if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1022
+ $fields['billing']['billing_company']['class'][] = 'form-row-full';
1023
+ }
1024
+ }
1025
+
1026
+ if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1027
+
1028
+ if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1029
+ $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1030
+ }
1031
+ }
1032
+
1033
+ if ( ! empty( $fields['billing']['billing_country'] ) ) {
1034
+
1035
+ if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1036
+ $fields['billing']['billing_country']['class'][] = 'form-row-full';
1037
+ }
1038
+ }
1039
+
1040
+ if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1041
+
1042
+ if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1043
+ $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1044
+ }
1045
+ }
1046
+
1047
+ if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1048
+
1049
+ if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1050
+ $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1051
+ }
1052
+ }
1053
+
1054
+ if ( ! empty( $fields['billing']['billing_email'] ) ) {
1055
+
1056
+ if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1057
+ $fields['billing']['billing_email']['class'][] = 'form-row-full';
1058
+ }
1059
+ }
1060
+
1061
+ if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1062
+
1063
+ if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1064
+ $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1065
+ }
1066
+ }
1067
+
1068
+ if ( isset( $fields['billing']['billing_city'] ) &&
1069
+ isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1070
+
1071
+ $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1072
+ $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1073
+ $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1074
+ }
1075
+
1076
+ if ( isset( $fields['shipping']['shipping_city'] ) &&
1077
+ isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1078
+
1079
+ $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1080
+ $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1081
+ $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1082
+ }
1083
+
1084
+ return $fields;
1085
+ }
1086
+
1087
+ /**
1088
+ * Add opening dev
1089
+ *
1090
+ * @since 1.0.0
1091
+ */
1092
+ function order_wrap_div_start() {
1093
+
1094
+ echo "<div class='wcf-order-wrap'> ";
1095
+ }
1096
+
1097
+ /**
1098
+ * Add closing dev
1099
+ *
1100
+ * @since 1.0.0
1101
+ */
1102
+ function order_wrap_div_end() {
1103
+
1104
+ echo '</div> ';
1105
+ }
1106
+ }
1107
+
1108
+ /**
1109
+ * Kicking this off by calling 'get_instance()' method
1110
+ */
1111
+ Cartflows_Checkout_Markup::get_instance();
modules/checkout/classes/class-cartflows-checkout-meta.php CHANGED
@@ -1,765 +1,765 @@
1
- <?php
2
- /**
3
- * Checkout post meta
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Checkout_Meta extends Cartflows_Meta {
12
-
13
- /**
14
- * Instance
15
- *
16
- * @var $instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Meta Option
22
- *
23
- * @var $meta_option
24
- */
25
- private static $meta_option = null;
26
-
27
- /**
28
- * Initiator
29
- */
30
- public static function get_instance() {
31
- if ( ! isset( self::$instance ) ) {
32
- self::$instance = new self;
33
- }
34
-
35
- return self::$instance;
36
- }
37
-
38
- /**
39
- * Constructor
40
- */
41
- public function __construct() {
42
-
43
- /* Init Metabox */
44
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
- }
47
-
48
- /**
49
- * Init Metabox
50
- */
51
- public function init_metabox() {
52
-
53
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
- }
56
-
57
- /**
58
- * Setup Metabox
59
- */
60
- function setup_meta_box() {
61
-
62
- // Get all posts.
63
- $post_types = get_post_types();
64
-
65
- if ( _is_wcf_checkout_type() ) {
66
- add_meta_box(
67
- 'wcf-checkout-settings', // Id.
68
- __( 'Checkout Layout', 'cartflows' ), // Title.
69
- array( $this, 'markup_meta_box' ), // Callback.
70
- wcf()->utils->get_step_post_type(), // Post_type.
71
- 'normal', // Context.
72
- 'high' // Priority.
73
- );
74
- }
75
- }
76
-
77
- /**
78
- * Metabox Markup
79
- *
80
- * @param object $post Post object.
81
- * @return void
82
- */
83
- function markup_meta_box( $post ) {
84
-
85
- wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
86
-
87
- $stored = get_post_meta( $post->ID );
88
-
89
- $checkout_meta = self::get_meta_option( $post->ID );
90
-
91
- // Set stored and override defaults.
92
- foreach ( $stored as $key => $value ) {
93
- if ( array_key_exists( $key, $checkout_meta ) ) {
94
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
95
- } else {
96
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
97
- }
98
- }
99
-
100
- // Get defaults.
101
- $meta = self::get_meta_option( $post->ID );
102
- $checkout_data = array();
103
-
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $checkout_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- /*
110
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
111
-
112
- foreach ( $billing_fields as $key => $value ) {
113
-
114
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
115
- }
116
-
117
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
118
-
119
- foreach ( $shipping_fields as $key => $value ) {
120
-
121
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
122
- }
123
-
124
- $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
125
-
126
- foreach ( $additional_fields as $key => $value ) {
127
-
128
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
129
- }
130
- */
131
-
132
- do_action( 'wcf_checkout_settings_markup_before' );
133
- $this->tabs_markup( $checkout_data, $post->ID );
134
- do_action( 'wcf_checkout_settings_markup_after' );
135
- }
136
-
137
- /**
138
- * Page Header Tabs
139
- *
140
- * @param array $options options.
141
- * @param int $post_id post ID.
142
- */
143
- function tabs_markup( $options, $post_id ) {
144
-
145
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
146
-
147
- if ( empty( $active_tab ) ) {
148
- $active_tab = 'wcf-checkout-shortcodes';
149
- }
150
-
151
- $tabs = array(
152
- array(
153
- 'title' => __( 'Shortcodes', 'cartflows' ),
154
- 'id' => 'wcf-checkout-shortcodes',
155
- 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
156
- 'icon' => 'dashicons-editor-code',
157
- ),
158
- array(
159
- 'title' => __( 'Select Product', 'cartflows' ),
160
- 'id' => 'wcf-checkout-general',
161
- 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
162
- 'icon' => 'dashicons-info',
163
- ),
164
- array(
165
- 'title' => __( 'Order Bump', 'cartflows' ),
166
- 'id' => 'wcf-product-order-bump',
167
- 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
168
- 'icon' => 'dashicons-cart',
169
- ),
170
- array(
171
- 'title' => __( 'Checkout Design', 'cartflows' ),
172
- 'id' => 'wcf-checkout-style',
173
- 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
174
- 'icon' => 'dashicons-admin-customizer',
175
- ),
176
- array(
177
- 'title' => __( 'Checkout Fields', 'cartflows' ),
178
- 'id' => 'wcf-checkout-custom-fields',
179
- 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
180
- 'icon' => 'dashicons-welcome-widgets-menus',
181
- ),
182
- array(
183
- 'title' => __( 'Logo ( Optional )', 'cartflows' ),
184
- 'id' => 'wcf-checkout-header',
185
- 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
186
- 'icon' => 'dashicons-format-image',
187
- ),
188
- array(
189
- 'title' => __( 'Custom Script', 'cartflows' ),
190
- 'id' => 'wcf-checkout-custom-script-header',
191
- 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
192
- 'icon' => 'dashicons-format-aside',
193
- ),
194
- );
195
-
196
- ?>
197
- <div class="wcf-checkout-table wcf-metabox-wrap widefat">
198
- <div class="wcf-table-container">
199
- <div class="wcf-column-left">
200
- <div class="wcf-tab-wrapper">
201
-
202
- <?php foreach ( $tabs as $key => $tab ) { ?>
203
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
204
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
205
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
206
- </div>
207
- <?php } ?>
208
-
209
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
210
- </div>
211
- </div>
212
- <div class="wcf-column-right">
213
- <?php $this->tab_shortcodes( $options, $post_id ); ?>
214
- <?php $this->tab_general( $options, $post_id ); ?>
215
- <?php $this->tab_style( $options, $post_id ); ?>
216
- <?php $this->tab_product_bump( $options, $post_id ); ?>
217
- <?php $this->tab_custom_fields( $options, $post_id ); ?>
218
- <?php $this->tab_header_content( $options, $post_id ); ?>
219
- <?php $this->tab_custom_script( $options, $post_id ); ?>
220
- <?php $this->right_column_footer( $options, $post_id ); ?>
221
- </div>
222
- </div>
223
- </div>
224
-
225
- <?php
226
- }
227
-
228
- /**
229
- * Shortcodes tab
230
- *
231
- * @param array $options options.
232
- * @param int $post_id post ID.
233
- */
234
- function tab_shortcodes( $options, $post_id ) {
235
- ?>
236
- <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
237
-
238
- <?php
239
-
240
- echo wcf()->meta->get_shortcode_field(
241
- array(
242
- 'label' => 'Checkout Page',
243
- 'name' => 'wcf-checkout-shortcode',
244
- 'content' => '[cartflows_checkout]',
245
- 'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
246
- )
247
- );
248
- ?>
249
- </div>
250
- <?php
251
- }
252
-
253
-
254
- /**
255
- * General tab
256
- *
257
- * @param array $options options.
258
- * @param int $post_id post ID.
259
- */
260
- function tab_general( $options, $post_id ) {
261
- ?>
262
- <div class="wcf-checkout-general wcf-tab-content widefat">
263
-
264
- <?php
265
-
266
- echo wcf()->meta->get_product_selection_repeater(
267
- array(
268
- 'name' => 'wcf-checkout-products',
269
- 'value' => $options['wcf-checkout-products'],
270
- 'allow_clear' => true,
271
- )
272
- );
273
-
274
- do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
275
-
276
- ?>
277
- </div>
278
- <?php
279
- }
280
-
281
- /**
282
- * Product bump tab
283
- *
284
- * @param array $options options.
285
- * @param int $post_id post ID.
286
- */
287
- function tab_product_bump( $options, $post_id ) {
288
- ?>
289
- <div class="wcf-product-order-bump wcf-tab-content widefat">
290
- <?php
291
- if ( ! _is_cartflows_pro() ) {
292
-
293
- echo wcf()->meta->get_description_field(
294
- array(
295
- 'name' => 'wcf-upgrade-to-pro',
296
- /* translators: %s: link */
297
- 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
298
- )
299
- );
300
- }
301
- ?>
302
-
303
- <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
304
- </div>
305
- <?php
306
- }
307
- /**
308
- * Tab custom fields
309
- *
310
- * @param array $options options.
311
- * @param int $post_id post ID.
312
- */
313
- function tab_custom_fields( $options, $post_id ) {
314
- ?>
315
- <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
316
- <?php
317
- /* Custom Checkout Fields Section */
318
-
319
- if ( ! _is_cartflows_pro() ) {
320
-
321
- echo wcf()->meta->get_description_field(
322
- array(
323
- 'name' => 'wcf-upgrade-to-pro',
324
- /* translators: %s: link */
325
- 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
326
- )
327
- );
328
- }
329
- ?>
330
- <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
331
- </div>
332
- <?php
333
- }
334
-
335
- /**
336
- * Tab style
337
- *
338
- * @param array $options options.
339
- * @param int $post_id post ID.
340
- */
341
- function tab_style( $options, $post_id ) {
342
- ?>
343
-
344
- <div class="wcf-checkout-style wcf-tab-content widefat">
345
- <div class="wcf-cs-fields">
346
- <div class="wcf-cs-checkbox-field">
347
- <?php
348
-
349
- $layout_pro_option = array();
350
-
351
- if ( ! _is_cartflows_pro() ) {
352
- $layout_pro_option = array(
353
- 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
354
- );
355
- }
356
-
357
- echo wcf()->meta->get_select_field(
358
- array(
359
- 'label' => __( 'Checkout Skin', 'cartflows' ),
360
- 'name' => 'wcf-checkout-layout',
361
- 'value' => $options['wcf-checkout-layout'],
362
- 'options' => array(
363
- 'one-column' => __( 'One Column', 'cartflows' ),
364
- 'two-column' => __( 'Two Column', 'cartflows' ),
365
- ),
366
- 'pro-options' => $layout_pro_option,
367
-
368
- )
369
- );
370
-
371
- echo wcf()->meta->get_color_picker_field(
372
- array(
373
- 'label' => __( 'Primary Color', 'cartflows' ),
374
- 'name' => 'wcf-primary-color',
375
- 'value' => $options['wcf-primary-color'],
376
- )
377
- );
378
-
379
- echo wcf()->meta->get_font_family_field(
380
- array(
381
- 'for' => 'wcf-base',
382
- 'label' => __( 'Font Family', 'cartflows' ),
383
- 'name' => 'wcf-base-font-family',
384
- 'value' => $options['wcf-base-font-family'],
385
- )
386
- );
387
-
388
- echo wcf()->meta->get_checkbox_field(
389
- array(
390
- 'label' => __( 'Advance Options', 'cartflows' ),
391
- 'name' => 'wcf-advance-options-fields',
392
- 'value' => $options['wcf-advance-options-fields'],
393
- 'after' => 'Enable',
394
- )
395
- );
396
- ?>
397
- </div>
398
- <div class="wcf-cs-fields-options">
399
- <?php
400
- echo wcf()->meta->get_section(
401
- array(
402
- 'label' => __( 'Heading', 'cartflows' ),
403
- )
404
- );
405
-
406
- echo wcf()->meta->get_color_picker_field(
407
- array(
408
- 'label' => __( 'Heading Color', 'cartflows' ),
409
- 'name' => 'wcf-heading-color',
410
- 'value' => $options['wcf-heading-color'],
411
- )
412
- );
413
-
414
- echo wcf()->meta->get_font_family_field(
415
- array(
416
- 'for' => 'wcf-heading',
417
- 'label' => __( 'Font Family', 'cartflows' ),
418
- 'name' => 'wcf-heading-font-family',
419
- 'value' => $options['wcf-heading-font-family'],
420
- )
421
- );
422
-
423
- echo wcf()->meta->get_font_weight_field(
424
- array(
425
- 'for' => 'wcf-heading',
426
- 'label' => __( 'Font Weight', 'cartflows' ),
427
- 'name' => 'wcf-heading-font-weight',
428
- 'value' => $options['wcf-heading-font-weight'],
429
- )
430
- );
431
-
432
- echo wcf()->meta->get_section(
433
- array(
434
- 'label' => __( 'Input Fields', 'cartflows' ),
435
- )
436
- );
437
-
438
- $fields_skin_pro_option = array();
439
-
440
- if ( ! _is_cartflows_pro() ) {
441
- $fields_skin_pro_option = array(
442
- 'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
443
- );
444
- }
445
-
446
- echo wcf()->meta->get_select_field(
447
- array(
448
- 'label' => __( 'Style', 'cartflows' ),
449
- 'name' => 'wcf-fields-skins',
450
- 'value' => $options['wcf-fields-skins'],
451
- 'options' => array(
452
- 'default' => __( 'Default', 'cartflows' ),
453
- 'style-one' => __( 'Floating Labels', 'cartflows' ),
454
- ),
455
- 'pro-options' => $fields_skin_pro_option,
456
-
457
- )
458
- );
459
-
460
- echo wcf()->meta->get_font_family_field(
461
- array(
462
- 'for' => 'wcf-input',
463
- 'label' => __( 'Font Family', 'cartflows' ),
464
- 'name' => 'wcf-input-font-family',
465
- 'value' => $options['wcf-input-font-family'],
466
- )
467
- );
468
-
469
- echo wcf()->meta->get_font_weight_field(
470
- array(
471
- 'for' => 'wcf-input',
472
- 'label' => __( 'Font Weight', 'cartflows' ),
473
- 'name' => 'wcf-input-font-weight',
474
- 'value' => $options['wcf-input-font-weight'],
475
- )
476
- );
477
-
478
- echo wcf()->meta->get_select_field(
479
- array(
480
- 'label' => __( 'Size', 'cartflows' ),
481
- 'name' => 'wcf-input-field-size',
482
- 'value' => $options['wcf-input-field-size'],
483
- 'options' => array(
484
- '33px' => __( 'Extra Small', 'cartflows' ),
485
- '38px' => __( 'Small', 'cartflows' ),
486
- '44px' => __( 'Medium', 'cartflows' ),
487
- '58px' => __( 'Large', 'cartflows' ),
488
- '68px' => __( 'Extra Large', 'cartflows' ),
489
- 'custom' => __( 'Custom', 'cartflows' ),
490
- ),
491
- )
492
- );
493
-
494
- echo wcf()->meta->get_number_field(
495
- array(
496
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
497
- 'name' => 'wcf-field-tb-padding',
498
- 'value' => $options['wcf-field-tb-padding'],
499
- )
500
- );
501
-
502
- echo wcf()->meta->get_number_field(
503
- array(
504
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
505
- 'name' => 'wcf-field-lr-padding',
506
- 'value' => $options['wcf-field-lr-padding'],
507
- )
508
- );
509
-
510
- echo wcf()->meta->get_color_picker_field(
511
- array(
512
- 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
513
- 'name' => 'wcf-field-color',
514
- 'value' => $options['wcf-field-color'],
515
- )
516
- );
517
-
518
- echo wcf()->meta->get_color_picker_field(
519
- array(
520
- 'label' => __( 'Background Color', 'cartflows' ),
521
- 'name' => 'wcf-field-bg-color',
522
- 'value' => $options['wcf-field-bg-color'],
523
- )
524
- );
525
-
526
- echo wcf()->meta->get_color_picker_field(
527
- array(
528
- 'label' => __( 'Border Color', 'cartflows' ),
529
- 'name' => 'wcf-field-border-color',
530
- 'value' => $options['wcf-field-border-color'],
531
- )
532
- );
533
- echo wcf()->meta->get_color_picker_field(
534
- array(
535
- 'label' => __( 'Label Color', 'cartflows' ),
536
- 'name' => 'wcf-field-label-color',
537
- 'value' => $options['wcf-field-label-color'],
538
- )
539
- );
540
-
541
- ?>
542
- </div>
543
- <div class="wcf-cs-button-options">
544
- <?php
545
-
546
- echo wcf()->meta->get_section(
547
- array(
548
- 'label' => __( 'Buttons', 'cartflows' ),
549
- )
550
- );
551
-
552
- echo wcf()->meta->get_font_family_field(
553
- array(
554
- 'for' => 'wcf-button',
555
- 'label' => __( 'Font Family', 'cartflows' ),
556
- 'name' => 'wcf-button-font-family',
557
- 'value' => $options['wcf-button-font-family'],
558
- )
559
- );
560
-
561
- echo wcf()->meta->get_font_weight_field(
562
- array(
563
- 'for' => 'wcf-button',
564
- 'label' => __( 'Font Weight', 'cartflows' ),
565
- 'name' => 'wcf-button-font-weight',
566
- 'value' => $options['wcf-button-font-weight'],
567
- )
568
- );
569
-
570
- echo wcf()->meta->get_select_field(
571
- array(
572
- 'label' => __( 'Size', 'cartflows' ),
573
- 'name' => 'wcf-input-button-size',
574
- 'value' => $options['wcf-input-button-size'],
575
- 'options' => array(
576
- '33px' => __( 'Extra Small', 'cartflows' ),
577
- '38px' => __( 'Small', 'cartflows' ),
578
- '44px' => __( 'Medium', 'cartflows' ),
579
- '58px' => __( 'Large', 'cartflows' ),
580
- '68px' => __( 'Extra Large', 'cartflows' ),
581
- 'custom' => __( 'Custom', 'cartflows' ),
582
- ),
583
- )
584
- );
585
-
586
- echo wcf()->meta->get_number_field(
587
- array(
588
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
589
- 'name' => 'wcf-submit-tb-padding',
590
- 'value' => $options['wcf-submit-tb-padding'],
591
- )
592
- );
593
-
594
- echo wcf()->meta->get_number_field(
595
- array(
596
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
597
- 'name' => 'wcf-submit-lr-padding',
598
- 'value' => $options['wcf-submit-lr-padding'],
599
- )
600
- );
601
-
602
- echo wcf()->meta->get_color_picker_field(
603
- array(
604
- 'label' => __( 'Text Color', 'cartflows' ),
605
- 'name' => 'wcf-submit-color',
606
- 'value' => $options['wcf-submit-color'],
607
- )
608
- );
609
-
610
- echo wcf()->meta->get_color_picker_field(
611
- array(
612
- 'label' => __( 'Text Hover Color', 'cartflows' ),
613
- 'name' => 'wcf-submit-hover-color',
614
- 'value' => $options['wcf-submit-hover-color'],
615
- )
616
- );
617
-
618
- echo wcf()->meta->get_color_picker_field(
619
- array(
620
- 'label' => __( 'Background Color', 'cartflows' ),
621
- 'name' => 'wcf-submit-bg-color',
622
- 'value' => $options['wcf-submit-bg-color'],
623
- )
624
- );
625
-
626
- echo wcf()->meta->get_color_picker_field(
627
- array(
628
- 'label' => __( 'Background Hover Color', 'cartflows' ),
629
- 'name' => 'wcf-submit-bg-hover-color',
630
- 'value' => $options['wcf-submit-bg-hover-color'],
631
- )
632
- );
633
-
634
- echo wcf()->meta->get_color_picker_field(
635
- array(
636
- 'label' => __( 'Border Color', 'cartflows' ),
637
- 'name' => 'wcf-submit-border-color',
638
- 'value' => $options['wcf-submit-border-color'],
639
- )
640
- );
641
-
642
- echo wcf()->meta->get_color_picker_field(
643
- array(
644
- 'label' => __( 'Border Hover Color', 'cartflows' ),
645
- 'name' => 'wcf-submit-border-hover-color',
646
- 'value' => $options['wcf-submit-border-hover-color'],
647
- )
648
- );
649
-
650
- ?>
651
- </div>
652
- <div class="wcf-cs-section-options">
653
- <?php
654
-
655
- echo wcf()->meta->get_section(
656
- array(
657
- 'label' => __( 'Sections', 'cartflows' ),
658
- )
659
- );
660
-
661
- echo wcf()->meta->get_color_picker_field(
662
- array(
663
- 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
664
- 'name' => 'wcf-hl-bg-color',
665
- 'value' => $options['wcf-hl-bg-color'],
666
- )
667
- );
668
-
669
- echo wcf()->meta->get_hidden_field(
670
- array(
671
- 'name' => 'wcf-field-google-font-url',
672
- 'value' => $options['wcf-field-google-font-url'],
673
- )
674
- );
675
- ?>
676
- </div>
677
- <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
678
- </div>
679
- </div>
680
- <?php
681
- }
682
-
683
-
684
- /**
685
- * Tab Header (Used for add logo into header)
686
- *
687
- * @param array $options options.
688
- * @param int $post_id post ID.
689
- */
690
- function tab_header_content( $options, $post_id ) {
691
- ?>
692
-
693
- <div class="wcf-checkout-header wcf-tab-content widefat">
694
- <?php
695
-
696
- $layout_pro_option = array();
697
-
698
- echo wcf()->meta->get_image_field(
699
- array(
700
- 'name' => 'wcf-header-logo-image',
701
- 'value' => $options['wcf-header-logo-image'],
702
- 'label' => __( 'Header Logo', 'cartflows' ),
703
- )
704
- );
705
-
706
- echo wcf()->meta->get_number_field(
707
- array(
708
- 'name' => 'wcf-header-logo-width',
709
- 'value' => $options['wcf-header-logo-width'],
710
- 'label' => __( 'Logo Width (In px)', 'cartflows' ),
711
- )
712
- );
713
- ?>
714
- <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
715
- </div>
716
- <?php
717
- }
718
- /**
719
- * Get metabox options
720
- *
721
- * @param int $post_id post ID.
722
- */
723
- public static function get_meta_option( $post_id ) {
724
-
725
- if ( null === self::$meta_option ) {
726
-
727
- /**
728
- * Set metabox options
729
- *
730
- * @see http://php.net/manual/en/filter.filters.sanitize.php
731
- */
732
- self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
733
- }
734
-
735
- return self::$meta_option;
736
- }
737
-
738
- /**
739
- * Metabox Save
740
- *
741
- * @param number $post_id Post ID.
742
- * @return void
743
- */
744
- function save_meta_box( $post_id ) {
745
-
746
- // Checks save status.
747
- $is_autosave = wp_is_post_autosave( $post_id );
748
- $is_revision = wp_is_post_revision( $post_id );
749
-
750
- $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
751
-
752
- // Exits script depending on save status.
753
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
754
- return;
755
- }
756
-
757
- wcf()->options->save_checkout_fields( $post_id );
758
- }
759
-
760
- }
761
-
762
- /**
763
- * Kicking this off by calling 'get_instance()' method
764
- */
765
- Cartflows_Checkout_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Checkout post meta
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Checkout_Meta extends Cartflows_Meta {
12
+
13
+ /**
14
+ * Instance
15
+ *
16
+ * @var $instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Meta Option
22
+ *
23
+ * @var $meta_option
24
+ */
25
+ private static $meta_option = null;
26
+
27
+ /**
28
+ * Initiator
29
+ */
30
+ public static function get_instance() {
31
+ if ( ! isset( self::$instance ) ) {
32
+ self::$instance = new self;
33
+ }
34
+
35
+ return self::$instance;
36
+ }
37
+
38
+ /**
39
+ * Constructor
40
+ */
41
+ public function __construct() {
42
+
43
+ /* Init Metabox */
44
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
+ }
47
+
48
+ /**
49
+ * Init Metabox
50
+ */
51
+ public function init_metabox() {
52
+
53
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
+ }
56
+
57
+ /**
58
+ * Setup Metabox
59
+ */
60
+ function setup_meta_box() {
61
+
62
+ // Get all posts.
63
+ $post_types = get_post_types();
64
+
65
+ if ( _is_wcf_checkout_type() ) {
66
+ add_meta_box(
67
+ 'wcf-checkout-settings', // Id.
68
+ __( 'Checkout Layout', 'cartflows' ), // Title.
69
+ array( $this, 'markup_meta_box' ), // Callback.
70
+ wcf()->utils->get_step_post_type(), // Post_type.
71
+ 'normal', // Context.
72
+ 'high' // Priority.
73
+ );
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Metabox Markup
79
+ *
80
+ * @param object $post Post object.
81
+ * @return void
82
+ */
83
+ function markup_meta_box( $post ) {
84
+
85
+ wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
86
+
87
+ $stored = get_post_meta( $post->ID );
88
+
89
+ $checkout_meta = self::get_meta_option( $post->ID );
90
+
91
+ // Set stored and override defaults.
92
+ foreach ( $stored as $key => $value ) {
93
+ if ( array_key_exists( $key, $checkout_meta ) ) {
94
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
95
+ } else {
96
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
97
+ }
98
+ }
99
+
100
+ // Get defaults.
101
+ $meta = self::get_meta_option( $post->ID );
102
+ $checkout_data = array();
103
+
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $checkout_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ /*
110
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
111
+
112
+ foreach ( $billing_fields as $key => $value ) {
113
+
114
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
115
+ }
116
+
117
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
118
+
119
+ foreach ( $shipping_fields as $key => $value ) {
120
+
121
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
122
+ }
123
+
124
+ $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
125
+
126
+ foreach ( $additional_fields as $key => $value ) {
127
+
128
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
129
+ }
130
+ */
131
+
132
+ do_action( 'wcf_checkout_settings_markup_before' );
133
+ $this->tabs_markup( $checkout_data, $post->ID );
134
+ do_action( 'wcf_checkout_settings_markup_after' );
135
+ }
136
+
137
+ /**
138
+ * Page Header Tabs
139
+ *
140
+ * @param array $options options.
141
+ * @param int $post_id post ID.
142
+ */
143
+ function tabs_markup( $options, $post_id ) {
144
+
145
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
146
+
147
+ if ( empty( $active_tab ) ) {
148
+ $active_tab = 'wcf-checkout-shortcodes';
149
+ }
150
+
151
+ $tabs = array(
152
+ array(
153
+ 'title' => __( 'Shortcodes', 'cartflows' ),
154
+ 'id' => 'wcf-checkout-shortcodes',
155
+ 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
156
+ 'icon' => 'dashicons-editor-code',
157
+ ),
158
+ array(
159
+ 'title' => __( 'Select Product', 'cartflows' ),
160
+ 'id' => 'wcf-checkout-general',
161
+ 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
162
+ 'icon' => 'dashicons-info',
163
+ ),
164
+ array(
165
+ 'title' => __( 'Order Bump', 'cartflows' ),
166
+ 'id' => 'wcf-product-order-bump',
167
+ 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
168
+ 'icon' => 'dashicons-cart',
169
+ ),
170
+ array(
171
+ 'title' => __( 'Checkout Design', 'cartflows' ),
172
+ 'id' => 'wcf-checkout-style',
173
+ 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
174
+ 'icon' => 'dashicons-admin-customizer',
175
+ ),
176
+ array(
177
+ 'title' => __( 'Checkout Fields', 'cartflows' ),
178
+ 'id' => 'wcf-checkout-custom-fields',
179
+ 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
180
+ 'icon' => 'dashicons-welcome-widgets-menus',
181
+ ),
182
+ array(
183
+ 'title' => __( 'Logo ( Optional )', 'cartflows' ),
184
+ 'id' => 'wcf-checkout-header',
185
+ 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
186
+ 'icon' => 'dashicons-format-image',
187
+ ),
188
+ array(
189
+ 'title' => __( 'Custom Script', 'cartflows' ),
190
+ 'id' => 'wcf-checkout-custom-script-header',
191
+ 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
192
+ 'icon' => 'dashicons-format-aside',
193
+ ),
194
+ );
195
+
196
+ ?>
197
+ <div class="wcf-checkout-table wcf-metabox-wrap widefat">
198
+ <div class="wcf-table-container">
199
+ <div class="wcf-column-left">
200
+ <div class="wcf-tab-wrapper">
201
+
202
+ <?php foreach ( $tabs as $key => $tab ) { ?>
203
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
204
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
205
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
206
+ </div>
207
+ <?php } ?>
208
+
209
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
210
+ </div>
211
+ </div>
212
+ <div class="wcf-column-right">
213
+ <?php $this->tab_shortcodes( $options, $post_id ); ?>
214
+ <?php $this->tab_general( $options, $post_id ); ?>
215
+ <?php $this->tab_style( $options, $post_id ); ?>
216
+ <?php $this->tab_product_bump( $options, $post_id ); ?>
217
+ <?php $this->tab_custom_fields( $options, $post_id ); ?>
218
+ <?php $this->tab_header_content( $options, $post_id ); ?>
219
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
220
+ <?php $this->right_column_footer( $options, $post_id ); ?>
221
+ </div>
222
+ </div>
223
+ </div>
224
+
225
+ <?php
226
+ }
227
+
228
+ /**
229
+ * Shortcodes tab
230
+ *
231
+ * @param array $options options.
232
+ * @param int $post_id post ID.
233
+ */
234
+ function tab_shortcodes( $options, $post_id ) {
235
+ ?>
236
+ <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
237
+
238
+ <?php
239
+
240
+ echo wcf()->meta->get_shortcode_field(
241
+ array(
242
+ 'label' => 'Checkout Page',
243
+ 'name' => 'wcf-checkout-shortcode',
244
+ 'content' => '[cartflows_checkout]',
245
+ 'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
246
+ )
247
+ );
248
+ ?>
249
+ </div>
250
+ <?php
251
+ }
252
+
253
+
254
+ /**
255
+ * General tab
256
+ *
257
+ * @param array $options options.
258
+ * @param int $post_id post ID.
259
+ */
260
+ function tab_general( $options, $post_id ) {
261
+ ?>
262
+ <div class="wcf-checkout-general wcf-tab-content widefat">
263
+
264
+ <?php
265
+
266
+ echo wcf()->meta->get_product_selection_repeater(
267
+ array(
268
+ 'name' => 'wcf-checkout-products',
269
+ 'value' => $options['wcf-checkout-products'],
270
+ 'allow_clear' => true,
271
+ )
272
+ );
273
+
274
+ do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
275
+
276
+ ?>
277
+ </div>
278
+ <?php
279
+ }
280
+
281
+ /**
282
+ * Product bump tab
283
+ *
284
+ * @param array $options options.
285
+ * @param int $post_id post ID.
286
+ */
287
+ function tab_product_bump( $options, $post_id ) {
288
+ ?>
289
+ <div class="wcf-product-order-bump wcf-tab-content widefat">
290
+ <?php
291
+ if ( ! _is_cartflows_pro() ) {
292
+
293
+ echo wcf()->meta->get_description_field(
294
+ array(
295
+ 'name' => 'wcf-upgrade-to-pro',
296
+ /* translators: %s: link */
297
+ 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
298
+ )
299
+ );
300
+ }
301
+ ?>
302
+
303
+ <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
304
+ </div>
305
+ <?php
306
+ }
307
+ /**
308
+ * Tab custom fields
309
+ *
310
+ * @param array $options options.
311
+ * @param int $post_id post ID.
312
+ */
313
+ function tab_custom_fields( $options, $post_id ) {
314
+ ?>
315
+ <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
316
+ <?php
317
+ /* Custom Checkout Fields Section */
318
+
319
+ if ( ! _is_cartflows_pro() ) {
320
+
321
+ echo wcf()->meta->get_description_field(
322
+ array(
323
+ 'name' => 'wcf-upgrade-to-pro',
324
+ /* translators: %s: link */
325
+ 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
326
+ )
327
+ );
328
+ }
329
+ ?>
330
+ <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
331
+ </div>
332
+ <?php
333
+ }
334
+
335
+ /**
336
+ * Tab style
337
+ *
338
+ * @param array $options options.
339
+ * @param int $post_id post ID.
340
+ */
341
+ function tab_style( $options, $post_id ) {
342
+ ?>
343
+
344
+ <div class="wcf-checkout-style wcf-tab-content widefat">
345
+ <div class="wcf-cs-fields">
346
+ <div class="wcf-cs-checkbox-field">
347
+ <?php
348
+
349
+ $layout_pro_option = array();
350
+
351
+ if ( ! _is_cartflows_pro() ) {
352
+ $layout_pro_option = array(
353
+ 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
354
+ );
355
+ }
356
+
357
+ echo wcf()->meta->get_select_field(
358
+ array(
359
+ 'label' => __( 'Checkout Skin', 'cartflows' ),
360
+ 'name' => 'wcf-checkout-layout',
361
+ 'value' => $options['wcf-checkout-layout'],
362
+ 'options' => array(
363
+ 'one-column' => __( 'One Column', 'cartflows' ),
364
+ 'two-column' => __( 'Two Column', 'cartflows' ),
365
+ ),
366
+ 'pro-options' => $layout_pro_option,
367
+
368
+ )
369
+ );
370
+
371
+ echo wcf()->meta->get_color_picker_field(
372
+ array(
373
+ 'label' => __( 'Primary Color', 'cartflows' ),
374
+ 'name' => 'wcf-primary-color',
375
+ 'value' => $options['wcf-primary-color'],
376
+ )
377
+ );
378
+
379
+ echo wcf()->meta->get_font_family_field(
380
+ array(
381
+ 'for' => 'wcf-base',
382
+ 'label' => __( 'Font Family', 'cartflows' ),
383
+ 'name' => 'wcf-base-font-family',
384
+ 'value' => $options['wcf-base-font-family'],
385
+ )
386
+ );
387
+
388
+ echo wcf()->meta->get_checkbox_field(
389
+ array(
390
+ 'label' => __( 'Advance Options', 'cartflows' ),
391
+ 'name' => 'wcf-advance-options-fields',
392
+ 'value' => $options['wcf-advance-options-fields'],
393
+ 'after' => 'Enable',
394
+ )
395
+ );
396
+ ?>
397
+ </div>
398
+ <div class="wcf-cs-fields-options">
399
+ <?php
400
+ echo wcf()->meta->get_section(
401
+ array(
402
+ 'label' => __( 'Heading', 'cartflows' ),
403
+ )
404
+ );
405
+
406
+ echo wcf()->meta->get_color_picker_field(
407
+ array(
408
+ 'label' => __( 'Heading Color', 'cartflows' ),
409
+ 'name' => 'wcf-heading-color',
410
+ 'value' => $options['wcf-heading-color'],
411
+ )
412
+ );
413
+
414
+ echo wcf()->meta->get_font_family_field(
415
+ array(
416
+ 'for' => 'wcf-heading',
417
+ 'label' => __( 'Font Family', 'cartflows' ),
418
+ 'name' => 'wcf-heading-font-family',
419
+ 'value' => $options['wcf-heading-font-family'],
420
+ )
421
+ );
422
+
423
+ echo wcf()->meta->get_font_weight_field(
424
+ array(
425
+ 'for' => 'wcf-heading',
426
+ 'label' => __( 'Font Weight', 'cartflows' ),
427
+ 'name' => 'wcf-heading-font-weight',
428
+ 'value' => $options['wcf-heading-font-weight'],
429
+ )
430
+ );
431
+
432
+ echo wcf()->meta->get_section(
433
+ array(
434
+ 'label' => __( 'Input Fields', 'cartflows' ),
435
+ )
436
+ );
437
+
438
+ $fields_skin_pro_option = array();
439
+
440
+ if ( ! _is_cartflows_pro() ) {
441
+ $fields_skin_pro_option = array(
442
+ 'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
443
+ );
444
+ }
445
+
446
+ echo wcf()->meta->get_select_field(
447
+ array(
448
+ 'label' => __( 'Style', 'cartflows' ),
449
+ 'name' => 'wcf-fields-skins',
450
+ 'value' => $options['wcf-fields-skins'],
451
+ 'options' => array(
452
+ 'default' => __( 'Default', 'cartflows' ),
453
+ 'style-one' => __( 'Floating Labels', 'cartflows' ),
454
+ ),
455
+ 'pro-options' => $fields_skin_pro_option,
456
+
457
+ )
458
+ );
459
+
460
+ echo wcf()->meta->get_font_family_field(
461
+ array(
462
+ 'for' => 'wcf-input',
463
+ 'label' => __( 'Font Family', 'cartflows' ),
464
+ 'name' => 'wcf-input-font-family',
465
+ 'value' => $options['wcf-input-font-family'],
466
+ )
467
+ );
468
+
469
+ echo wcf()->meta->get_font_weight_field(
470
+ array(
471
+ 'for' => 'wcf-input',
472
+ 'label' => __( 'Font Weight', 'cartflows' ),
473
+ 'name' => 'wcf-input-font-weight',
474
+ 'value' => $options['wcf-input-font-weight'],
475
+ )
476
+ );
477
+
478
+ echo wcf()->meta->get_select_field(
479
+ array(
480
+ 'label' => __( 'Size', 'cartflows' ),
481
+ 'name' => 'wcf-input-field-size',
482
+ 'value' => $options['wcf-input-field-size'],
483
+ 'options' => array(
484
+ '33px' => __( 'Extra Small', 'cartflows' ),
485
+ '38px' => __( 'Small', 'cartflows' ),
486
+ '44px' => __( 'Medium', 'cartflows' ),
487
+ '58px' => __( 'Large', 'cartflows' ),
488
+ '68px' => __( 'Extra Large', 'cartflows' ),
489
+ 'custom' => __( 'Custom', 'cartflows' ),
490
+ ),
491
+ )
492
+ );
493
+
494
+ echo wcf()->meta->get_number_field(
495
+ array(
496
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
497
+ 'name' => 'wcf-field-tb-padding',
498
+ 'value' => $options['wcf-field-tb-padding'],
499
+ )
500
+ );
501
+
502
+ echo wcf()->meta->get_number_field(
503
+ array(
504
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
505
+ 'name' => 'wcf-field-lr-padding',
506
+ 'value' => $options['wcf-field-lr-padding'],
507
+ )
508
+ );
509
+
510
+ echo wcf()->meta->get_color_picker_field(
511
+ array(
512
+ 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
513
+ 'name' => 'wcf-field-color',
514
+ 'value' => $options['wcf-field-color'],
515
+ )
516
+ );
517
+
518
+ echo wcf()->meta->get_color_picker_field(
519
+ array(
520
+ 'label' => __( 'Background Color', 'cartflows' ),
521
+ 'name' => 'wcf-field-bg-color',
522
+ 'value' => $options['wcf-field-bg-color'],
523
+ )
524
+ );
525
+
526
+ echo wcf()->meta->get_color_picker_field(
527
+ array(
528
+ 'label' => __( 'Border Color', 'cartflows' ),
529
+ 'name' => 'wcf-field-border-color',
530
+ 'value' => $options['wcf-field-border-color'],
531
+ )
532
+ );
533
+ echo wcf()->meta->get_color_picker_field(
534
+ array(
535
+ 'label' => __( 'Label Color', 'cartflows' ),
536
+ 'name' => 'wcf-field-label-color',
537
+ 'value' => $options['wcf-field-label-color'],
538
+ )
539
+ );
540
+
541
+ ?>
542
+ </div>
543
+ <div class="wcf-cs-button-options">
544
+ <?php
545
+
546
+ echo wcf()->meta->get_section(
547
+ array(
548
+ 'label' => __( 'Buttons', 'cartflows' ),
549
+ )
550
+ );
551
+
552
+ echo wcf()->meta->get_font_family_field(
553
+ array(
554
+ 'for' => 'wcf-button',
555
+ 'label' => __( 'Font Family', 'cartflows' ),
556
+ 'name' => 'wcf-button-font-family',
557
+ 'value' => $options['wcf-button-font-family'],
558
+ )
559
+ );
560
+
561
+ echo wcf()->meta->get_font_weight_field(
562
+ array(
563
+ 'for' => 'wcf-button',
564
+ 'label' => __( 'Font Weight', 'cartflows' ),
565
+ 'name' => 'wcf-button-font-weight',
566
+ 'value' => $options['wcf-button-font-weight'],
567
+ )
568
+ );
569
+
570
+ echo wcf()->meta->get_select_field(
571
+ array(
572
+ 'label' => __( 'Size', 'cartflows' ),
573
+ 'name' => 'wcf-input-button-size',
574
+ 'value' => $options['wcf-input-button-size'],
575
+ 'options' => array(
576
+ '33px' => __( 'Extra Small', 'cartflows' ),
577
+ '38px' => __( 'Small', 'cartflows' ),
578
+ '44px' => __( 'Medium', 'cartflows' ),
579
+ '58px' => __( 'Large', 'cartflows' ),
580
+ '68px' => __( 'Extra Large', 'cartflows' ),
581
+ 'custom' => __( 'Custom', 'cartflows' ),
582
+ ),
583
+ )
584
+ );
585
+
586
+ echo wcf()->meta->get_number_field(
587
+ array(
588
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
589
+ 'name' => 'wcf-submit-tb-padding',
590
+ 'value' => $options['wcf-submit-tb-padding'],
591
+ )
592
+ );
593
+
594
+ echo wcf()->meta->get_number_field(
595
+ array(
596
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
597
+ 'name' => 'wcf-submit-lr-padding',
598
+ 'value' => $options['wcf-submit-lr-padding'],
599
+ )
600
+ );
601
+
602
+ echo wcf()->meta->get_color_picker_field(
603
+ array(
604
+ 'label' => __( 'Text Color', 'cartflows' ),
605
+ 'name' => 'wcf-submit-color',
606
+ 'value' => $options['wcf-submit-color'],
607
+ )
608
+ );
609
+
610
+ echo wcf()->meta->get_color_picker_field(
611
+ array(
612
+ 'label' => __( 'Text Hover Color', 'cartflows' ),
613
+ 'name' => 'wcf-submit-hover-color',
614
+ 'value' => $options['wcf-submit-hover-color'],
615
+ )
616
+ );
617
+
618
+ echo wcf()->meta->get_color_picker_field(
619
+ array(
620
+ 'label' => __( 'Background Color', 'cartflows' ),
621
+ 'name' => 'wcf-submit-bg-color',
622
+ 'value' => $options['wcf-submit-bg-color'],
623
+ )
624
+ );
625
+
626
+ echo wcf()->meta->get_color_picker_field(
627
+ array(
628
+ 'label' => __( 'Background Hover Color', 'cartflows' ),
629
+ 'name' => 'wcf-submit-bg-hover-color',
630
+ 'value' => $options['wcf-submit-bg-hover-color'],
631
+ )
632
+ );
633
+
634
+ echo wcf()->meta->get_color_picker_field(
635
+ array(
636
+ 'label' => __( 'Border Color', 'cartflows' ),
637
+ 'name' => 'wcf-submit-border-color',
638
+ 'value' => $options['wcf-submit-border-color'],
639
+ )
640
+ );
641
+
642
+ echo wcf()->meta->get_color_picker_field(
643
+ array(
644
+ 'label' => __( 'Border Hover Color', 'cartflows' ),
645
+ 'name' => 'wcf-submit-border-hover-color',
646
+ 'value' => $options['wcf-submit-border-hover-color'],
647
+ )
648
+ );
649
+
650
+ ?>
651
+ </div>
652
+ <div class="wcf-cs-section-options">
653
+ <?php
654
+
655
+ echo wcf()->meta->get_section(
656
+ array(
657
+ 'label' => __( 'Sections', 'cartflows' ),
658
+ )
659
+ );
660
+
661
+ echo wcf()->meta->get_color_picker_field(
662
+ array(
663
+ 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
664
+ 'name' => 'wcf-hl-bg-color',
665
+ 'value' => $options['wcf-hl-bg-color'],
666
+ )
667
+ );
668
+
669
+ echo wcf()->meta->get_hidden_field(
670
+ array(
671
+ 'name' => 'wcf-field-google-font-url',
672
+ 'value' => $options['wcf-field-google-font-url'],
673
+ )
674
+ );
675
+ ?>
676
+ </div>
677
+ <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
678
+ </div>
679
+ </div>
680
+ <?php
681
+ }
682
+
683
+
684
+ /**
685
+ * Tab Header (Used for add logo into header)
686
+ *
687
+ * @param array $options options.
688
+ * @param int $post_id post ID.
689
+ */
690
+ function tab_header_content( $options, $post_id ) {
691
+ ?>
692
+
693
+ <div class="wcf-checkout-header wcf-tab-content widefat">
694
+ <?php
695
+
696
+ $layout_pro_option = array();
697
+
698
+ echo wcf()->meta->get_image_field(
699
+ array(
700
+ 'name' => 'wcf-header-logo-image',
701
+ 'value' => $options['wcf-header-logo-image'],
702
+ 'label' => __( 'Header Logo', 'cartflows' ),
703
+ )
704
+ );
705
+
706
+ echo wcf()->meta->get_number_field(
707
+ array(
708
+ 'name' => 'wcf-header-logo-width',
709
+ 'value' => $options['wcf-header-logo-width'],
710
+ 'label' => __( 'Logo Width (In px)', 'cartflows' ),
711
+ )
712
+ );
713
+ ?>
714
+ <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
715
+ </div>
716
+ <?php
717
+ }
718
+ /**
719
+ * Get metabox options
720
+ *
721
+ * @param int $post_id post ID.
722
+ */
723
+ public static function get_meta_option( $post_id ) {
724
+
725
+ if ( null === self::$meta_option ) {
726
+
727
+ /**
728
+ * Set metabox options
729
+ *
730
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
731
+ */
732
+ self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
733
+ }
734
+
735
+ return self::$meta_option;
736
+ }
737
+
738
+ /**
739
+ * Metabox Save
740
+ *
741
+ * @param number $post_id Post ID.
742
+ * @return void
743
+ */
744
+ function save_meta_box( $post_id ) {
745
+
746
+ // Checks save status.
747
+ $is_autosave = wp_is_post_autosave( $post_id );
748
+ $is_revision = wp_is_post_revision( $post_id );
749
+
750
+ $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
751
+
752
+ // Exits script depending on save status.
753
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
754
+ return;
755
+ }
756
+
757
+ wcf()->options->save_checkout_fields( $post_id );
758
+ }
759
+
760
+ }
761
+
762
+ /**
763
+ * Kicking this off by calling 'get_instance()' method
764
+ */
765
+ Cartflows_Checkout_Meta::get_instance();
modules/flow/classes/class-cartflows-step-post-type.php CHANGED
@@ -1,465 +1,465 @@
1
- <?php
2
- /**
3
- * Step post type.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Initialization
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Step_Post_Type {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var body_classes
27
- */
28
- private $body_classes = array();
29
-
30
- /**
31
- * Initiator
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- */
43
- public function __construct() {
44
-
45
- add_action( 'init', array( $this, 'step_post_type' ) );
46
- add_action( 'init', array( $this, 'add_wp_templates_support' ) );
47
- add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
48
- add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
49
- add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
50
- add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ), 20 );
51
-
52
- add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
53
- }
54
-
55
-
56
- /**
57
- * Trys to load page.php for a header, footer or part theme layout.
58
- *
59
- * @since 1.0.0
60
- * @param string $template The current template to be loaded.
61
- * @return string
62
- */
63
- function load_page_template( $template ) {
64
-
65
- global $post;
66
-
67
- if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
68
-
69
- /**
70
- * Remove Next/Prev Navigation
71
- * add_filter('next_post_link', '__return_empty_string');
72
- * add_filter('previous_post_link', '__return_empty_string');
73
- *
74
- * $page = locate_template( array( 'page.php' ) );
75
- *
76
- * if ( ! empty( $page ) ) {
77
- * return $page;
78
- * }
79
- */
80
-
81
- $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
82
-
83
- $page_template = apply_filters( 'cartflows_page_template', $page_template );
84
-
85
- $file = '';
86
-
87
- switch ( $page_template ) {
88
-
89
- case 'cartflows-default':
90
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
91
- $this->body_classes[] = $page_template;
92
- break;
93
- case 'cartflows-canvas':
94
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
95
- $this->body_classes[] = $page_template;
96
- break;
97
- default:
98
- $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
99
- $this->body_classes[] = 'cartflows-default';
100
- break;
101
- }
102
-
103
- // Just to be safe, we check if the file exist first.
104
- if ( file_exists( $file ) ) {
105
-
106
- /* Add Body Class */
107
- add_filter( 'body_class', [ $this, 'body_class' ] );
108
-
109
- return $file;
110
- } else {
111
- echo $file;
112
- }
113
- }
114
-
115
- return $template;
116
- }
117
-
118
- /**
119
- * Body classes.
120
- *
121
- * @since 1.0.0
122
- * @param array $classes Body classes.
123
- * @return array
124
- */
125
- function body_class( $classes = [] ) {
126
-
127
- $classes = array_merge( $classes, $this->body_classes );
128
-
129
- return $classes;
130
- }
131
-
132
- /**
133
- * Create custom post type
134
- */
135
- function step_post_type() {
136
-
137
- $labels = array(
138
- 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
139
- 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
140
- 'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
141
- 'all_items' => esc_html__( 'All Steps', 'cartflows' ),
142
- 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
143
- 'view_item' => esc_html__( 'View Step', 'cartflows' ),
144
- 'add_new' => esc_html__( 'Add New', 'cartflows' ),
145
- 'update_item' => esc_html__( 'Update Step', 'cartflows' ),
146
- 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
147
- 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
148
- );
149
-
150
- $args = array(
151
- 'labels' => $labels,
152
- 'public' => true,
153
- 'query_var' => true,
154
- 'can_export' => true,
155
- 'exclude_from_search' => true,
156
- 'show_ui' => true,
157
- 'show_in_menu' => false,
158
- 'show_in_admin_bar' => true,
159
- 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ),
160
- 'capability_type' => 'post',
161
- 'capabilities' => array(
162
- 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
163
- ),
164
- 'map_meta_cap' => true,
165
- );
166
-
167
- register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
168
-
169
- $args = array(
170
- 'label' => __( 'Step Type', 'cartflows' ),
171
- 'public' => false,
172
- 'rewrite' => false,
173
- 'hierarchical' => false,
174
- );
175
-
176
- register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
177
-
178
- $args = array(
179
- 'label' => __( 'Step Flow', 'cartflows' ),
180
- 'public' => false,
181
- 'rewrite' => false,
182
- 'hierarchical' => false,
183
- );
184
-
185
- register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
186
-
187
- /**
188
- * Register 'Elementor' & 'Beaver Builder' site types.
189
- *
190
- * @see self::add_terms();
191
- */
192
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
193
-
194
- $terms = array(
195
- array(
196
- 'name' => __( 'Landing', 'cartflows' ),
197
- 'args' => array(
198
- 'slug' => 'landing',
199
- ),
200
- ),
201
- array(
202
- 'name' => __( 'Checkout', 'cartflows' ),
203
- 'args' => array(
204
- 'slug' => 'checkout',
205
- ),
206
- ),
207
- array(
208
- 'name' => __( 'Thank You', 'cartflows' ),
209
- 'args' => array(
210
- 'slug' => 'thankyou',
211
- ),
212
- ),
213
- array(
214
- 'name' => __( 'Upsell', 'cartflows' ),
215
- 'args' => array(
216
- 'slug' => 'upsell',
217
- ),
218
- ),
219
- array(
220
- 'name' => __( 'Downsell', 'cartflows' ),
221
- 'args' => array(
222
- 'slug' => 'downsell',
223
- ),
224
- ),
225
- );
226
-
227
- $this->add_terms( $taxonomy, $terms );
228
- }
229
-
230
- /**
231
- * Add WordPress templates.
232
- *
233
- * Adds Cartflows templates to steps
234
- *
235
- * @since 1.0.0
236
- * @access public
237
- */
238
- function add_wp_templates_support() {
239
- add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
240
- }
241
-
242
- /**
243
- * Add page templates.
244
- *
245
- * @since 1.0.0
246
- * @access public
247
- *
248
- * @param array $page_templates Array of page templates.
249
- *
250
- * @param object $wp_theme wp theme.
251
- * @param object $post post.
252
- *
253
- * @return array Page templates.
254
- */
255
- function add_page_templates( $page_templates, $wp_theme, $post ) {
256
-
257
- $page_templates = array(
258
- 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
259
- );
260
-
261
- return $page_templates;
262
- }
263
-
264
- /**
265
- * Have WordPress match postname to any of our public post types.
266
- * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
267
- * By default, WordPress only accounts for posts and pages where the slug is /post-name/.
268
- *
269
- * @param string $query query statement.
270
- */
271
- function add_cpt_post_names_to_main_query( $query ) {
272
-
273
- // Bail if this is not the main query.
274
- if ( ! $query->is_main_query() ) {
275
- return;
276
- }
277
-
278
- // Bail if this query doesn't match our very specific rewrite rule.
279
- if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
280
- return;
281
- }
282
-
283
- // Bail if we're not querying based on the post name.
284
- if ( empty( $query->query['name'] ) ) {
285
- return;
286
- }
287
-
288
- // Add cartflows step post type to existing post type array.
289
- if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) {
290
-
291
- $post_types = $query->query_vars['post_type'];
292
-
293
- $post_types[] = CARTFLOWS_STEP_POST_TYPE;
294
-
295
- $query->set( 'post_type', $post_types );
296
-
297
- } else {
298
-
299
- // Add CPT to the list of post types WP will include when it queries based on the post name.
300
- $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
301
- }
302
- }
303
-
304
- /**
305
- * Modify permalink
306
- *
307
- * @param string $post_link post link.
308
- * @param array $post post data.
309
- * @param string $leavename leave name.
310
- * @return string
311
- */
312
- function post_type_permalinks( $post_link, $post, $leavename ) {
313
-
314
- // If elementor page preview, return post link as it is.
315
- if ( isset( $_REQUEST['elementor-preview'] ) ) {
316
- return $post_link;
317
- }
318
-
319
- $structure = get_option( 'permalink_structure' );
320
-
321
- if ( '/%postname%/' === $structure ) {
322
-
323
- if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
324
-
325
- $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
326
- }
327
- }
328
-
329
- return $post_link;
330
- }
331
-
332
- /**
333
- * Prevent slug duplicated
334
- *
335
- * @param string $slug post slug.
336
- * @param int $post_ID post id.
337
- * @param string $post_status post status.
338
- * @param string $post_type post type.
339
- * @param int $post_parent post parent id.
340
- * @param string $original_slug original slug.
341
- * @return string
342
- */
343
- function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
344
-
345
- $check_post_types = array(
346
- 'post',
347
- 'page',
348
- CARTFLOWS_STEP_POST_TYPE,
349
- );
350
-
351
- if ( ! in_array( $post_type, $check_post_types ) ) {
352
- return $slug;
353
- }
354
-
355
- if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
356
- // Saving a post, check for duplicates in POST or PAGE post types.
357
- $post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
358
- $page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
359
-
360
- if ( $post_match || $page_match ) {
361
- $slug .= '-2';
362
- }
363
- } else {
364
-
365
- // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
366
- $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
367
-
368
- if ( $custom_post_type_match ) {
369
- $slug .= '-2';
370
- }
371
- }
372
-
373
- return $slug;
374
- }
375
-
376
- /**
377
- * Add Update messages for any custom post type
378
- *
379
- * @param array $messages Array of default messages.
380
- */
381
- function post_update_messages( $messages ) {
382
-
383
- $custom_post_type = get_post_type( get_the_ID() );
384
-
385
- if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
386
-
387
- $obj = get_post_type_object( $custom_post_type );
388
- $singular_name = $obj->labels->singular_name;
389
- $messages[ $custom_post_type ] = array(
390
- 0 => '', // Unused. Messages start at index 1.
391
- /* translators: %s: singular custom post type name */
392
- 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
393
- /* translators: %s: singular custom post type name */
394
- 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
395
- /* translators: %s: singular custom post type name */
396
- 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
397
- /* translators: %s: singular custom post type name */
398
- 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
399
- /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
400
- 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
401
- /* translators: %s: singular custom post type name */
402
- 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
403
- /* translators: %s: singular custom post type name */
404
- 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
405
- /* translators: %s: singular custom post type name */
406
- 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
407
- /* translators: %s: singular custom post type name */
408
- 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
409
- /* translators: %s: singular custom post type name */
410
- 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
411
- );
412
- }
413
-
414
- return $messages;
415
- }
416
-
417
- /**
418
- * Add Terms for Taxonomy.
419
- *
420
- * => Example.
421
- *
422
- * $taxonomy = '{taxonomy}';
423
- * $terms = array(
424
- * array(
425
- * 'name' => 'Free',
426
- * ),
427
- * array(
428
- * 'name' => 'Premium',
429
- * ),
430
- * );
431
- *
432
- * self::add_terms( $taxonomy, $terms );
433
- *
434
- * @since 1.0.0
435
- * @param string $taxonomy Taxonomy Name.
436
- * @param array $terms Terms list.
437
- * @return void
438
- */
439
- function add_terms( $taxonomy = '', $terms = array() ) {
440
-
441
- foreach ( $terms as $key => $term ) {
442
-
443
- $term_exist = term_exists( $term['name'], $taxonomy );
444
-
445
- if ( empty( $term_exist ) ) {
446
-
447
- /**
448
- * Add additional args if passed from request.
449
- *
450
- * @see https://codex.wordpress.org/Function_Reference/wp_insert_term
451
- */
452
- if ( array_key_exists( 'args', $term ) ) {
453
- wp_insert_term( $term['name'], $taxonomy, $term['args'] );
454
- } else {
455
- wp_insert_term( $term['name'], $taxonomy );
456
- }
457
- }
458
- }
459
- }
460
- }
461
-
462
- /**
463
- * Kicking this off by calling 'get_instance()' method
464
- */
465
- Cartflows_Step_Post_Type::get_instance();
1
+ <?php
2
+ /**
3
+ * Step post type.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Initialization
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Step_Post_Type {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var body_classes
27
+ */
28
+ private $body_classes = array();
29
+
30
+ /**
31
+ * Initiator
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ */
43
+ public function __construct() {
44
+
45
+ add_action( 'init', array( $this, 'step_post_type' ) );
46
+ add_action( 'init', array( $this, 'add_wp_templates_support' ) );
47
+ add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
48
+ add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
49
+ add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
50
+ add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ), 20 );
51
+
52
+ add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
53
+ }
54
+
55
+
56
+ /**
57
+ * Trys to load page.php for a header, footer or part theme layout.
58
+ *
59
+ * @since 1.0.0
60
+ * @param string $template The current template to be loaded.
61
+ * @return string
62
+ */
63
+ function load_page_template( $template ) {
64
+
65
+ global $post;
66
+
67
+ if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
68
+
69
+ /**
70
+ * Remove Next/Prev Navigation
71
+ * add_filter('next_post_link', '__return_empty_string');
72
+ * add_filter('previous_post_link', '__return_empty_string');
73
+ *
74
+ * $page = locate_template( array( 'page.php' ) );
75
+ *
76
+ * if ( ! empty( $page ) ) {
77
+ * return $page;
78
+ * }
79
+ */
80
+
81
+ $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
82
+
83
+ $page_template = apply_filters( 'cartflows_page_template', $page_template );
84
+
85
+ $file = '';
86
+
87
+ switch ( $page_template ) {
88
+
89
+ case 'cartflows-default':
90
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
91
+ $this->body_classes[] = $page_template;
92
+ break;
93
+ case 'cartflows-canvas':
94
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
95
+ $this->body_classes[] = $page_template;
96
+ break;
97
+ default:
98
+ $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
99
+ $this->body_classes[] = 'cartflows-default';
100
+ break;
101
+ }
102
+
103
+ // Just to be safe, we check if the file exist first.
104
+ if ( file_exists( $file ) ) {
105
+
106
+ /* Add Body Class */
107
+ add_filter( 'body_class', [ $this, 'body_class' ] );
108
+
109
+ return $file;
110
+ } else {
111
+ echo $file;
112
+ }
113
+ }
114
+
115
+ return $template;
116
+ }
117
+
118
+ /**
119
+ * Body classes.
120
+ *
121
+ * @since 1.0.0
122
+ * @param array $classes Body classes.
123
+ * @return array
124
+ */
125
+ function body_class( $classes = [] ) {
126
+
127
+ $classes = array_merge( $classes, $this->body_classes );
128
+
129
+ return $classes;
130
+ }
131
+
132
+ /**
133
+ * Create custom post type
134
+ */
135
+ function step_post_type() {
136
+
137
+ $labels = array(
138
+ 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
139
+ 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
140
+ 'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
141
+ 'all_items' => esc_html__( 'All Steps', 'cartflows' ),
142
+ 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
143
+ 'view_item' => esc_html__( 'View Step', 'cartflows' ),
144
+ 'add_new' => esc_html__( 'Add New', 'cartflows' ),
145
+ 'update_item' => esc_html__( 'Update Step', 'cartflows' ),
146
+ 'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
147
+ 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
148
+ );
149
+
150
+ $args = array(
151
+ 'labels' => $labels,
152
+ 'public' => true,
153
+ 'query_var' => true,
154
+ 'can_export' => true,
155
+ 'exclude_from_search' => true,
156
+ 'show_ui' => true,
157
+ 'show_in_menu' => false,
158
+ 'show_in_admin_bar' => true,
159
+ 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ),
160
+ 'capability_type' => 'post',
161
+ 'capabilities' => array(
162
+ 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
163
+ ),
164
+ 'map_meta_cap' => true,
165
+ );
166
+
167
+ register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
168
+
169
+ $args = array(
170
+ 'label' => __( 'Step Type', 'cartflows' ),
171
+ 'public' => false,
172
+ 'rewrite' => false,
173
+ 'hierarchical' => false,
174
+ );
175
+
176
+ register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
177
+
178
+ $args = array(
179
+ 'label' => __( 'Step Flow', 'cartflows' ),
180
+ 'public' => false,
181
+ 'rewrite' => false,
182
+ 'hierarchical' => false,
183
+ );
184
+
185
+ register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
186
+
187
+ /**
188
+ * Register 'Elementor' & 'Beaver Builder' site types.
189
+ *
190
+ * @see self::add_terms();
191
+ */
192
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
193
+
194
+ $terms = array(
195
+ array(
196
+ 'name' => __( 'Landing', 'cartflows' ),
197
+ 'args' => array(
198
+ 'slug' => 'landing',
199
+ ),
200
+ ),
201
+ array(
202
+ 'name' => __( 'Checkout', 'cartflows' ),
203
+ 'args' => array(
204
+ 'slug' => 'checkout',
205
+ ),
206
+ ),
207
+ array(
208
+ 'name' => __( 'Thank You', 'cartflows' ),
209
+ 'args' => array(
210
+ 'slug' => 'thankyou',
211
+ ),
212
+ ),
213
+ array(
214
+ 'name' => __( 'Upsell', 'cartflows' ),
215
+ 'args' => array(
216
+ 'slug' => 'upsell',
217
+ ),
218
+ ),
219
+ array(
220
+ 'name' => __( 'Downsell', 'cartflows' ),
221
+ 'args' => array(
222
+ 'slug' => 'downsell',
223
+ ),
224
+ ),
225
+ );
226
+
227
+ $this->add_terms( $taxonomy, $terms );
228
+ }
229
+
230
+ /**
231
+ * Add WordPress templates.
232
+ *
233
+ * Adds Cartflows templates to steps
234
+ *
235
+ * @since 1.0.0
236
+ * @access public
237
+ */
238
+ function add_wp_templates_support() {
239
+ add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
240
+ }
241
+
242
+ /**
243
+ * Add page templates.
244
+ *
245
+ * @since 1.0.0
246
+ * @access public
247
+ *
248
+ * @param array $page_templates Array of page templates.
249
+ *
250
+ * @param object $wp_theme wp theme.
251
+ * @param object $post post.
252
+ *
253
+ * @return array Page templates.
254
+ */
255
+ function add_page_templates( $page_templates, $wp_theme, $post ) {
256
+
257
+ $page_templates = array(
258
+ 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
259
+ );
260
+
261
+ return $page_templates;
262
+ }
263
+
264
+ /**
265
+ * Have WordPress match postname to any of our public post types.
266
+ * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
267
+ * By default, WordPress only accounts for posts and pages where the slug is /post-name/.
268
+ *
269
+ * @param string $query query statement.
270
+ */
271
+ function add_cpt_post_names_to_main_query( $query ) {
272
+
273
+ // Bail if this is not the main query.
274
+ if ( ! $query->is_main_query() ) {
275
+ return;
276
+ }
277
+
278
+ // Bail if this query doesn't match our very specific rewrite rule.
279
+ if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
280
+ return;
281
+ }
282
+
283
+ // Bail if we're not querying based on the post name.
284
+ if ( empty( $query->query['name'] ) ) {
285
+ return;
286
+ }
287
+
288
+ // Add cartflows step post type to existing post type array.
289
+ if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) {
290
+
291
+ $post_types = $query->query_vars['post_type'];
292
+
293
+ $post_types[] = CARTFLOWS_STEP_POST_TYPE;
294
+
295
+ $query->set( 'post_type', $post_types );
296
+
297
+ } else {
298
+
299
+ // Add CPT to the list of post types WP will include when it queries based on the post name.
300
+ $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Modify permalink
306
+ *
307
+ * @param string $post_link post link.
308
+ * @param array $post post data.
309
+ * @param string $leavename leave name.
310
+ * @return string
311
+ */
312
+ function post_type_permalinks( $post_link, $post, $leavename ) {
313
+
314
+ // If elementor page preview, return post link as it is.
315
+ if ( isset( $_REQUEST['elementor-preview'] ) ) {
316
+ return $post_link;
317
+ }
318
+
319
+ $structure = get_option( 'permalink_structure' );
320
+
321
+ if ( '/%postname%/' === $structure ) {
322
+
323
+ if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
324
+
325
+ $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
326
+ }
327
+ }
328
+
329
+ return $post_link;
330
+ }
331
+
332
+ /**
333
+ * Prevent slug duplicated
334
+ *
335
+ * @param string $slug post slug.
336
+ * @param int $post_ID post id.
337
+ * @param string $post_status post status.
338
+ * @param string $post_type post type.
339
+ * @param int $post_parent post parent id.
340
+ * @param string $original_slug original slug.
341
+ * @return string
342
+ */
343
+ function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
344
+
345
+ $check_post_types = array(
346
+ 'post',
347
+ 'page',
348
+ CARTFLOWS_STEP_POST_TYPE,
349
+ );
350
+
351
+ if ( ! in_array( $post_type, $check_post_types ) ) {
352
+ return $slug;
353
+ }
354
+
355
+ if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
356
+ // Saving a post, check for duplicates in POST or PAGE post types.
357
+ $post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
358
+ $page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
359
+
360
+ if ( $post_match || $page_match ) {
361
+ $slug .= '-2';
362
+ }
363
+ } else {
364
+
365
+ // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
366
+ $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
367
+
368
+ if ( $custom_post_type_match ) {
369
+ $slug .= '-2';
370
+ }
371
+ }
372
+
373
+ return $slug;
374
+ }
375
+
376
+ /**
377
+ * Add Update messages for any custom post type
378
+ *
379
+ * @param array $messages Array of default messages.
380
+ */
381
+ function post_update_messages( $messages ) {
382
+
383
+ $custom_post_type = get_post_type( get_the_ID() );
384
+
385
+ if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
386
+
387
+ $obj = get_post_type_object( $custom_post_type );
388
+ $singular_name = $obj->labels->singular_name;
389
+ $messages[ $custom_post_type ] = array(
390
+ 0 => '', // Unused. Messages start at index 1.
391
+ /* translators: %s: singular custom post type name */
392
+ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
393
+ /* translators: %s: singular custom post type name */
394
+ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
395
+ /* translators: %s: singular custom post type name */
396
+ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
397
+ /* translators: %s: singular custom post type name */
398
+ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
399
+ /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
400
+ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
401
+ /* translators: %s: singular custom post type name */
402
+ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
403
+ /* translators: %s: singular custom post type name */
404
+ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
405
+ /* translators: %s: singular custom post type name */
406
+ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
407
+ /* translators: %s: singular custom post type name */
408
+ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
409
+ /* translators: %s: singular custom post type name */
410
+ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
411
+ );
412
+ }
413
+
414
+ return $messages;
415
+ }
416
+
417
+ /**
418
+ * Add Terms for Taxonomy.
419
+ *
420
+ * => Example.
421
+ *
422
+ * $taxonomy = '{taxonomy}';
423
+ * $terms = array(
424
+ * array(
425
+ * 'name' => 'Free',
426
+ * ),
427
+ * array(
428
+ * 'name' => 'Premium',
429
+ * ),
430
+ * );
431
+ *
432
+ * self::add_terms( $taxonomy, $terms );
433
+ *
434
+ * @since 1.0.0
435
+ * @param string $taxonomy Taxonomy Name.
436
+ * @param array $terms Terms list.
437
+ * @return void
438
+ */
439
+ function add_terms( $taxonomy = '', $terms = array() ) {
440
+
441
+ foreach ( $terms as $key => $term ) {
442
+
443
+ $term_exist = term_exists( $term['name'], $taxonomy );
444
+
445
+ if ( empty( $term_exist ) ) {
446
+
447
+ /**
448
+ * Add additional args if passed from request.
449
+ *
450
+ * @see https://codex.wordpress.org/Function_Reference/wp_insert_term
451
+ */
452
+ if ( array_key_exists( 'args', $term ) ) {
453
+ wp_insert_term( $term['name'], $taxonomy, $term['args'] );
454
+ } else {
455
+ wp_insert_term( $term['name'], $taxonomy );
456
+ }
457
+ }
458
+ }
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Kicking this off by calling 'get_instance()' method
464
+ */
465
+ Cartflows_Step_Post_Type::get_instance();
modules/landing/classes/class-cartflows-landing-meta.php CHANGED
@@ -1,236 +1,236 @@
1
- <?php
2
- /**
3
- * Landing post meta box
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Landing_Meta extends Cartflows_Meta {
12
-
13
-
14
- /**
15
- * Instance
16
- *
17
- * @var $instance
18
- */
19
- private static $instance;
20
-
21
- /**
22
- * Meta Option
23
- *
24
- * @var $meta_option
25
- */
26
- private static $meta_option = null;
27
-
28
- /**
29
- * Initiator
30
- */
31
- public static function get_instance() {
32
- if ( ! isset( self::$instance ) ) {
33
- self::$instance = new self;
34
- }
35
-
36
- return self::$instance;
37
- }
38
-
39
- /**
40
- * Constructor
41
- */
42
- public function __construct() {
43
-
44
- /* Init Metabox */
45
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
46
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
47
- }
48
-
49
- /**
50
- * Init Metabox
51
- */
52
- public function init_metabox() {
53
-
54
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
55
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
56
- }
57
-
58
- /**
59
- * Setup Metabox
60
- */
61
- function setup_meta_box() {
62
-
63
- if ( _is_wcf_landing_type() ) {
64
- add_meta_box(
65
- 'wcf-ladning-settings', // Id.
66
- __( 'Landing Page Settings', 'cartflows' ), // Title.
67
- array( $this, 'landing_meta_box' ), // Callback.
68
- wcf()->utils->get_step_post_type(), // Post_type.
69
- 'normal', // Context.
70
- 'high' // Priority.
71
- );
72
- }
73
- }
74
-
75
- /**
76
- * Landing Metabox Markup
77
- *
78
- * @param object $post Post object.
79
- * @return void
80
- */
81
- function landing_meta_box( $post ) {
82
-
83
- wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-step-meta' );
84
- $stored = get_post_meta( $post->ID );
85
-
86
- $checkout_meta = self::get_meta_option( $post->ID );
87
-
88
- // Set stored and override defaults.
89
- foreach ( $stored as $key => $value ) {
90
- if ( array_key_exists( $key, $checkout_meta ) ) {
91
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
92
- } else {
93
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
94
- }
95
- }
96
-
97
- // Get defaults.
98
- $meta = self::get_meta_option( $post->ID );
99
-
100
- /**
101
- * Get options
102
- */
103
- $landing_data = array();
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $landing_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- do_action( 'wcf_landing_settings_markup_before', $meta );
110
- $this->page_header_tab( $landing_data, $post->ID );
111
- do_action( 'wcf_landing_settings_markup_after', $meta );
112
- }
113
-
114
- /**
115
- * Page Header Tabs
116
- *
117
- * @param array $options Post meta.
118
- * @param int $post_id Post ID.
119
- */
120
- function page_header_tab( $options, $post_id ) {
121
-
122
- $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true );
123
-
124
- if ( empty( $active_tab ) ) {
125
- $active_tab = 'wcf-thankyou-shortcodes';
126
- }
127
-
128
- $tabs = array(
129
- array(
130
- 'title' => __( 'Shortcodes', 'cartflows' ),
131
- 'id' => 'wcf-thankyou-shortcodes',
132
- 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
- 'icon' => 'dashicons-info',
134
- ),
135
- array(
136
- 'title' => __( 'Custom Script', 'cartflows' ),
137
- 'id' => 'wcf-landing-custom-script-header',
138
- 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
- 'icon' => 'dashicons-format-aside',
140
- ),
141
- );
142
-
143
- ?>
144
- <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
145
- <div class="wcf-table-container">
146
- <div class="wcf-column-left">
147
- <div class="wcf-tab-wrapper">
148
-
149
- <?php foreach ( $tabs as $key => $tab ) { ?>
150
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
151
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
152
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
153
- </div>
154
- <?php } ?>
155
- <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
156
-
157
- </div>
158
- </div>
159
- <div class="wcf-column-right">
160
- <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
161
- <?php
162
-
163
- $next_step_link = wcf()->utils->get_linking_url(
164
- array( 'class' => 'wcf-next-step' )
165
- );
166
-
167
- echo wcf()->meta->get_shortcode_field(
168
- array(
169
- 'label' => __( 'Next Step Link', 'cartflows' ),
170
- 'name' => 'wcf-next-step-link',
171
- 'content' => $next_step_link,
172
- )
173
- );
174
-
175
- ?>
176
- </div>
177
-
178
- <?php $this->tab_custom_script( $options, $post_id ); ?>
179
-
180
- <?php $this->right_column_footer( $options, $post_id ); ?>
181
- </div>
182
- </div>
183
- </div>
184
-
185
- <?php
186
-
187
- }
188
-
189
- /**
190
- * Get metabox options
191
- *
192
- * @param int $post_id post ID.
193
- * @return array
194
- */
195
- public static function get_meta_option( $post_id ) {
196
-
197
- if ( null === self::$meta_option ) {
198
- /**
199
- * Set metabox options
200
- *
201
- * @see http://php.net/manual/en/filter.filters.sanitize.php
202
- */
203
- // self::$meta_option = array(); .
204
- self::$meta_option = wcf()->options->get_landing_fields( $post_id );
205
- }
206
-
207
- return self::$meta_option;
208
- }
209
-
210
- /**
211
- * Metabox Save
212
- *
213
- * @param number $post_id Post ID.
214
- * @return void
215
- */
216
- function save_meta_box( $post_id ) {
217
-
218
- // Checks save status.
219
- $is_autosave = wp_is_post_autosave( $post_id );
220
- $is_revision = wp_is_post_revision( $post_id );
221
-
222
- $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
223
-
224
- // Exits script depending on save status.
225
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
226
- return;
227
- }
228
-
229
- wcf()->options->save_landing_fields( $post_id );
230
- }
231
- }
232
-
233
- /**
234
- * Kicking this off by calling 'get_instance()' method
235
- */
236
- Cartflows_Landing_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Landing post meta box
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Landing_Meta extends Cartflows_Meta {
12
+
13
+
14
+ /**
15
+ * Instance
16
+ *
17
+ * @var $instance
18
+ */
19
+ private static $instance;
20
+
21
+ /**
22
+ * Meta Option
23
+ *
24
+ * @var $meta_option
25
+ */
26
+ private static $meta_option = null;
27
+
28
+ /**
29
+ * Initiator
30
+ */
31
+ public static function get_instance() {
32
+ if ( ! isset( self::$instance ) ) {
33
+ self::$instance = new self;
34
+ }
35
+
36
+ return self::$instance;
37
+ }
38
+
39
+ /**
40
+ * Constructor
41
+ */
42
+ public function __construct() {
43
+
44
+ /* Init Metabox */
45
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
46
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
47
+ }
48
+
49
+ /**
50
+ * Init Metabox
51
+ */
52
+ public function init_metabox() {
53
+
54
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
55
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
56
+ }
57
+
58
+ /**
59
+ * Setup Metabox
60
+ */
61
+ function setup_meta_box() {
62
+
63
+ if ( _is_wcf_landing_type() ) {
64
+ add_meta_box(
65
+ 'wcf-ladning-settings', // Id.
66
+ __( 'Landing Page Settings', 'cartflows' ), // Title.
67
+ array( $this, 'landing_meta_box' ), // Callback.
68
+ wcf()->utils->get_step_post_type(), // Post_type.
69
+ 'normal', // Context.
70
+ 'high' // Priority.
71
+ );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Landing Metabox Markup
77
+ *
78
+ * @param object $post Post object.
79
+ * @return void
80
+ */
81
+ function landing_meta_box( $post ) {
82
+
83
+ wp_nonce_field( 'save-nonce-landing-step-meta', 'nonce-landing-step-meta' );
84
+ $stored = get_post_meta( $post->ID );
85
+
86
+ $checkout_meta = self::get_meta_option( $post->ID );
87
+
88
+ // Set stored and override defaults.
89
+ foreach ( $stored as $key => $value ) {
90
+ if ( array_key_exists( $key, $checkout_meta ) ) {
91
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
92
+ } else {
93
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
94
+ }
95
+ }
96
+
97
+ // Get defaults.
98
+ $meta = self::get_meta_option( $post->ID );
99
+
100
+ /**
101
+ * Get options
102
+ */
103
+ $landing_data = array();
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $landing_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ do_action( 'wcf_landing_settings_markup_before', $meta );
110
+ $this->page_header_tab( $landing_data, $post->ID );
111
+ do_action( 'wcf_landing_settings_markup_after', $meta );
112
+ }
113
+
114
+ /**
115
+ * Page Header Tabs
116
+ *
117
+ * @param array $options Post meta.
118
+ * @param int $post_id Post ID.
119
+ */
120
+ function page_header_tab( $options, $post_id ) {
121
+
122
+ $active_tab = get_post_meta( $post_id, 'wcf_active_tab', true );
123
+
124
+ if ( empty( $active_tab ) ) {
125
+ $active_tab = 'wcf-thankyou-shortcodes';
126
+ }
127
+
128
+ $tabs = array(
129
+ array(
130
+ 'title' => __( 'Shortcodes', 'cartflows' ),
131
+ 'id' => 'wcf-thankyou-shortcodes',
132
+ 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
+ 'icon' => 'dashicons-info',
134
+ ),
135
+ array(
136
+ 'title' => __( 'Custom Script', 'cartflows' ),
137
+ 'id' => 'wcf-landing-custom-script-header',
138
+ 'class' => 'wcf-landing-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
+ 'icon' => 'dashicons-format-aside',
140
+ ),
141
+ );
142
+
143
+ ?>
144
+ <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
145
+ <div class="wcf-table-container">
146
+ <div class="wcf-column-left">
147
+ <div class="wcf-tab-wrapper">
148
+
149
+ <?php foreach ( $tabs as $key => $tab ) { ?>
150
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
151
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
152
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
153
+ </div>
154
+ <?php } ?>
155
+ <input type="hidden" id="wcf_active_tab" name="wcf_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
156
+
157
+ </div>
158
+ </div>
159
+ <div class="wcf-column-right">
160
+ <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
161
+ <?php
162
+
163
+ $next_step_link = wcf()->utils->get_linking_url(
164
+ array( 'class' => 'wcf-next-step' )
165
+ );
166
+
167
+ echo wcf()->meta->get_shortcode_field(
168
+ array(
169
+ 'label' => __( 'Next Step Link', 'cartflows' ),
170
+ 'name' => 'wcf-next-step-link',
171
+ 'content' => $next_step_link,
172
+ )
173
+ );
174
+
175
+ ?>
176
+ </div>
177
+
178
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
179
+
180
+ <?php $this->right_column_footer( $options, $post_id ); ?>
181
+ </div>
182
+ </div>
183
+ </div>
184
+
185
+ <?php
186
+
187
+ }
188
+
189
+ /**
190
+ * Get metabox options
191
+ *
192
+ * @param int $post_id post ID.
193
+ * @return array
194
+ */
195
+ public static function get_meta_option( $post_id ) {
196
+
197
+ if ( null === self::$meta_option ) {
198
+ /**
199
+ * Set metabox options
200
+ *
201
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
202
+ */
203
+ // self::$meta_option = array(); .
204
+ self::$meta_option = wcf()->options->get_landing_fields( $post_id );
205
+ }
206
+
207
+ return self::$meta_option;
208
+ }
209
+
210
+ /**
211
+ * Metabox Save
212
+ *
213
+ * @param number $post_id Post ID.
214
+ * @return void
215
+ */
216
+ function save_meta_box( $post_id ) {
217
+
218
+ // Checks save status.
219
+ $is_autosave = wp_is_post_autosave( $post_id );
220
+ $is_revision = wp_is_post_revision( $post_id );
221
+
222
+ $is_valid_nonce = ( isset( $_POST['nonce-landing-step-meta'] ) && wp_verify_nonce( $_POST['nonce-landing-step-meta'], 'save-nonce-landing-step-meta' ) ) ? true : false;
223
+
224
+ // Exits script depending on save status.
225
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
226
+ return;
227
+ }
228
+
229
+ wcf()->options->save_landing_fields( $post_id );
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Kicking this off by calling 'get_instance()' method
235
+ */
236
+ Cartflows_Landing_Meta::get_instance();
modules/thankyou/classes/class-cartflows-thankyou-meta.php CHANGED
@@ -1,371 +1,371 @@
1
- <?php
2
- /**
3
- * Checkout post meta box
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Thankyou_Meta extends Cartflows_Meta {
12
-
13
- /**
14
- * Instance
15
- *
16
- * @var $instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Meta Option
22
- *
23
- * @var $meta_option
24
- */
25
- private static $meta_option = null;
26
-
27
- /**
28
- * Initiator
29
- */
30
- public static function get_instance() {
31
- if ( ! isset( self::$instance ) ) {
32
- self::$instance = new self;
33
- }
34
-
35
- return self::$instance;
36
- }
37
-
38
- /**
39
- * Constructor
40
- */
41
- public function __construct() {
42
-
43
- /* Init Metabox */
44
- add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
- add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
- }
47
-
48
- /**
49
- * Init Metabox
50
- */
51
- public function init_metabox() {
52
-
53
- add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
- add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
- }
56
-
57
- /**
58
- * Setup Metabox
59
- */
60
- function setup_meta_box() {
61
-
62
- if ( _is_wcf_thankyou_type() ) {
63
- add_meta_box(
64
- 'wcf-thankyou-settings', // Id.
65
- __( 'Thank You Page Settings', 'cartflows' ), // Title.
66
- array( $this, 'markup_meta_box' ), // Callback.
67
- wcf()->utils->get_step_post_type(), // Post_type.
68
- 'normal', // Context.
69
- 'high' // Priority.
70
- );
71
- }
72
- }
73
-
74
- /**
75
- * Metabox Markup
76
- *
77
- * @param object $post Post object.
78
- * @return void
79
- */
80
- function markup_meta_box( $post ) {
81
-
82
- wp_nonce_field( 'save-nonce-thankyou-step-meta', 'nonce-thankyou-step-meta' );
83
- $stored = get_post_meta( $post->ID );
84
-
85
- $checkout_meta = self::get_meta_option( $post->ID );
86
-
87
- // Set stored and override defaults.
88
- foreach ( $stored as $key => $value ) {
89
- if ( array_key_exists( $key, $checkout_meta ) ) {
90
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
91
- } else {
92
- self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
93
- }
94
- }
95
-
96
- // Get defaults.
97
- $meta = self::get_meta_option( $post->ID );
98
-
99
- /**
100
- * Get options
101
- */
102
- $thankyou_data = array();
103
-
104
- foreach ( $meta as $key => $value ) {
105
-
106
- $thankyou_data[ $key ] = $meta[ $key ]['default'];
107
- }
108
-
109
- do_action( 'wcf_thankyou_settings_markup_before', $meta );
110
- $this->page_header_tab( $thankyou_data, $post->ID );
111
- do_action( 'wcf_thankyou_settings_markup_after', $meta );
112
- }
113
-
114
- /**
115
- * Page Header Tabs
116
- *
117
- * @param array $options Post meta.
118
- * @param int $post_id Post ID.
119
- */
120
- function page_header_tab( $options, $post_id ) {
121
-
122
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
123
-
124
- if ( empty( $active_tab ) ) {
125
- $active_tab = 'wcf-thankyou-shortcodes';
126
- }
127
-
128
- $tabs = array(
129
- array(
130
- 'title' => __( 'Shortcodes', 'cartflows' ),
131
- 'id' => 'wcf-thankyou-shortcodes',
132
- 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
- 'icon' => 'dashicons-editor-code',
134
- ),
135
- array(
136
- 'title' => __( 'Thank You Design', 'cartflows' ),
137
- 'id' => 'wcf-thankyou-design',
138
- 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
- 'icon' => 'dashicons-admin-customizer',
140
- ),
141
- array(
142
- 'title' => __( 'Thank You Fields', 'cartflows' ),
143
- 'id' => 'wcf-thankyou-fields',
144
- 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
145
- 'icon' => 'dashicons-welcome-widgets-menus',
146
- ),
147
- array(
148
- 'title' => __( 'Custom Script', 'cartflows' ),
149
- 'id' => 'wcf-thankyou-custom-script-header',
150
- 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
- 'icon' => 'dashicons-format-aside',
152
- ),
153
- );
154
-
155
- ?>
156
- <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
157
- <div class="wcf-table-container">
158
- <div class="wcf-column-left">
159
- <div class="wcf-tab-wrapper">
160
-
161
- <?php foreach ( $tabs as $key => $tab ) { ?>
162
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
163
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
164
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
165
- </div>
166
- <?php } ?>
167
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
168
-
169
- </div>
170
- </div>
171
- <div class="wcf-column-right">
172
- <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
173
- <?php
174
- echo wcf()->meta->get_shortcode_field(
175
- array(
176
- 'label' => __( 'Order Details', 'cartflows' ),
177
- 'name' => 'wcf-order-details',
178
- 'content' => esc_html( '[cartflows_order_details]' ),
179
- )
180
- );
181
- ?>
182
- </div>
183
- <div class="wcf-thankyou-design wcf-tab-content widefat">
184
- <?php
185
-
186
- echo wcf()->meta->get_section(
187
- array(
188
- 'label' => __( 'Text', 'cartflows' ),
189
- )
190
- );
191
-
192
- echo wcf()->meta->get_color_picker_field(
193
- array(
194
- 'label' => __( 'Color', 'cartflows' ),
195
- 'name' => 'wcf-tq-text-color',
196
- 'value' => $options['wcf-tq-text-color'],
197
- )
198
- );
199
-
200
- echo wcf()->meta->get_font_family_field(
201
- array(
202
- 'for' => 'wcf-tq-font-family',
203
- 'label' => __( 'Font Family', 'cartflows' ),
204
- 'name' => 'wcf-tq-font-family',
205
- 'value' => $options['wcf-tq-font-family'],
206
- )
207
- );
208
-
209
- echo wcf()->meta->get_section(
210
- array(
211
- 'label' => __( 'Heading', 'cartflows' ),
212
- )
213
- );
214
-
215
- echo wcf()->meta->get_color_picker_field(
216
- array(
217
- 'label' => __( 'Color', 'cartflows' ),
218
- 'name' => 'wcf-tq-heading-color',
219
- 'value' => $options['wcf-tq-heading-color'],
220
- )
221
- );
222
-
223
- echo wcf()->meta->get_font_family_field(
224
- array(
225
- 'for' => 'wcf-tq-heading-font-family',
226
- 'label' => __( 'Font Family', 'cartflows' ),
227
- 'name' => 'wcf-tq-heading-font-family',
228
- 'value' => $options['wcf-tq-heading-font-family'],
229
- )
230
- );
231
-
232
- echo wcf()->meta->get_font_weight_field(
233
- array(
234
- 'for' => 'wcf-tq-heading-font-family',
235
- 'label' => __( 'Font Weight', 'cartflows' ),
236
- 'name' => 'wcf-tq-heading-font-wt',
237
- 'value' => $options['wcf-tq-heading-font-wt'],
238
- )
239
- );
240
-
241
- echo wcf()->meta->get_checkbox_field(
242
- array(
243
- 'label' => __( 'Advanced Options', 'cartflows' ),
244
- 'name' => 'wcf-tq-advance-options-fields',
245
- 'value' => $options['wcf-tq-advance-options-fields'],
246
- 'after' => 'Enable',
247
- )
248
- );
249
-
250
- echo wcf()->meta->get_number_field(
251
- array(
252
- 'for' => 'wcf-heading',
253
- 'label' => __( 'Container Width (In px)', 'cartflows' ),
254
- 'name' => 'wcf-tq-container-width',
255
- 'value' => $options['wcf-tq-container-width'],
256
- )
257
- );
258
-
259
- echo wcf()->meta->get_color_picker_field(
260
- array(
261
- 'label' => __( 'Section Background Color', 'cartflows' ),
262
- 'name' => 'wcf-tq-section-bg-color',
263
- 'value' => $options['wcf-tq-section-bg-color'],
264
- )
265
- );
266
-
267
- ?>
268
- </div>
269
- <div class="wcf-thankyou-fields wcf-tab-content widefat">
270
- <?php
271
- echo wcf()->meta->get_checkbox_field(
272
- array(
273
- 'name' => 'wcf-show-overview-section',
274
- 'value' => $options['wcf-show-overview-section'],
275
- 'after' => __( 'Enable Order Overview ', 'cartflows' ),
276
- )
277
- );
278
-
279
- echo wcf()->meta->get_checkbox_field(
280
- array(
281
- 'name' => 'wcf-show-details-section',
282
- 'value' => $options['wcf-show-details-section'],
283
- 'after' => __( 'Enable Order Details ', 'cartflows' ),
284
- )
285
- );
286
-
287
- echo wcf()->meta->get_checkbox_field(
288
- array(
289
- 'name' => 'wcf-show-billing-section',
290
- 'value' => $options['wcf-show-billing-section'],
291
- 'after' => __( 'Enable Billing Details ', 'cartflows' ),
292
- )
293
- );
294
-
295
- echo wcf()->meta->get_checkbox_field(
296
- array(
297
- 'name' => 'wcf-show-shipping-section',
298
- 'value' => $options['wcf-show-shipping-section'],
299
- 'after' => __( 'Enable Shipping Details ', 'cartflows' ),
300
- )
301
- );
302
-
303
- echo wcf()->meta->get_hidden_field(
304
- array(
305
- 'name' => 'wcf-field-google-font-url',
306
- 'value' => $options['wcf-field-google-font-url'],
307
- )
308
- );
309
- ?>
310
- </div>
311
-
312
- <?php $this->tab_custom_script( $options, $post_id ); ?>
313
-
314
- <?php $this->right_column_footer( $options, $post_id ); ?>
315
- </div>
316
- </div>
317
- </div>
318
-
319
- <?php
320
-
321
- }
322
-
323
- /**
324
- * Get metabox options
325
- *
326
- * @param int $post_id post ID.
327
- * @return array
328
- */
329
- public static function get_meta_option( $post_id ) {
330
-
331
- if ( null === self::$meta_option ) {
332
-
333
- /**
334
- * Set metabox options
335
- *
336
- * @see http://php.net/manual/en/filter.filters.sanitize.php
337
- */
338
- self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
339
- }
340
-
341
- return self::$meta_option;
342
-
343
- }
344
-
345
- /**
346
- * Metabox Save
347
- *
348
- * @param number $post_id Post ID.
349
- * @return void
350
- */
351
- function save_meta_box( $post_id ) {
352
-
353
- // Checks save status.
354
- $is_autosave = wp_is_post_autosave( $post_id );
355
- $is_revision = wp_is_post_revision( $post_id );
356
-
357
- $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( $_POST['nonce-thankyou-step-meta'], 'save-nonce-thankyou-step-meta' ) ) ? true : false;
358
-
359
- // Exits script depending on save status.
360
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
361
- return;
362
- }
363
-
364
- wcf()->options->save_thankyou_fields( $post_id );
365
- }
366
- }
367
-
368
- /**
369
- * Kicking this off by calling 'get_instance()' method
370
- */
371
- Cartflows_Thankyou_Meta::get_instance();
1
+ <?php
2
+ /**
3
+ * Checkout post meta box
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Meta Boxes setup
10
+ */
11
+ class Cartflows_Thankyou_Meta extends Cartflows_Meta {
12
+
13
+ /**
14
+ * Instance
15
+ *
16
+ * @var $instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Meta Option
22
+ *
23
+ * @var $meta_option
24
+ */
25
+ private static $meta_option = null;
26
+
27
+ /**
28
+ * Initiator
29
+ */
30
+ public static function get_instance() {
31
+ if ( ! isset( self::$instance ) ) {
32
+ self::$instance = new self;
33
+ }
34
+
35
+ return self::$instance;
36
+ }
37
+
38
+ /**
39
+ * Constructor
40
+ */
41
+ public function __construct() {
42
+
43
+ /* Init Metabox */
44
+ add_action( 'load-post.php', array( $this, 'init_metabox' ) );
45
+ add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
46
+ }
47
+
48
+ /**
49
+ * Init Metabox
50
+ */
51
+ public function init_metabox() {
52
+
53
+ add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
54
+ add_action( 'save_post', array( $this, 'save_meta_box' ) );
55
+ }
56
+
57
+ /**
58
+ * Setup Metabox
59
+ */
60
+ function setup_meta_box() {
61
+
62
+ if ( _is_wcf_thankyou_type() ) {
63
+ add_meta_box(
64
+ 'wcf-thankyou-settings', // Id.
65
+ __( 'Thank You Page Settings', 'cartflows' ), // Title.
66
+ array( $this, 'markup_meta_box' ), // Callback.
67
+ wcf()->utils->get_step_post_type(), // Post_type.
68
+ 'normal', // Context.
69
+ 'high' // Priority.
70
+ );
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Metabox Markup
76
+ *
77
+ * @param object $post Post object.
78
+ * @return void
79
+ */
80
+ function markup_meta_box( $post ) {
81
+
82
+ wp_nonce_field( 'save-nonce-thankyou-step-meta', 'nonce-thankyou-step-meta' );
83
+ $stored = get_post_meta( $post->ID );
84
+
85
+ $checkout_meta = self::get_meta_option( $post->ID );
86
+
87
+ // Set stored and override defaults.
88
+ foreach ( $stored as $key => $value ) {
89
+ if ( array_key_exists( $key, $checkout_meta ) ) {
90
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
91
+ } else {
92
+ self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
93
+ }
94
+ }
95
+
96
+ // Get defaults.
97
+ $meta = self::get_meta_option( $post->ID );
98
+
99
+ /**
100
+ * Get options
101
+ */
102
+ $thankyou_data = array();
103
+
104
+ foreach ( $meta as $key => $value ) {
105
+
106
+ $thankyou_data[ $key ] = $meta[ $key ]['default'];
107
+ }
108
+
109
+ do_action( 'wcf_thankyou_settings_markup_before', $meta );
110
+ $this->page_header_tab( $thankyou_data, $post->ID );
111
+ do_action( 'wcf_thankyou_settings_markup_after', $meta );
112
+ }
113
+
114
+ /**
115
+ * Page Header Tabs
116
+ *
117
+ * @param array $options Post meta.
118
+ * @param int $post_id Post ID.
119
+ */
120
+ function page_header_tab( $options, $post_id ) {
121
+
122
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
123
+
124
+ if ( empty( $active_tab ) ) {
125
+ $active_tab = 'wcf-thankyou-shortcodes';
126
+ }
127
+
128
+ $tabs = array(
129
+ array(
130
+ 'title' => __( 'Shortcodes', 'cartflows' ),
131
+ 'id' => 'wcf-thankyou-shortcodes',
132
+ 'class' => 'wcf-thankyou-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
133
+ 'icon' => 'dashicons-editor-code',
134
+ ),
135
+ array(
136
+ 'title' => __( 'Thank You Design', 'cartflows' ),
137
+ 'id' => 'wcf-thankyou-design',
138
+ 'class' => 'wcf-thankyou-design' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
139
+ 'icon' => 'dashicons-admin-customizer',
140
+ ),
141
+ array(
142
+ 'title' => __( 'Thank You Fields', 'cartflows' ),
143
+ 'id' => 'wcf-thankyou-fields',
144
+ 'class' => 'wcf-thankyou-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
145
+ 'icon' => 'dashicons-welcome-widgets-menus',
146
+ ),
147
+ array(
148
+ 'title' => __( 'Custom Script', 'cartflows' ),
149
+ 'id' => 'wcf-thankyou-custom-script-header',
150
+ 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
+ 'icon' => 'dashicons-format-aside',
152
+ ),
153
+ );
154
+
155
+ ?>
156
+ <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
157
+ <div class="wcf-table-container">
158
+ <div class="wcf-column-left">
159
+ <div class="wcf-tab-wrapper">
160
+
161
+ <?php foreach ( $tabs as $key => $tab ) { ?>
162
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
163
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
164
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
165
+ </div>
166
+ <?php } ?>
167
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
168
+
169
+ </div>
170
+ </div>
171
+ <div class="wcf-column-right">
172
+ <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
173
+ <?php
174
+ echo wcf()->meta->get_shortcode_field(
175
+ array(
176
+ 'label' => __( 'Order Details', 'cartflows' ),
177
+ 'name' => 'wcf-order-details',
178
+ 'content' => esc_html( '[cartflows_order_details]' ),
179
+ )
180
+ );
181
+ ?>
182
+ </div>
183
+ <div class="wcf-thankyou-design wcf-tab-content widefat">
184
+ <?php
185
+
186
+ echo wcf()->meta->get_section(
187
+ array(
188
+ 'label' => __( 'Text', 'cartflows' ),
189
+ )
190
+ );
191
+
192
+ echo wcf()->meta->get_color_picker_field(
193
+ array(
194
+ 'label' => __( 'Color', 'cartflows' ),
195
+ 'name' => 'wcf-tq-text-color',
196
+ 'value' => $options['wcf-tq-text-color'],
197
+ )
198
+ );
199
+
200
+ echo wcf()->meta->get_font_family_field(
201
+ array(
202
+ 'for' => 'wcf-tq-font-family',
203
+ 'label' => __( 'Font Family', 'cartflows' ),
204
+ 'name' => 'wcf-tq-font-family',
205
+ 'value' => $options['wcf-tq-font-family'],
206
+ )
207
+ );
208
+
209
+ echo wcf()->meta->get_section(
210
+ array(
211
+ 'label' => __( 'Heading', 'cartflows' ),
212
+ )
213
+ );
214
+
215
+ echo wcf()->meta->get_color_picker_field(
216
+ array(
217
+ 'label' => __( 'Color', 'cartflows' ),
218
+ 'name' => 'wcf-tq-heading-color',
219
+ 'value' => $options['wcf-tq-heading-color'],
220
+ )
221
+ );
222
+
223
+ echo wcf()->meta->get_font_family_field(
224
+ array(
225
+ 'for' => 'wcf-tq-heading-font-family',
226
+ 'label' => __( 'Font Family', 'cartflows' ),
227
+ 'name' => 'wcf-tq-heading-font-family',
228
+ 'value' => $options['wcf-tq-heading-font-family'],
229
+ )
230
+ );
231
+
232
+ echo wcf()->meta->get_font_weight_field(
233
+ array(
234
+ 'for' => 'wcf-tq-heading-font-family',
235
+ 'label' => __( 'Font Weight', 'cartflows' ),
236
+ 'name' => 'wcf-tq-heading-font-wt',
237
+ 'value' => $options['wcf-tq-heading-font-wt'],
238
+ )
239
+ );
240
+
241
+ echo wcf()->meta->get_checkbox_field(
242
+ array(
243
+ 'label' => __( 'Advanced Options', 'cartflows' ),
244
+ 'name' => 'wcf-tq-advance-options-fields',
245
+ 'value' => $options['wcf-tq-advance-options-fields'],
246
+ 'after' => 'Enable',
247
+ )
248
+ );
249
+
250
+ echo wcf()->meta->get_number_field(
251
+ array(
252
+ 'for' => 'wcf-heading',
253
+ 'label' => __( 'Container Width (In px)', 'cartflows' ),
254
+ 'name' => 'wcf-tq-container-width',
255
+ 'value' => $options['wcf-tq-container-width'],
256
+ )
257
+ );
258
+
259
+ echo wcf()->meta->get_color_picker_field(
260
+ array(
261
+ 'label' => __( 'Section Background Color', 'cartflows' ),
262
+ 'name' => 'wcf-tq-section-bg-color',
263
+ 'value' => $options['wcf-tq-section-bg-color'],
264
+ )
265
+ );
266
+
267
+ ?>
268
+ </div>
269
+ <div class="wcf-thankyou-fields wcf-tab-content widefat">
270
+ <?php
271
+ echo wcf()->meta->get_checkbox_field(
272
+ array(
273
+ 'name' => 'wcf-show-overview-section',
274
+ 'value' => $options['wcf-show-overview-section'],
275
+ 'after' => __( 'Enable Order Overview ', 'cartflows' ),
276
+ )
277
+ );
278
+
279
+ echo wcf()->meta->get_checkbox_field(
280
+ array(
281
+ 'name' => 'wcf-show-details-section',
282
+ 'value' => $options['wcf-show-details-section'],
283
+ 'after' => __( 'Enable Order Details ', 'cartflows' ),
284
+ )
285
+ );
286
+
287
+ echo wcf()->meta->get_checkbox_field(
288
+ array(
289
+ 'name' => 'wcf-show-billing-section',
290
+ 'value' => $options['wcf-show-billing-section'],
291
+ 'after' => __( 'Enable Billing Details ', 'cartflows' ),
292
+ )
293
+ );
294
+
295
+ echo wcf()->meta->get_checkbox_field(
296
+ array(
297
+ 'name' => 'wcf-show-shipping-section',
298
+ 'value' => $options['wcf-show-shipping-section'],
299
+ 'after' => __( 'Enable Shipping Details ', 'cartflows' ),
300
+ )
301
+ );
302
+
303
+ echo wcf()->meta->get_hidden_field(
304
+ array(
305
+ 'name' => 'wcf-field-google-font-url',
306
+ 'value' => $options['wcf-field-google-font-url'],
307
+ )
308
+ );
309
+ ?>
310
+ </div>
311
+
312
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
313
+
314
+ <?php $this->right_column_footer( $options, $post_id ); ?>
315
+ </div>
316
+ </div>
317
+ </div>
318
+
319
+ <?php
320
+
321
+ }
322
+
323
+ /**
324
+ * Get metabox options
325
+ *
326
+ * @param int $post_id post ID.
327
+ * @return array
328
+ */
329
+ public static function get_meta_option( $post_id ) {
330
+
331
+ if ( null === self::$meta_option ) {
332
+
333
+ /**
334
+ * Set metabox options
335
+ *
336
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
337
+ */
338
+ self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
339
+ }
340
+
341
+ return self::$meta_option;
342
+
343
+ }
344
+
345
+ /**
346
+ * Metabox Save
347
+ *
348
+ * @param number $post_id Post ID.
349
+ * @return void
350
+ */
351
+ function save_meta_box( $post_id ) {
352
+
353
+ // Checks save status.
354
+ $is_autosave = wp_is_post_autosave( $post_id );
355
+ $is_revision = wp_is_post_revision( $post_id );
356
+
357
+ $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( $_POST['nonce-thankyou-step-meta'], 'save-nonce-thankyou-step-meta' ) ) ? true : false;
358
+
359
+ // Exits script depending on save status.
360
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
361
+ return;
362
+ }
363
+
364
+ wcf()->options->save_thankyou_fields( $post_id );
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Kicking this off by calling 'get_instance()' method
370
+ */
371
+ Cartflows_Thankyou_Meta::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.8
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -94,6 +94,10 @@ Say goodby to using the same ridgid checkout page that everyone else is using. C
94
 
95
  == Changelog ==
96
 
 
 
 
 
97
  = Version 1.1.8 - Wednesday, 27th February 2019 =
98
  * New: Custom script support added for Landing, Checkout and Thank You page type.
99
  * Fix: Added compatibility for pre-applied coupon field fix.
5
  Requires at least: 4.4
6
  Requires PHP: 5.6
7
  Tested up to: 5.1
8
+ Stable tag: 1.1.9
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
94
 
95
  == Changelog ==
96
 
97
+ = Version 1.1.9 - Tuesday, 5th March 2019 =
98
+ * Fix: Divi builder fails to open if the page is set as home page.
99
+ * Fix: Checkout field's width issue on mobile devices in Divi.
100
+
101
  = Version 1.1.8 - Wednesday, 27th February 2019 =
102
  * New: Custom script support added for Landing, Checkout and Thank You page type.
103
  * Fix: Added compatibility for pre-applied coupon field fix.