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

Version Description

Download this release

Release Info

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

Code changes from version 1.5.1 to 1.5.2

Files changed (31) hide show
  1. admin/meta-assets/js/admin-edit.js +8 -5
  2. assets/js/frontend.js +2 -2
  3. assets/min-js/frontend.min.js +1 -1
  4. cartflows.php +1 -1
  5. changelog.txt +7 -0
  6. classes/class-cartflows-admin.php +653 -653
  7. classes/class-cartflows-compatibility.php +447 -410
  8. classes/class-cartflows-default-meta.php +27 -0
  9. classes/class-cartflows-elementor-compatibility.php +100 -100
  10. classes/class-cartflows-frontend.php +15 -3
  11. classes/class-cartflows-functions.php +523 -523
  12. classes/class-cartflows-helper.php +22 -0
  13. classes/class-cartflows-importer.php +1694 -1694
  14. classes/class-cartflows-learndash-compatibility.php +140 -140
  15. classes/class-cartflows-loader.php +1 -1
  16. classes/class-cartflows-meta-fields.php +13 -7
  17. classes/class-cartflows-meta.php +75 -75
  18. classes/class-cartflows-tracking.php +277 -277
  19. includes/admin/cartflows-general.php +23 -1
  20. languages/cartflows.pot +58 -53
  21. modules/checkout/classes/class-cartflows-checkout-markup.php +9 -151
  22. modules/checkout/classes/class-cartflows-checkout-meta.php +915 -915
  23. modules/checkout/includes/checkout-dynamic-css.php +162 -0
  24. modules/checkout/includes/checkout-dynamic-divi-css.php +169 -0
  25. modules/flow/view/meta-flow-steps.php +210 -210
  26. modules/landing/classes/class-cartflows-landing-markup.php +143 -143
  27. modules/optin/classes/class-cartflows-optin-markup.php +802 -802
  28. modules/optin/classes/class-cartflows-optin-meta.php +672 -672
  29. modules/thankyou/classes/class-cartflows-thankyou-markup.php +372 -372
  30. modules/thankyou/classes/class-cartflows-thankyou-meta.php +423 -423
  31. readme.txt +8 -1
admin/meta-assets/js/admin-edit.js CHANGED
@@ -631,11 +631,13 @@
631
  window.inputWrapper.find( '#wcf-image-preview' ).append('<img src="' + attachment.url + '" width="150" class="saved-image" style="margin-bottom:12px;" />');
632
 
633
  window.inputWrapper.find( '.wcf-image' ).val( attachment.url );
 
 
 
634
 
635
- // window.inputWrapper.find( '.wcf-image-id' ).val( attachment.id );
636
-
637
- // window.inputWrapper.find( '.wcf-image-value' ).val( attachment.url );
638
-
639
  window.inputWrapper.find('.wcf-remove-image').show();
640
  });
641
 
@@ -651,7 +653,8 @@
651
 
652
  closeRow.find( '#wcf-image-preview img' ).hide();
653
  closeRow.find( '.wcf-image-id' ).val('');
654
- closeRow.find( '.wcf-image' ).val('');
 
655
  button.hide();
656
 
657
  });
631
  window.inputWrapper.find( '#wcf-image-preview' ).append('<img src="' + attachment.url + '" width="150" class="saved-image" style="margin-bottom:12px;" />');
632
 
633
  window.inputWrapper.find( '.wcf-image' ).val( attachment.url );
634
+
635
+ //image obj.
636
+ var size = Object.keys(attachment).length;
637
 
638
+ if(size > 0){
639
+ window.inputWrapper.find( '.wcf-image-obj' ).val( JSON.stringify(attachment) );
640
+ }
 
641
  window.inputWrapper.find('.wcf-remove-image').show();
642
  });
643
 
653
 
654
  closeRow.find( '#wcf-image-preview img' ).hide();
655
  closeRow.find( '.wcf-image-id' ).val('');
656
+ closeRow.find( '.wcf-image' ).val('');
657
+ closeRow.find('.wcf-image-obj').val('');
658
  button.hide();
659
 
660
  });
assets/js/frontend.js CHANGED
@@ -44,11 +44,11 @@
44
  var initial_checkout_event = cartflows.fb_active['facebook_pixel_initiate_checkout'];
45
  var purchase_event = cartflows.fb_active['facebook_pixel_purchase_complete'];
46
  var add_payment_info_event = cartflows.fb_active['facebook_pixel_add_payment_info'];
 
47
  var is_checkout_page = cartflows.is_checkout_page;
48
 
49
  fbq('init', facebook_pixel);
50
  fbq('track', 'PageView', {'plugin': 'CartFlows'});
51
-
52
  if ('enable' === initial_checkout_event) {
53
  if ('1' === is_checkout_page) {
54
  fbq('track', 'AddToCart', cartflows.params);
@@ -76,7 +76,7 @@
76
  }
77
 
78
  var trigger_google_events = function(){
79
- console.log('here');
80
  if( cartflows.wcf_ga_active['enable_google_analytics'] === "enable" ){
81
  // Get all required Data
82
  var google_a_id = cartflows.wcf_ga_active['google_analytics_id'];
44
  var initial_checkout_event = cartflows.fb_active['facebook_pixel_initiate_checkout'];
45
  var purchase_event = cartflows.fb_active['facebook_pixel_purchase_complete'];
46
  var add_payment_info_event = cartflows.fb_active['facebook_pixel_add_payment_info'];
47
+ var facebook_pixel_for_site = cartflows.fb_active['facebook_pixel_tracking_for_site'];
48
  var is_checkout_page = cartflows.is_checkout_page;
49
 
50
  fbq('init', facebook_pixel);
51
  fbq('track', 'PageView', {'plugin': 'CartFlows'});
 
52
  if ('enable' === initial_checkout_event) {
53
  if ('1' === is_checkout_page) {
54
  fbq('track', 'AddToCart', cartflows.params);
76
  }
77
 
78
  var trigger_google_events = function(){
79
+
80
  if( cartflows.wcf_ga_active['enable_google_analytics'] === "enable" ){
81
  // Get all required Data
82
  var google_a_id = cartflows.wcf_ga_active['google_analytics_id'];
assets/min-js/frontend.min.js CHANGED
@@ -1 +1 @@
1
- !function(w){w(document).on("click",'a[href*="wcf-next-step"]',function(e){if(e.preventDefault(),void 0===cartflows.is_pb_preview||"1"!=cartflows.is_pb_preview)return window.location.href=cartflows.next_step,!1;e.stopPropagation()}),w(document).on("click",".wcf-next-step-link",function(e){if(void 0!==cartflows.is_pb_preview&&"1"==cartflows.is_pb_preview)return e.preventDefault(),e.stopPropagation(),!1});w(document).ready(function(e){var a=e('a[href*="wcf-next-step"]');0<a.length&&void 0!==cartflows.next_step&&(a.addClass("wcf-next-step-link"),a.attr("href",cartflows.next_step)),function(){if("OceanWP"===cartflows.current_theme&&"default"!==cartflows.page_template){var e=document.getElementById("oceanwp-style-css");null!=e&&e.remove()}}(),"1"!==cartflows.is_pb_preview&&(function(){if("enable"===cartflows.fb_active.facebook_pixel_tracking&&""!=cartflows.fb_active.facebook_pixel_id){var e=cartflows.fb_active.facebook_pixel_id,a=cartflows.fb_active.facebook_pixel_initiate_checkout,t=cartflows.fb_active.facebook_pixel_purchase_complete,c=cartflows.fb_active.facebook_pixel_add_payment_info,o=cartflows.is_checkout_page;if(fbq("init",e),fbq("track","PageView",{plugin:"CartFlows"}),"enable"===a&&"1"===o&&(fbq("track","AddToCart",cartflows.params),fbq("track","InitiateCheckout",cartflows.params)),"enable"===t){var n=w.cookie("wcf_order_details");void 0!==n&&(fbq("track","Purchase",jQuery.parseJSON(n)),w.removeCookie("wcf_order_details",{path:"/"}))}"enable"===c&&jQuery("form.woocommerce-checkout").on("submit",function(){var e=cartflows.params;fbq("track","AddPaymentInfo",e)})}}(),function(){if("enable"===cartflows.wcf_ga_active.enable_google_analytics){var e=cartflows.wcf_ga_active.google_analytics_id,a=cartflows.wcf_ga_active.enable_google_analytics_for_site,t=cartflows.wcf_ga_active.enable_begin_checkout,c=cartflows.wcf_ga_active.enable_add_payment_info,o=cartflows.wcf_ga_active.enable_purchase_event,n=cartflows.wcf_ga_active.enable_add_to_cart,i=w.cookie("wcf_ga_trans_data"),r=jQuery.parseJSON(i),_=cartflows.is_checkout_page;if("disable"===a&&gtag("event","page_view",{send_to:e,non_interaction:!0}),"1"===_){var f=cartflows.ga_param,s={send_to:e,event_category:"ecommerce",items:f,non_interaction:!0};"enable"===t&&gtag("event","begin_checkout",s),"enable"===n&&gtag("event","add_to_cart",s),"enable"===c&&jQuery("form.woocommerce-checkout").on("submit",function(){gtag("event","add_payment_info",{send_to:e,non_interaction:!0})})}if(void 0!==i){var l={send_to:e,event_category:"ecommerce",transaction_id:r.transaction_id,value:r.value,currency:r.currency,shipping:r.shipping,tax:r.tax,items:r.items,non_interaction:!0};"enable"===o&&(gtag("event","purchase",l),w.removeCookie("wcf_ga_trans_data",{path:"/"}))}}}())})}(jQuery);
1
+ !function(w){w(document).on("click",'a[href*="wcf-next-step"]',function(e){if(e.preventDefault(),void 0===cartflows.is_pb_preview||"1"!=cartflows.is_pb_preview)return window.location.href=cartflows.next_step,!1;e.stopPropagation()}),w(document).on("click",".wcf-next-step-link",function(e){if(void 0!==cartflows.is_pb_preview&&"1"==cartflows.is_pb_preview)return e.preventDefault(),e.stopPropagation(),!1});w(document).ready(function(e){var a=e('a[href*="wcf-next-step"]');0<a.length&&void 0!==cartflows.next_step&&(a.addClass("wcf-next-step-link"),a.attr("href",cartflows.next_step)),function(){if("OceanWP"===cartflows.current_theme&&"default"!==cartflows.page_template){var e=document.getElementById("oceanwp-style-css");null!=e&&e.remove()}}(),"1"!==cartflows.is_pb_preview&&(function(){if("enable"===cartflows.fb_active.facebook_pixel_tracking&&""!=cartflows.fb_active.facebook_pixel_id){var e=cartflows.fb_active.facebook_pixel_id,a=cartflows.fb_active.facebook_pixel_initiate_checkout,t=cartflows.fb_active.facebook_pixel_purchase_complete,c=cartflows.fb_active.facebook_pixel_add_payment_info,o=(cartflows.fb_active.facebook_pixel_tracking_for_site,cartflows.is_checkout_page);if(fbq("init",e),fbq("track","PageView",{plugin:"CartFlows"}),"enable"===a&&"1"===o&&(fbq("track","AddToCart",cartflows.params),fbq("track","InitiateCheckout",cartflows.params)),"enable"===t){var n=w.cookie("wcf_order_details");void 0!==n&&(fbq("track","Purchase",jQuery.parseJSON(n)),w.removeCookie("wcf_order_details",{path:"/"}))}"enable"===c&&jQuery("form.woocommerce-checkout").on("submit",function(){var e=cartflows.params;fbq("track","AddPaymentInfo",e)})}}(),function(){if("enable"===cartflows.wcf_ga_active.enable_google_analytics){var e=cartflows.wcf_ga_active.google_analytics_id,a=cartflows.wcf_ga_active.enable_google_analytics_for_site,t=cartflows.wcf_ga_active.enable_begin_checkout,c=cartflows.wcf_ga_active.enable_add_payment_info,o=cartflows.wcf_ga_active.enable_purchase_event,n=cartflows.wcf_ga_active.enable_add_to_cart,i=w.cookie("wcf_ga_trans_data"),r=jQuery.parseJSON(i),_=cartflows.is_checkout_page;if("disable"===a&&gtag("event","page_view",{send_to:e,non_interaction:!0}),"1"===_){var f=cartflows.ga_param,s={send_to:e,event_category:"ecommerce",items:f,non_interaction:!0};"enable"===t&&gtag("event","begin_checkout",s),"enable"===n&&gtag("event","add_to_cart",s),"enable"===c&&jQuery("form.woocommerce-checkout").on("submit",function(){gtag("event","add_payment_info",{send_to:e,non_interaction:!0})})}if(void 0!==i){var l={send_to:e,event_category:"ecommerce",transaction_id:r.transaction_id,value:r.value,currency:r.currency,shipping:r.shipping,tax:r.tax,items:r.items,non_interaction:!0};"enable"===o&&(gtag("event","purchase",l),w.removeCookie("wcf_ga_trans_data",{path:"/"}))}}}())})}(jQuery);
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.5.1
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.5.2
7
  * Author: CartFlows Inc
8
  * Author URI: https://cartflows.com/
9
  * Text Domain: cartflows
changelog.txt CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
  Version 1.5.1 - Thursday, 12th March 2020
2
  - Improvement: WooCommerce version 4.0.0 compatibility tested.
3
 
1
+ Version 1.5.2 - Wednesday, 18th March 2020
2
+ - New: Added an option to enable Facebook pixel's Pageview event on the whole site.
3
+ - Improvement: Added compatibility for the Pro theme.
4
+ - Improvement: Added compatibility for the Kallyas theme.
5
+ - Improvement: Added compatibility for a future release of CartFlows Pro.
6
+ - Fix: Dynamic CSS was not working properly in some DIVI cases.
7
+
8
  Version 1.5.1 - Thursday, 12th March 2020
9
  - Improvement: WooCommerce version 4.0.0 compatibility tested.
10
 
classes/class-cartflows-admin.php CHANGED
@@ -1,653 +1,653 @@
1
- <?php
2
- /**
3
- * CartFlows Admin.
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class Cartflows_Admin.
10
- */
11
- class Cartflows_Admin {
12
-
13
- /**
14
- * Calls on initialization
15
- *
16
- * @since 1.0.0
17
- */
18
- public static function init() {
19
-
20
- self::initialise_plugin();
21
- self::init_hooks();
22
- }
23
-
24
- /**
25
- * Init Hooks.
26
- *
27
- * @since 1.0.0
28
- * @return void
29
- */
30
- public static function init_hooks() {
31
-
32
- if ( ! is_admin() ) {
33
- return;
34
- }
35
-
36
- include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-fields.php';
37
-
38
- /*
39
- Add CARTFLOWS menu option to admin.
40
- add_action( 'network_admin_menu', __CLASS__ . '::menu' );
41
- */
42
- add_action( 'admin_menu', __CLASS__ . '::menu' );
43
- add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
44
-
45
- add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
46
-
47
- add_action( 'admin_init', __CLASS__ . '::settings_admin_scripts' );
48
-
49
- /* Global Addmin Script */
50
- add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
51
-
52
- add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
53
-
54
- /* Add lite version class to body */
55
- add_action( 'admin_body_class', __CLASS__ . '::add_admin_body_class' );
56
-
57
- add_filter( 'plugin_action_links_' . CARTFLOWS_BASE, __CLASS__ . '::add_action_links' );
58
-
59
- add_action( 'admin_init', __CLASS__ . '::cartflows_after_save_permalinks' );
60
-
61
- }
62
-
63
- /**
64
- * After save of permalinks.
65
- */
66
- public static function cartflows_after_save_permalinks() {
67
-
68
- $has_saved_permalinks = get_option( 'cartflows_permalink_saved' );
69
- if ( $has_saved_permalinks ) {
70
- flush_rewrite_rules();
71
- delete_option( 'cartflows_permalink_saved' );
72
- }
73
- }
74
-
75
-
76
- /**
77
- * Initialize after Cartflows pro get loaded.
78
- */
79
- public static function settings_admin_scripts() {
80
- // Enqueue admin scripts.
81
- if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS === $_REQUEST['page'] ) { //phpcs:ignore
82
- add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
83
-
84
- self::save_settings();
85
- }
86
- }
87
- /**
88
- * Show action on plugin page.
89
- *
90
- * @param array $links links.
91
- * @return array
92
- */
93
- public static function add_action_links( $links ) {
94
- $mylinks = array(
95
- '<a href="' . admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS ) . '">Settings</a>',
96
- '<a target="_blank" href="' . esc_url( 'https://cartflows.com/docs' ) . '">Docs</a>',
97
- );
98
-
99
- if ( ! _is_cartflows_pro() ) {
100
- array_push( $mylinks, '<a style="color: #39b54a; font-weight: bold;" target="_blank" href="' . esc_url( 'https://cartflows.com/pricing/' ) . '"> Go Pro </a>' );
101
- }
102
-
103
- return array_merge( $links, $mylinks );
104
- }
105
-
106
- /**
107
- * Initialises the Plugin Name.
108
- *
109
- * @since 1.0.0
110
- * @return void
111
- */
112
- public static function initialise_plugin() {
113
-
114
- $name = 'Cartflows';
115
- $short_name = 'Cflows';
116
-
117
- define( 'CARTFLOWS_PLUGIN_NAME', $name );
118
- define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
119
- }
120
-
121
- /**
122
- * Renders the admin settings menu.
123
- *
124
- * @since 1.0.0
125
- * @return void
126
- */
127
- public static function menu() {
128
-
129
- if ( ! current_user_can( 'manage_options' ) ) {
130
- return;
131
- }
132
-
133
- add_menu_page(
134
- 'CartFlows',
135
- 'CartFlows',
136
- 'manage_options',
137
- CARTFLOWS_SLUG,
138
- __CLASS__ . '::render',
139
- 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),//phpcs:ignore
140
- 39.7
141
- );
142
-
143
- }
144
-
145
- /**
146
- * Add submenu to admin menu.
147
- *
148
- * @since 1.0.0
149
- */
150
- public static function submenu() {
151
-
152
- $parent_slug = CARTFLOWS_SLUG;
153
- $page_title = __( 'Settings', 'cartflows' );
154
- $menu_title = __( 'Settings', 'cartflows' );
155
- $capability = 'manage_options';
156
- $menu_slug = 'cartflows_settings';
157
- $callback = __CLASS__ . '::render';
158
-
159
- add_submenu_page(
160
- $parent_slug,
161
- $page_title,
162
- $menu_title,
163
- $capability,
164
- $menu_slug,
165
- $callback
166
- );
167
- }
168
-
169
- /**
170
- * Renders the admin settings.
171
- *
172
- * @since 1.0.0
173
- * @return void
174
- */
175
- public static function render() {
176
- $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
177
- $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
178
- $action = str_replace( '_', '-', $action );
179
-
180
- // Enable header icon filter below.
181
- $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
182
-
183
- include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
184
- }
185
-
186
- /**
187
- * Renders the admin settings content.
188
- *
189
- * @since 1.0.0
190
- * @return void
191
- */
192
- public static function render_content() {
193
-
194
- $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
195
- $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
196
- $action = str_replace( '_', '-', $action );
197
- $action = 'general';
198
-
199
- $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
200
-
201
- include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
202
- }
203
-
204
- /**
205
- * Save Global Setting options.
206
- *
207
- * @since 1.0.0
208
- */
209
- public static function save_common_settings() {
210
-
211
- if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-common-settings-nonce'] ) ), 'cartflows-common-settings' ) ) {
212
-
213
- $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
214
- $new_settings = array();
215
-
216
- if ( isset( $_POST['_cartflows_common'] ) ) {
217
- // Loop through the input and sanitize each of the values.
218
- $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_common'] ) ); //phpcs:ignore
219
- }
220
-
221
- Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, false );
222
-
223
- $query = array(
224
- 'message' => 'saved',
225
- );
226
-
227
- $redirect_to = add_query_arg( $query, $url );
228
-
229
- wp_safe_redirect( $redirect_to );
230
- exit;
231
- } // End if statement.
232
- }
233
-
234
- /**
235
- * Save Debug Setting options.
236
- *
237
- * @since 1.1.14
238
- */
239
- public static function save_debug_settings() {
240
-
241
- if ( isset( $_POST['cartflows-debug-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-debug-settings-nonce'] ) ), 'cartflows-debug-settings' ) ) {
242
-
243
- $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
244
- $new_settings = array();
245
-
246
- if ( isset( $_POST['_cartflows_debug_data'] ) ) {
247
- $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_debug_data'] ) ); //phpcs:ignore
248
- }
249
-
250
- Cartflows_Helper::update_admin_settings_option( '_cartflows_debug_data', $new_settings, false );
251
-
252
- $query = array(
253
- 'message' => 'saved',
254
- );
255
-
256
- $redirect_to = add_query_arg( $query, $url );
257
-
258
- wp_safe_redirect( $redirect_to );
259
- exit;
260
-
261
- }
262
- }
263
-
264
-
265
- /**
266
- * Save permalink Setting options.
267
- *
268
- * @since 1.1.14
269
- */
270
- public static function save_permalink_settings() {
271
-
272
- if ( isset( $_POST['cartflows-permalink-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-permalink-settings-nonce'] ) ), 'cartflows-permalink-settings' ) ) {
273
-
274
- $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
275
- $new_settings = array();
276
-
277
- if ( isset( $_POST['reset'] ) ) {
278
- $_POST['_cartflows_permalink'] = array(
279
- 'permalink' => CARTFLOWS_STEP_POST_TYPE,
280
- 'permalink_flow_base' => CARTFLOWS_FLOW_POST_TYPE,
281
- 'permalink_structure' => '',
282
- );
283
-
284
- }
285
-
286
- if ( isset( $_POST['_cartflows_permalink'] ) ) {
287
- $cartflows_permalink_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_permalink'] ) ); //phpcs:ignore
288
-
289
- if ( empty( $cartflows_permalink_settings['permalink'] ) ) {
290
- $new_settings['permalink'] = CARTFLOWS_STEP_POST_TYPE;
291
- } else {
292
- $new_settings['permalink'] = $cartflows_permalink_settings['permalink'];
293
- }
294
-
295
- if ( empty( $cartflows_permalink_settings['permalink_flow_base'] ) ) {
296
- $new_settings['permalink_flow_base'] = CARTFLOWS_FLOW_POST_TYPE;
297
- } else {
298
- $new_settings['permalink_flow_base'] = $cartflows_permalink_settings['permalink_flow_base'];
299
- }
300
-
301
- $new_settings['permalink_structure'] = $cartflows_permalink_settings['permalink_structure'];
302
-
303
- }
304
-
305
- Cartflows_Helper::update_admin_settings_option( '_cartflows_permalink', $new_settings, false );
306
-
307
- $query = array(
308
- 'message' => 'saved',
309
- );
310
-
311
- $redirect_to = add_query_arg( $query, $url );
312
-
313
- update_option( 'cartflows_permalink_saved', true );
314
-
315
- wp_safe_redirect( $redirect_to );
316
- exit;
317
-
318
- }
319
- }
320
-
321
- /**
322
- * Save google analytics Setting options.
323
- *
324
- * @since 1.1.14
325
- */
326
- public static function save_google_analytics_settings() {
327
-
328
- if ( isset( $_POST['cartflows-google-analytics-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-google-analytics-settings-nonce'] ) ), 'cartflows-google-analytics-settings' ) ) {
329
-
330
- $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
331
- $new_settings = array();
332
-
333
- if ( isset( $_POST['_cartflows_google_analytics'] ) ) {
334
- $new_settings = self::sanitize_form_inputs( $_POST['_cartflows_google_analytics'] ); //phpcs:ignore
335
-
336
- }
337
-
338
- Cartflows_Helper::update_admin_settings_option( '_cartflows_google_analytics', $new_settings, true );
339
-
340
- $query = array(
341
- 'message' => 'saved',
342
- );
343
-
344
- $redirect_to = add_query_arg( $query, $url );
345
-
346
- wp_safe_redirect( $redirect_to );
347
- exit;
348
-
349
- }
350
- }
351
-
352
- /**
353
- * Loop through the input and sanitize each of the values.
354
- *
355
- * @param array $input_settings input settings.
356
- * @return array
357
- */
358
- public static function sanitize_form_inputs( $input_settings = array() ) {
359
- $new_settings = array();
360
- foreach ( $input_settings as $key => $val ) {
361
-
362
- if ( is_array( $val ) ) {
363
- foreach ( $val as $k => $v ) {
364
- $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
365
- }
366
- } else {
367
- $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
368
- }
369
- }
370
- return $new_settings;
371
- }
372
-
373
- /**
374
- * Check is cartflows admin.
375
- *
376
- * @since 1.0.0
377
- * @return boolean
378
- */
379
- public static function is_global_admin() {
380
-
381
- $current_screen = get_current_screen();
382
-
383
- if (
384
- is_object( $current_screen ) &&
385
- isset( $current_screen->post_type ) &&
386
- ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
387
- CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
388
- )
389
- ) {
390
- return true;
391
- }
392
- return false;
393
- }
394
-
395
- /**
396
- * Check is flow admin.
397
- *
398
- * @since 1.0.0
399
- * @return boolean
400
- */
401
- public static function is_flow_edit_admin() {
402
-
403
- $current_screen = get_current_screen();
404
-
405
- if (
406
- is_object( $current_screen ) &&
407
- isset( $current_screen->post_type ) &&
408
- ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
409
- isset( $current_screen->base ) &&
410
- ( 'post' === $current_screen->base )
411
- ) {
412
- return true;
413
- }
414
- return false;
415
- }
416
-
417
- /**
418
- * Global Admin Scripts.
419
- *
420
- * @since 1.0.0
421
- */
422
- public static function global_admin_scripts() {
423
-
424
- $installed_plugins = get_plugins();
425
- $is_wc_installed = isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? true : false;
426
- $edit_test_mode = filter_input( INPUT_GET, 'edit_test_mode', FILTER_SANITIZE_STRING );
427
- $edit_test_mode = 'yes' === $edit_test_mode ? true : false;
428
-
429
- $localize = array(
430
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
431
- 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
432
- 'wc_status' => array(
433
- 'installed' => $is_wc_installed,
434
- 'active' => wcf()->is_woo_active,
435
- ),
436
- 'wc_activating_message' => __( 'Installing and activating..', 'cartflows' ),
437
- 'wc_install_error' => __( 'There was an error with the installation of plugin.', 'cartflows' ),
438
- 'wcf_edit_test_mode' => $edit_test_mode,
439
- );
440
-
441
- wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
442
-
443
- if ( self::is_global_admin() ) {
444
-
445
- // Styles.
446
- wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
447
- wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
448
-
449
- wp_enqueue_script(
450
- 'wcf-global-admin',
451
- CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
452
- array( 'jquery' ),
453
- CARTFLOWS_VER,
454
- true
455
- );
456
-
457
- do_action( 'cartflows_global_admin_scripts' );
458
- }
459
- }
460
-
461
- /**
462
- * Global Admin Data.
463
- *
464
- * @since 1.0.0
465
- */
466
- public static function global_admin_data() {
467
-
468
- $current_screen = get_current_screen();
469
-
470
- if ( ! $current_screen ) {
471
- return;
472
- }
473
-
474
- if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) {
475
- return;
476
- }
477
-
478
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
479
- ?>
480
-
481
- <div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
482
- <div class="wcf-templates-popup-content">
483
- <div class="spinner"></div>
484
- <div class="wcf-templates-wrap wcf-templates-wrap-flows">
485
-
486
- <div id="wcf-remote-flow-actions" class="wcf-template-header">
487
- <div class="wcf-template-logo-wrap">
488
- <span class="wcf-cartflows-logo-img">
489
- <span class="cartflows-logo-icon"></span>
490
- </span>
491
- <span class="wcf-cartflows-title"><?php esc_html_e( 'Flows Library', 'cartflows' ); ?></span>
492
- </div>
493
- <div class="wcf-tab-wrapper">
494
- <?php if ( 'other' !== $default_page_builder ) { ?>
495
- <div id="wcf-get-started-steps">
496
- <ul class="filter-links ">
497
- <li>
498
- <a href="#" class="current" data-slug="ready-templates" data-title="<?php esc_html_e( 'Ready Templates', 'cartflows' ); ?>"><?php esc_html_e( 'Ready Templates', 'cartflows' ); ?></a>
499
- </li>
500
- <li>
501
- <a href="#" data-slug="canvas" data-title="<?php esc_html_e( 'Create Your Own', 'cartflows' ); ?>"><?php esc_html_e( 'Create Your Own', 'cartflows' ); ?></a>
502
- </li>
503
- </ul>
504
- </div>
505
- <?php } ?>
506
- </div>
507
- <div class="wcf-popup-close-wrap">
508
- <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
509
- </div>
510
- </div>
511
- <!-- <div class="wcf-search-form">
512
- <label class="screen-reader-text" for="wp-filter-search-input"><?php esc_html_e( 'Search Sites', 'cartflows' ); ?> </label>
513
- <input placeholder="<?php esc_html_e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
514
- </div> -->
515
-
516
- <div id="wcf-remote-content">
517
- <?php if ( 'other' !== $default_page_builder ) { ?>
518
- <div id="wcf-ready-templates">
519
- <div id="wcf-remote-filters">
520
- <div id="wcf-page-builders"></div>
521
- <div id="wcf-categories"></div>
522
- </div>
523
- <div class="wcf-page-builder-notice"></div>
524
- <div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
525
- <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
526
- </div>
527
- <?php } ?>
528
- <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
529
- <div class="inner">
530
- <a href="#" class="button button-hero button-primary cartflows-flow-import-blank"><?php esc_html_e( 'Design Your Flow', 'cartflows' ); ?></a>
531
- <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php esc_html_e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
532
- </div>
533
- </div>
534
- </div>
535
- </div>
536
- </div>
537
- </div>
538
-
539
- <?php
540
- }
541
-
542
- /**
543
- * Enqueues the needed CSS/JS for the builder's admin settings page.
544
- *
545
- * @since 1.0.0
546
- */
547
- public static function styles_scripts() {
548
-
549
- // Styles.
550
- wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
551
- wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
552
-
553
- // Script.
554
- wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER, false );
555
-
556
- $localize = array(
557
- 'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
558
- );
559
-
560
- wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
561
-
562
- do_action( 'cartflows_admin_settings_after_enqueue_scripts' );
563
- }
564
-
565
- /**
566
- * Save All admin settings here
567
- */
568
- public static function save_settings() {
569
-
570
- // Only admins can save settings.
571
- if ( ! current_user_can( 'manage_options' ) ) {
572
- return;
573
- }
574
-
575
- self::save_common_settings();
576
- self::save_debug_settings();
577
- self::save_permalink_settings();
578
-
579
- self::save_google_analytics_settings();
580
- self::save_facebook_settings();
581
-
582
- // Let extensions hook into saving.
583
- do_action( 'cartflows_admin_settings_save' );
584
- }
585
-
586
- /**
587
- * Get and return page URL
588
- *
589
- * @param string $menu_slug Menu name.
590
- * @since 1.0.0
591
- * @return string page url
592
- */
593
- public static function get_page_url( $menu_slug ) {
594
-
595
- $parent_page = self::$default_menu_position;
596
-
597
- if ( strpos( $parent_page, '?' ) !== false ) {
598
- $query_var = '&page=' . self::$plugin_slug;
599
- } else {
600
- $query_var = '?page=' . self::$plugin_slug;
601
- }
602
-
603
- $parent_page_url = admin_url( $parent_page . $query_var );
604
-
605
- $url = $parent_page_url . '&action=' . $menu_slug;
606
-
607
- return esc_url( $url );
608
- }
609
-
610
- /**
611
- * Admin body classes.
612
- *
613
- * Body classes to be added to <body> tag in admin page
614
- *
615
- * @param String $classes body classes returned from the filter.
616
- * @return String body classes to be added to <body> tag in admin page
617
- */
618
- public static function add_admin_body_class( $classes ) {
619
-
620
- $classes .= ' cartflows-' . CARTFLOWS_VER;
621
-
622
- return $classes;
623
- }
624
-
625
- /**
626
- * Save Global Setting options.
627
- *
628
- * @since 1.0.0
629
- */
630
- public static function save_facebook_settings() {
631
-
632
- if ( isset( $_POST['cartflows-facebook-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-facebook-settings-nonce'] ) ), 'cartflows-facebook-settings' ) ) {
633
-
634
- $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
635
- $new_settings = array();
636
-
637
- if ( isset( $_POST['_cartflows_facebook'] ) ) {
638
- $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_facebook'] ) ); //phpcs:ignore
639
- }
640
-
641
- Cartflows_Helper::update_admin_settings_option( '_cartflows_facebook', $new_settings, false );
642
- $query = array(
643
- 'message' => 'saved',
644
- );
645
- $redirect_to = add_query_arg( $query, $url );
646
- wp_safe_redirect( $redirect_to );
647
- exit;
648
- }
649
- }
650
-
651
- }
652
-
653
- Cartflows_Admin::init();
1
+ <?php
2
+ /**
3
+ * CartFlows Admin.
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class Cartflows_Admin.
10
+ */
11
+ class Cartflows_Admin {
12
+
13
+ /**
14
+ * Calls on initialization
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ public static function init() {
19
+
20
+ self::initialise_plugin();
21
+ self::init_hooks();
22
+ }
23
+
24
+ /**
25
+ * Init Hooks.
26
+ *
27
+ * @since 1.0.0
28
+ * @return void
29
+ */
30
+ public static function init_hooks() {
31
+
32
+ if ( ! is_admin() ) {
33
+ return;
34
+ }
35
+
36
+ include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin-fields.php';
37
+
38
+ /*
39
+ Add CARTFLOWS menu option to admin.
40
+ add_action( 'network_admin_menu', __CLASS__ . '::menu' );
41
+ */
42
+ add_action( 'admin_menu', __CLASS__ . '::menu' );
43
+ add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
44
+
45
+ add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
46
+
47
+ add_action( 'admin_init', __CLASS__ . '::settings_admin_scripts' );
48
+
49
+ /* Global Addmin Script */
50
+ add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
51
+
52
+ add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
53
+
54
+ /* Add lite version class to body */
55
+ add_action( 'admin_body_class', __CLASS__ . '::add_admin_body_class' );
56
+
57
+ add_filter( 'plugin_action_links_' . CARTFLOWS_BASE, __CLASS__ . '::add_action_links' );
58
+
59
+ add_action( 'admin_init', __CLASS__ . '::cartflows_after_save_permalinks' );
60
+
61
+ }
62
+
63
+ /**
64
+ * After save of permalinks.
65
+ */
66
+ public static function cartflows_after_save_permalinks() {
67
+
68
+ $has_saved_permalinks = get_option( 'cartflows_permalink_saved' );
69
+ if ( $has_saved_permalinks ) {
70
+ flush_rewrite_rules();
71
+ delete_option( 'cartflows_permalink_saved' );
72
+ }
73
+ }
74
+
75
+
76
+ /**
77
+ * Initialize after Cartflows pro get loaded.
78
+ */
79
+ public static function settings_admin_scripts() {
80
+ // Enqueue admin scripts.
81
+ if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS === $_REQUEST['page'] ) { //phpcs:ignore
82
+ add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
83
+
84
+ self::save_settings();
85
+ }
86
+ }
87
+ /**
88
+ * Show action on plugin page.
89
+ *
90
+ * @param array $links links.
91
+ * @return array
92
+ */
93
+ public static function add_action_links( $links ) {
94
+ $mylinks = array(
95
+ '<a href="' . admin_url( 'admin.php?page=' . CARTFLOWS_SETTINGS ) . '">Settings</a>',
96
+ '<a target="_blank" href="' . esc_url( 'https://cartflows.com/docs' ) . '">Docs</a>',
97
+ );
98
+
99
+ if ( ! _is_cartflows_pro() ) {
100
+ array_push( $mylinks, '<a style="color: #39b54a; font-weight: bold;" target="_blank" href="' . esc_url( 'https://cartflows.com/pricing/' ) . '"> Go Pro </a>' );
101
+ }
102
+
103
+ return array_merge( $links, $mylinks );
104
+ }
105
+
106
+ /**
107
+ * Initialises the Plugin Name.
108
+ *
109
+ * @since 1.0.0
110
+ * @return void
111
+ */
112
+ public static function initialise_plugin() {
113
+
114
+ $name = 'Cartflows';
115
+ $short_name = 'Cflows';
116
+
117
+ define( 'CARTFLOWS_PLUGIN_NAME', $name );
118
+ define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
119
+ }
120
+
121
+ /**
122
+ * Renders the admin settings menu.
123
+ *
124
+ * @since 1.0.0
125
+ * @return void
126
+ */
127
+ public static function menu() {
128
+
129
+ if ( ! current_user_can( 'manage_options' ) ) {
130
+ return;
131
+ }
132
+
133
+ add_menu_page(
134
+ 'CartFlows',
135
+ 'CartFlows',
136
+ 'manage_options',
137
+ CARTFLOWS_SLUG,
138
+ __CLASS__ . '::render',
139
+ 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),//phpcs:ignore
140
+ 39.7
141
+ );
142
+
143
+ }
144
+
145
+ /**
146
+ * Add submenu to admin menu.
147
+ *
148
+ * @since 1.0.0
149
+ */
150
+ public static function submenu() {
151
+
152
+ $parent_slug = CARTFLOWS_SLUG;
153
+ $page_title = __( 'Settings', 'cartflows' );
154
+ $menu_title = __( 'Settings', 'cartflows' );
155
+ $capability = 'manage_options';
156
+ $menu_slug = 'cartflows_settings';
157
+ $callback = __CLASS__ . '::render';
158
+
159
+ add_submenu_page(
160
+ $parent_slug,
161
+ $page_title,
162
+ $menu_title,
163
+ $capability,
164
+ $menu_slug,
165
+ $callback
166
+ );
167
+ }
168
+
169
+ /**
170
+ * Renders the admin settings.
171
+ *
172
+ * @since 1.0.0
173
+ * @return void
174
+ */
175
+ public static function render() {
176
+ $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
177
+ $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
178
+ $action = str_replace( '_', '-', $action );
179
+
180
+ // Enable header icon filter below.
181
+ $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
182
+
183
+ include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
184
+ }
185
+
186
+ /**
187
+ * Renders the admin settings content.
188
+ *
189
+ * @since 1.0.0
190
+ * @return void
191
+ */
192
+ public static function render_content() {
193
+
194
+ $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
195
+ $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
196
+ $action = str_replace( '_', '-', $action );
197
+ $action = 'general';
198
+
199
+ $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
200
+
201
+ include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
202
+ }
203
+
204
+ /**
205
+ * Save Global Setting options.
206
+ *
207
+ * @since 1.0.0
208
+ */
209
+ public static function save_common_settings() {
210
+
211
+ if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-common-settings-nonce'] ) ), 'cartflows-common-settings' ) ) {
212
+
213
+ $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
214
+ $new_settings = array();
215
+
216
+ if ( isset( $_POST['_cartflows_common'] ) ) {
217
+ // Loop through the input and sanitize each of the values.
218
+ $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_common'] ) ); //phpcs:ignore
219
+ }
220
+
221
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, false );
222
+
223
+ $query = array(
224
+ 'message' => 'saved',
225
+ );
226
+
227
+ $redirect_to = add_query_arg( $query, $url );
228
+
229
+ wp_safe_redirect( $redirect_to );
230
+ exit;
231
+ } // End if statement.
232
+ }
233
+
234
+ /**
235
+ * Save Debug Setting options.
236
+ *
237
+ * @since 1.1.14
238
+ */
239
+ public static function save_debug_settings() {
240
+
241
+ if ( isset( $_POST['cartflows-debug-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-debug-settings-nonce'] ) ), 'cartflows-debug-settings' ) ) {
242
+
243
+ $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
244
+ $new_settings = array();
245
+
246
+ if ( isset( $_POST['_cartflows_debug_data'] ) ) {
247
+ $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_debug_data'] ) ); //phpcs:ignore
248
+ }
249
+
250
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_debug_data', $new_settings, false );
251
+
252
+ $query = array(
253
+ 'message' => 'saved',
254
+ );
255
+
256
+ $redirect_to = add_query_arg( $query, $url );
257
+
258
+ wp_safe_redirect( $redirect_to );
259
+ exit;
260
+
261
+ }
262
+ }
263
+
264
+
265
+ /**
266
+ * Save permalink Setting options.
267
+ *
268
+ * @since 1.1.14
269
+ */
270
+ public static function save_permalink_settings() {
271
+
272
+ if ( isset( $_POST['cartflows-permalink-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-permalink-settings-nonce'] ) ), 'cartflows-permalink-settings' ) ) {
273
+
274
+ $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
275
+ $new_settings = array();
276
+
277
+ if ( isset( $_POST['reset'] ) ) {
278
+ $_POST['_cartflows_permalink'] = array(
279
+ 'permalink' => CARTFLOWS_STEP_POST_TYPE,
280
+ 'permalink_flow_base' => CARTFLOWS_FLOW_POST_TYPE,
281
+ 'permalink_structure' => '',
282
+ );
283
+
284
+ }
285
+
286
+ if ( isset( $_POST['_cartflows_permalink'] ) ) {
287
+ $cartflows_permalink_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_permalink'] ) ); //phpcs:ignore
288
+
289
+ if ( empty( $cartflows_permalink_settings['permalink'] ) ) {
290
+ $new_settings['permalink'] = CARTFLOWS_STEP_POST_TYPE;
291
+ } else {
292
+ $new_settings['permalink'] = $cartflows_permalink_settings['permalink'];
293
+ }
294
+
295
+ if ( empty( $cartflows_permalink_settings['permalink_flow_base'] ) ) {
296
+ $new_settings['permalink_flow_base'] = CARTFLOWS_FLOW_POST_TYPE;
297
+ } else {
298
+ $new_settings['permalink_flow_base'] = $cartflows_permalink_settings['permalink_flow_base'];
299
+ }
300
+
301
+ $new_settings['permalink_structure'] = $cartflows_permalink_settings['permalink_structure'];
302
+
303
+ }
304
+
305
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_permalink', $new_settings, false );
306
+
307
+ $query = array(
308
+ 'message' => 'saved',
309
+ );
310
+
311
+ $redirect_to = add_query_arg( $query, $url );
312
+
313
+ update_option( 'cartflows_permalink_saved', true );
314
+
315
+ wp_safe_redirect( $redirect_to );
316
+ exit;
317
+
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Save google analytics Setting options.
323
+ *
324
+ * @since 1.1.14
325
+ */
326
+ public static function save_google_analytics_settings() {
327
+
328
+ if ( isset( $_POST['cartflows-google-analytics-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-google-analytics-settings-nonce'] ) ), 'cartflows-google-analytics-settings' ) ) {
329
+
330
+ $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
331
+ $new_settings = array();
332
+
333
+ if ( isset( $_POST['_cartflows_google_analytics'] ) ) {
334
+ $new_settings = self::sanitize_form_inputs( $_POST['_cartflows_google_analytics'] ); //phpcs:ignore
335
+
336
+ }
337
+
338
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_google_analytics', $new_settings, true );
339
+
340
+ $query = array(
341
+ 'message' => 'saved',
342
+ );
343
+
344
+ $redirect_to = add_query_arg( $query, $url );
345
+
346
+ wp_safe_redirect( $redirect_to );
347
+ exit;
348
+
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Loop through the input and sanitize each of the values.
354
+ *
355
+ * @param array $input_settings input settings.
356
+ * @return array
357
+ */
358
+ public static function sanitize_form_inputs( $input_settings = array() ) {
359
+ $new_settings = array();
360
+ foreach ( $input_settings as $key => $val ) {
361
+
362
+ if ( is_array( $val ) ) {
363
+ foreach ( $val as $k => $v ) {
364
+ $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
365
+ }
366
+ } else {
367
+ $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
368
+ }
369
+ }
370
+ return $new_settings;
371
+ }
372
+
373
+ /**
374
+ * Check is cartflows admin.
375
+ *
376
+ * @since 1.0.0
377
+ * @return boolean
378
+ */
379
+ public static function is_global_admin() {
380
+
381
+ $current_screen = get_current_screen();
382
+
383
+ if (
384
+ is_object( $current_screen ) &&
385
+ isset( $current_screen->post_type ) &&
386
+ ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
387
+ CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
388
+ )
389
+ ) {
390
+ return true;
391
+ }
392
+ return false;
393
+ }
394
+
395
+ /**
396
+ * Check is flow admin.
397
+ *
398
+ * @since 1.0.0
399
+ * @return boolean
400
+ */
401
+ public static function is_flow_edit_admin() {
402
+
403
+ $current_screen = get_current_screen();
404
+
405
+ if (
406
+ is_object( $current_screen ) &&
407
+ isset( $current_screen->post_type ) &&
408
+ ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
409
+ isset( $current_screen->base ) &&
410
+ ( 'post' === $current_screen->base )
411
+ ) {
412
+ return true;
413
+ }
414
+ return false;
415
+ }
416
+
417
+ /**
418
+ * Global Admin Scripts.
419
+ *
420
+ * @since 1.0.0
421
+ */
422
+ public static function global_admin_scripts() {
423
+
424
+ $installed_plugins = get_plugins();
425
+ $is_wc_installed = isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? true : false;
426
+ $edit_test_mode = filter_input( INPUT_GET, 'edit_test_mode', FILTER_SANITIZE_STRING );
427
+ $edit_test_mode = 'yes' === $edit_test_mode ? true : false;
428
+
429
+ $localize = array(
430
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
431
+ 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
432
+ 'wc_status' => array(
433
+ 'installed' => $is_wc_installed,
434
+ 'active' => wcf()->is_woo_active,
435
+ ),
436
+ 'wc_activating_message' => __( 'Installing and activating..', 'cartflows' ),
437
+ 'wc_install_error' => __( 'There was an error with the installation of plugin.', 'cartflows' ),
438
+ 'wcf_edit_test_mode' => $edit_test_mode,
439
+ );
440
+
441
+ wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
442
+
443
+ if ( self::is_global_admin() ) {
444
+
445
+ // Styles.
446
+ wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
447
+ wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
448
+
449
+ wp_enqueue_script(
450
+ 'wcf-global-admin',
451
+ CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
452
+ array( 'jquery' ),
453
+ CARTFLOWS_VER,
454
+ true
455
+ );
456
+
457
+ do_action( 'cartflows_global_admin_scripts' );
458
+ }
459
+ }
460
+
461
+ /**
462
+ * Global Admin Data.
463
+ *
464
+ * @since 1.0.0
465
+ */
466
+ public static function global_admin_data() {
467
+
468
+ $current_screen = get_current_screen();
469
+
470
+ if ( ! $current_screen ) {
471
+ return;
472
+ }
473
+
474
+ if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) {
475
+ return;
476
+ }
477
+
478
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
479
+ ?>
480
+
481
+ <div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
482
+ <div class="wcf-templates-popup-content">
483
+ <div class="spinner"></div>
484
+ <div class="wcf-templates-wrap wcf-templates-wrap-flows">
485
+
486
+ <div id="wcf-remote-flow-actions" class="wcf-template-header">
487
+ <div class="wcf-template-logo-wrap">
488
+ <span class="wcf-cartflows-logo-img">
489
+ <span class="cartflows-logo-icon"></span>
490
+ </span>
491
+ <span class="wcf-cartflows-title"><?php esc_html_e( 'Flows Library', 'cartflows' ); ?></span>
492
+ </div>
493
+ <div class="wcf-tab-wrapper">
494
+ <?php if ( 'other' !== $default_page_builder ) { ?>
495
+ <div id="wcf-get-started-steps">
496
+ <ul class="filter-links ">
497
+ <li>
498
+ <a href="#" class="current" data-slug="ready-templates" data-title="<?php esc_html_e( 'Ready Templates', 'cartflows' ); ?>"><?php esc_html_e( 'Ready Templates', 'cartflows' ); ?></a>
499
+ </li>
500
+ <li>
501
+ <a href="#" data-slug="canvas" data-title="<?php esc_html_e( 'Create Your Own', 'cartflows' ); ?>"><?php esc_html_e( 'Create Your Own', 'cartflows' ); ?></a>
502
+ </li>
503
+ </ul>
504
+ </div>
505
+ <?php } ?>
506
+ </div>
507
+ <div class="wcf-popup-close-wrap">
508
+ <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
509
+ </div>
510
+ </div>
511
+ <!-- <div class="wcf-search-form">
512
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php esc_html_e( 'Search Sites', 'cartflows' ); ?> </label>
513
+ <input placeholder="<?php esc_html_e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
514
+ </div> -->
515
+
516
+ <div id="wcf-remote-content">
517
+ <?php if ( 'other' !== $default_page_builder ) { ?>
518
+ <div id="wcf-ready-templates">
519
+ <div id="wcf-remote-filters">
520
+ <div id="wcf-page-builders"></div>
521
+ <div id="wcf-categories"></div>
522
+ </div>
523
+ <div class="wcf-page-builder-notice"></div>
524
+ <div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
525
+ <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
526
+ </div>
527
+ <?php } ?>
528
+ <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
529
+ <div class="inner">
530
+ <a href="#" class="button button-hero button-primary cartflows-flow-import-blank"><?php esc_html_e( 'Design Your Flow', 'cartflows' ); ?></a>
531
+ <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php esc_html_e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
532
+ </div>
533
+ </div>
534
+ </div>
535
+ </div>
536
+ </div>
537
+ </div>
538
+
539
+ <?php
540
+ }
541
+
542
+ /**
543
+ * Enqueues the needed CSS/JS for the builder's admin settings page.
544
+ *
545
+ * @since 1.0.0
546
+ */
547
+ public static function styles_scripts() {
548
+
549
+ // Styles.
550
+ wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
551
+ wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
552
+
553
+ // Script.
554
+ wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER, false );
555
+
556
+ $localize = array(
557
+ 'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
558
+ );
559
+
560
+ wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
561
+
562
+ do_action( 'cartflows_admin_settings_after_enqueue_scripts' );
563
+ }
564
+
565
+ /**
566
+ * Save All admin settings here
567
+ */
568
+ public static function save_settings() {
569
+
570
+ // Only admins can save settings.
571
+ if ( ! current_user_can( 'manage_options' ) ) {
572
+ return;
573
+ }
574
+
575
+ self::save_common_settings();
576
+ self::save_debug_settings();
577
+ self::save_permalink_settings();
578
+
579
+ self::save_google_analytics_settings();
580
+ self::save_facebook_settings();
581
+
582
+ // Let extensions hook into saving.
583
+ do_action( 'cartflows_admin_settings_save' );
584
+ }
585
+
586
+ /**
587
+ * Get and return page URL
588
+ *
589
+ * @param string $menu_slug Menu name.
590
+ * @since 1.0.0
591
+ * @return string page url
592
+ */
593
+ public static function get_page_url( $menu_slug ) {
594
+
595
+ $parent_page = self::$default_menu_position;
596
+
597
+ if ( strpos( $parent_page, '?' ) !== false ) {
598
+ $query_var = '&page=' . self::$plugin_slug;
599
+ } else {
600
+ $query_var = '?page=' . self::$plugin_slug;
601
+ }
602
+
603
+ $parent_page_url = admin_url( $parent_page . $query_var );
604
+
605
+ $url = $parent_page_url . '&action=' . $menu_slug;
606
+
607
+ return esc_url( $url );
608
+ }
609
+
610
+ /**
611
+ * Admin body classes.
612
+ *
613
+ * Body classes to be added to <body> tag in admin page
614
+ *
615
+ * @param String $classes body classes returned from the filter.
616
+ * @return String body classes to be added to <body> tag in admin page
617
+ */
618
+ public static function add_admin_body_class( $classes ) {
619
+
620
+ $classes .= ' cartflows-' . CARTFLOWS_VER;
621
+
622
+ return $classes;
623
+ }
624
+
625
+ /**
626
+ * Save Global Setting options.
627
+ *
628
+ * @since 1.0.0
629
+ */
630
+ public static function save_facebook_settings() {
631
+
632
+ if ( isset( $_POST['cartflows-facebook-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-facebook-settings-nonce'] ) ), 'cartflows-facebook-settings' ) ) {
633
+
634
+ $url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
635
+ $new_settings = array();
636
+
637
+ if ( isset( $_POST['_cartflows_facebook'] ) ) {
638
+ $new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_facebook'] ) ); //phpcs:ignore
639
+ }
640
+
641
+ Cartflows_Helper::update_admin_settings_option( '_cartflows_facebook', $new_settings, false );
642
+ $query = array(
643
+ 'message' => 'saved',
644
+ );
645
+ $redirect_to = add_query_arg( $query, $url );
646
+ wp_safe_redirect( $redirect_to );
647
+ exit;
648
+ }
649
+ }
650
+
651
+ }
652
+
653
+ Cartflows_Admin::init();
classes/class-cartflows-compatibility.php CHANGED
@@ -1,410 +1,447 @@
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
- if ( defined( 'LEARNDASH_VERSION' ) ) {
66
- require_once CARTFLOWS_DIR . 'classes/class-cartflows-learndash-compatibility.php';
67
- }
68
- }
69
-
70
- /**
71
- * Check if it is beaver builder enabled.
72
- *
73
- * @since 1.1.4
74
- */
75
- public function is_bb_enabled() {
76
-
77
- if ( class_exists( 'FLBuilderModel' ) ) {
78
- return true;
79
- }
80
-
81
- return false;
82
- }
83
-
84
- /**
85
- * Check if elementor preview mode is on.
86
- */
87
- public function is_elementor_preview_mode() {
88
-
89
- if ( class_exists( '\Elementor\Plugin' ) ) {
90
-
91
- if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
92
- return true;
93
- }
94
- }
95
-
96
- return false;
97
- }
98
-
99
- /**
100
- * Get Current Theme.
101
- */
102
- public function get_current_theme() {
103
-
104
- $theme_name = '';
105
- $theme = wp_get_theme();
106
-
107
- if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
108
- $theme_name = $theme->parent_theme;
109
- } else {
110
- $theme_name = $theme->name;
111
- }
112
-
113
- return $theme_name;
114
- }
115
-
116
- /**
117
- * Check if it is beaver builder preview mode
118
- */
119
- public function is_bb_preview_mode() {
120
-
121
- if ( class_exists( 'FLBuilderModel' ) ) {
122
- if ( FLBuilderModel::is_builder_active() ) {
123
- return true;
124
- } else {
125
- return false;
126
- }
127
- }
128
-
129
- return false;
130
- }
131
-
132
- /**
133
- * Check for page builder preview mode.
134
- */
135
- public function is_page_builder_preview() {
136
-
137
- if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() ) {
138
- return true;
139
- }
140
-
141
- return false;
142
- }
143
-
144
- /**
145
- * Check if divi builder enabled for post id.
146
- */
147
- public function is_divi_builder_preview() {
148
-
149
- if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) { //phpcs:ignore
150
- return true;
151
- }
152
-
153
- return false;
154
- }
155
-
156
- /**
157
- * Check if divi builder enabled for post id.
158
- *
159
- * @param int $post_id post id.
160
- */
161
- public function is_divi_builder_enabled( $post_id ) {
162
-
163
- if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
164
- return true;
165
- }
166
-
167
- return false;
168
- }
169
-
170
- /**
171
- * Check if compatibility theme enabled.
172
- */
173
- public function is_compatibility_theme_enabled() {
174
-
175
- $theme = wp_get_theme();
176
-
177
- $is_compatibility = false;
178
-
179
- if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
180
-
181
- $is_compatibility = true;
182
- }
183
-
184
- return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
185
- }
186
-
187
- /**
188
- * Check if divi builder enabled for post id.
189
- *
190
- * @param object $theme theme data.
191
- * @return boolean
192
- */
193
- public function is_divi_enabled( $theme = false ) {
194
-
195
- if ( ! $theme ) {
196
- $theme = wp_get_theme();
197
- }
198
-
199
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
200
- return true;
201
- }
202
-
203
- return false;
204
- }
205
-
206
- /**
207
- * Check if Divi theme is install status.
208
- *
209
- * @return boolean
210
- */
211
- public function is_divi_theme_installed() {
212
- foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
213
- if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
214
- return true;
215
- }
216
- }
217
- return false;
218
- }
219
-
220
- /**
221
- * Check if Flatsome enabled for post id.
222
- *
223
- * @param object $theme theme data.
224
- * @return boolean
225
- */
226
- public function is_flatsome_enabled( $theme = false ) {
227
-
228
- if ( ! $theme ) {
229
- $theme = wp_get_theme();
230
- }
231
-
232
- if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
233
- return true;
234
- }
235
-
236
- return false;
237
- }
238
-
239
- /**
240
- * Check if The7 enabled for post id.
241
- *
242
- * @param object $theme theme data.
243
- * @return boolean
244
- */
245
- public function is_the_seven_enabled( $theme = false ) {
246
-
247
- if ( ! $theme ) {
248
- $theme = wp_get_theme();
249
- }
250
-
251
- if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
252
- return true;
253
- }
254
-
255
- return false;
256
- }
257
-
258
- /**
259
- * Check if OceanWp enabled for post id.
260
- *
261
- * @param object $theme theme data.
262
- * @return boolean
263
- */
264
- public function is_oceanwp_enabled( $theme = false ) {
265
-
266
- if ( ! $theme ) {
267
- $theme = wp_get_theme();
268
- }
269
-
270
- if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
271
- return true;
272
- }
273
-
274
- return false;
275
- }
276
-
277
- /**
278
- * Check for thrive architect edit page.
279
- *
280
- * @param int $post_id post id.
281
- */
282
- public function is_thrive_edit_page( $post_id ) {
283
-
284
- if ( true === $this->is_thrive_builder_page( $post_id ) ) {
285
- return true;
286
- } else {
287
- return false;
288
- }
289
- }
290
-
291
- /**
292
- * Check if the page being rendered is the main ID on the editor page.
293
- *
294
- * @since 1.0.0
295
- * @param String $post_id Post ID which is to be rendered.
296
- * @return boolean True if current if is being rendered is not being edited.
297
- */
298
- private function is_thrive_builder_page( $post_id ) {
299
- $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false; //phpcs:ignore
300
- $post = isset( $_GET['post'] ) ? intval( wp_unslash( $_GET['post'] ) ) : false; //phpcs:ignore
301
-
302
- return ( true == $tve && $post_id !== $post );
303
- }
304
-
305
- /**
306
- * Overwrite meta for page
307
- */
308
- public function override_meta() {
309
-
310
- // don't override meta for `elementor_library` post type.
311
- if ( 'elementor_library' == get_post_type() ) {
312
- return;
313
- }
314
-
315
- if ( ! is_singular() ) {
316
- return;
317
- }
318
-
319
- global $post;
320
- $post_id = $post->ID;
321
- $post_type = get_post_type();
322
-
323
- if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
324
- || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
325
- || $this->is_divi_builder_enabled( $post_id ) ) ) {
326
-
327
- if ( '' == $post->post_content ) {
328
-
329
- $this->overwrite_template( $post_id );
330
- }
331
- }
332
- }
333
-
334
- /**
335
- * Assign cartflow canvas template to page.
336
- *
337
- * @param int $post_id post ID.
338
- */
339
- public function overwrite_template( $post_id ) {
340
-
341
- $template = 'cartflows-canvas';
342
- $key = '_wp_page_template';
343
-
344
- $record_exists = get_post_meta( $post_id, $key, true );
345
-
346
- if ( 'cartflows-canvas' == $record_exists ) {
347
- return;
348
- }
349
-
350
- // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
351
- if ( class_exists( '\Elementor\Plugin' ) ) {
352
-
353
- global $wpdb;
354
-
355
- if ( '' == $record_exists || ! $record_exists ) {
356
-
357
- $wpdb->insert(
358
- $wpdb->prefix . 'postmeta',
359
- array(
360
- 'post_id' => $post_id,
361
- 'meta_key' => $key,//phpcs:ignore
362
- 'meta_value' => $template, //phpcs:ignore
363
- )
364
- );// db call ok;.
365
-
366
- // alternative query to above query.
367
- // $table = $wpdb->prefix . 'postmeta';
368
- // $wpdb->query($wpdb->prepare( "INSERT INTO { $table } ( `post_id`, `meta_key`, 'meta_value' )
369
- // VALUES ( '$post_id', '$key', '$template' )" ) );// db call ok; no-cache ok.
370
-
371
- } else {
372
-
373
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) ); // db call ok; no-cache ok.
374
- }
375
- } else {
376
-
377
- update_post_meta( $post_id, $key, $template );
378
- }
379
- }
380
-
381
- /**
382
- * Load font awesome style from oceanwp on checkout page.
383
- */
384
- public function load_fontawesome() {
385
-
386
- $theme = get_template();
387
-
388
- if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
389
-
390
- $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
391
-
392
- if ( $load_fa ) {
393
-
394
- wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );//phpcs:ignore
395
- }
396
-
397
- $custom_css = '
398
- #oceanwp-cart-sidebar-wrap,
399
- #owp-qv-wrap{
400
- display: none;
401
- }';
402
-
403
- wp_add_inline_style( 'wcf-frontend-global', $custom_css );
404
- }
405
- }
406
- }
407
- }
408
-
409
- Cartflows_Compatibility::get_instance();
410
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ( defined( 'LEARNDASH_VERSION' ) ) {
66
+ require_once CARTFLOWS_DIR . 'classes/class-cartflows-learndash-compatibility.php';
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Check if it is beaver builder enabled.
72
+ *
73
+ * @since 1.1.4
74
+ */
75
+ public function is_bb_enabled() {
76
+
77
+ if ( class_exists( 'FLBuilderModel' ) ) {
78
+ return true;
79
+ }
80
+
81
+ return false;
82
+ }
83
+
84
+ /**
85
+ * Check if elementor preview mode is on.
86
+ */
87
+ public function is_elementor_preview_mode() {
88
+
89
+ if ( class_exists( '\Elementor\Plugin' ) ) {
90
+
91
+ if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
92
+ return true;
93
+ }
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+ /**
100
+ * Get Current Theme.
101
+ */
102
+ public function get_current_theme() {
103
+
104
+ $theme_name = '';
105
+ $theme = wp_get_theme();
106
+
107
+ if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
108
+ $theme_name = $theme->parent_theme;
109
+ } else {
110
+ $theme_name = $theme->name;
111
+ }
112
+ return $theme_name;
113
+ }
114
+
115
+ /**
116
+ * Check if it is beaver builder preview mode
117
+ */
118
+ public function is_bb_preview_mode() {
119
+
120
+ if ( class_exists( 'FLBuilderModel' ) ) {
121
+ if ( FLBuilderModel::is_builder_active() ) {
122
+ return true;
123
+ } else {
124
+ return false;
125
+ }
126
+ }
127
+
128
+ return false;
129
+ }
130
+
131
+ /**
132
+ * Check for page builder preview mode.
133
+ */
134
+ public function is_page_builder_preview() {
135
+
136
+ if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() ) {
137
+ return true;
138
+ }
139
+
140
+ return false;
141
+ }
142
+
143
+ /**
144
+ * Check if divi builder enabled for post id.
145
+ */
146
+ public function is_divi_builder_preview() {
147
+
148
+ if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) { //phpcs:ignore
149
+ return true;
150
+ }
151
+
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * Check if divi builder enabled for post id.
157
+ *
158
+ * @param int $post_id post id.
159
+ */
160
+ public function is_divi_builder_enabled( $post_id ) {
161
+
162
+ if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
163
+ return true;
164
+ }
165
+
166
+ return false;
167
+ }
168
+
169
+ /**
170
+ * Check if compatibility theme enabled.
171
+ */
172
+ public function is_compatibility_theme_enabled() {
173
+
174
+ $theme = wp_get_theme();
175
+
176
+ $is_compatibility = false;
177
+
178
+ if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) || $this->is_pro_enabled( $theme ) || $this->is_kallyas_enabled( $theme ) ) {
179
+
180
+ $is_compatibility = true;
181
+ }
182
+
183
+ return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
184
+ }
185
+
186
+ /**
187
+ * Check if pro theme enabled for post id.
188
+ *
189
+ * @param object $theme theme data.
190
+ * @return boolean
191
+ */
192
+ public function is_pro_enabled( $theme = false ) {
193
+
194
+ if ( ! $theme ) {
195
+ $theme = wp_get_theme();
196
+ }
197
+
198
+ if ( 'Pro' == $theme->name ) {
199
+ return true;
200
+ }
201
+
202
+ return false;
203
+ }
204
+
205
+ /**
206
+ * Check if kallyas theme enabled for post id.
207
+ *
208
+ * @param object $theme theme data.
209
+ * @return boolean
210
+ */
211
+ public function is_kallyas_enabled( $theme = false ) {
212
+
213
+ if ( ! $theme ) {
214
+ $theme = wp_get_theme();
215
+ }
216
+
217
+ if ( 'Kallyas' == $theme->name ) {
218
+ return true;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Check if divi builder enabled for post id.
226
+ *
227
+ * @param object $theme theme data.
228
+ * @return boolean
229
+ */
230
+ public function is_divi_enabled( $theme = false ) {
231
+
232
+ if ( ! $theme ) {
233
+ $theme = wp_get_theme();
234
+ }
235
+
236
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
237
+ return true;
238
+ }
239
+
240
+ return false;
241
+ }
242
+
243
+ /**
244
+ * Check if Divi theme is install status.
245
+ *
246
+ * @return boolean
247
+ */
248
+ public function is_divi_theme_installed() {
249
+ foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
250
+ if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
251
+ return true;
252
+ }
253
+ }
254
+ return false;
255
+ }
256
+
257
+ /**
258
+ * Check if Flatsome enabled for post id.
259
+ *
260
+ * @param object $theme theme data.
261
+ * @return boolean
262
+ */
263
+ public function is_flatsome_enabled( $theme = false ) {
264
+
265
+ if ( ! $theme ) {
266
+ $theme = wp_get_theme();
267
+ }
268
+
269
+ if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
270
+ return true;
271
+ }
272
+
273
+ return false;
274
+ }
275
+
276
+ /**
277
+ * Check if The7 enabled for post id.
278
+ *
279
+ * @param object $theme theme data.
280
+ * @return boolean
281
+ */
282
+ public function is_the_seven_enabled( $theme = false ) {
283
+
284
+ if ( ! $theme ) {
285
+ $theme = wp_get_theme();
286
+ }
287
+
288
+ if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
289
+ return true;
290
+ }
291
+
292
+ return false;
293
+ }
294
+
295
+ /**
296
+ * Check if OceanWp enabled for post id.
297
+ *
298
+ * @param object $theme theme data.
299
+ * @return boolean
300
+ */
301
+ public function is_oceanwp_enabled( $theme = false ) {
302
+
303
+ if ( ! $theme ) {
304
+ $theme = wp_get_theme();
305
+ }
306
+
307
+ if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
308
+ return true;
309
+ }
310
+
311
+ return false;
312
+ }
313
+
314
+ /**
315
+ * Check for thrive architect edit page.
316
+ *
317
+ * @param int $post_id post id.
318
+ */
319
+ public function is_thrive_edit_page( $post_id ) {
320
+
321
+ if ( true === $this->is_thrive_builder_page( $post_id ) ) {
322
+ return true;
323
+ } else {
324
+ return false;
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Check if the page being rendered is the main ID on the editor page.
330
+ *
331
+ * @since 1.0.0
332
+ * @param String $post_id Post ID which is to be rendered.
333
+ * @return boolean True if current if is being rendered is not being edited.
334
+ */
335
+ private function is_thrive_builder_page( $post_id ) {
336
+ $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false; //phpcs:ignore
337
+ $post = isset( $_GET['post'] ) ? intval( wp_unslash( $_GET['post'] ) ) : false; //phpcs:ignore
338
+
339
+ return ( true == $tve && $post_id !== $post );
340
+ }
341
+
342
+ /**
343
+ * Overwrite meta for page
344
+ */
345
+ public function override_meta() {
346
+
347
+ // don't override meta for `elementor_library` post type.
348
+ if ( 'elementor_library' == get_post_type() ) {
349
+ return;
350
+ }
351
+
352
+ if ( ! is_singular() ) {
353
+ return;
354
+ }
355
+
356
+ global $post;
357
+ $post_id = $post->ID;
358
+ $post_type = get_post_type();
359
+
360
+ if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
361
+ || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
362
+ || $this->is_divi_builder_enabled( $post_id ) ) ) {
363
+
364
+ if ( '' == $post->post_content ) {
365
+
366
+ $this->overwrite_template( $post_id );
367
+ }
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Assign cartflow canvas template to page.
373
+ *
374
+ * @param int $post_id post ID.
375
+ */
376
+ public function overwrite_template( $post_id ) {
377
+
378
+ $template = 'cartflows-canvas';
379
+ $key = '_wp_page_template';
380
+
381
+ $record_exists = get_post_meta( $post_id, $key, true );
382
+
383
+ if ( 'cartflows-canvas' == $record_exists ) {
384
+ return;
385
+ }
386
+
387
+ // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
388
+ if ( class_exists( '\Elementor\Plugin' ) ) {
389
+
390
+ global $wpdb;
391
+
392
+ if ( '' == $record_exists || ! $record_exists ) {
393
+
394
+ $wpdb->insert(
395
+ $wpdb->prefix . 'postmeta',
396
+ array(
397
+ 'post_id' => $post_id,
398
+ 'meta_key' => $key,//phpcs:ignore
399
+ 'meta_value' => $template, //phpcs:ignore
400
+ )
401
+ );// db call ok;.
402
+
403
+ // alternative query to above query.
404
+ // $table = $wpdb->prefix . 'postmeta';
405
+ // $wpdb->query($wpdb->prepare( "INSERT INTO { $table } ( `post_id`, `meta_key`, 'meta_value' )
406
+ // VALUES ( '$post_id', '$key', '$template' )" ) );// db call ok; no-cache ok.
407
+
408
+ } else {
409
+
410
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) ); // db call ok; no-cache ok.
411
+ }
412
+ } else {
413
+
414
+ update_post_meta( $post_id, $key, $template );
415
+ }
416
+ }
417
+
418
+ /**
419
+ * Load font awesome style from oceanwp on checkout page.
420
+ */
421
+ public function load_fontawesome() {
422
+
423
+ $theme = get_template();
424
+
425
+ if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
426
+
427
+ $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
428
+
429
+ if ( $load_fa ) {
430
+
431
+ wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );//phpcs:ignore
432
+ }
433
+
434
+ $custom_css = '
435
+ #oceanwp-cart-sidebar-wrap,
436
+ #owp-qv-wrap{
437
+ display: none;
438
+ }';
439
+
440
+ wp_add_inline_style( 'wcf-frontend-global', $custom_css );
441
+ }
442
+ }
443
+ }
444
+ }
445
+
446
+ Cartflows_Compatibility::get_instance();
447
+
classes/class-cartflows-default-meta.php CHANGED
@@ -391,6 +391,33 @@ class Cartflows_Default_Meta {
391
  }
392
  }
393
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  default:
395
  if ( 'FILTER_DEFAULT' === $sanitize_filter ) {
396
  $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
391
  }
392
  }
393
  break;
394
+
395
+ case 'FILTER_CARTFLOWS_IMAGES':
396
+ $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
397
+
398
+ if ( isset( $_POST[ $key . '-obj' ] )) { //phpcs:ignore
399
+
400
+ if ( ! is_serialized( $_POST[ $key . '-obj' ] ) ) { //phpcs:ignore
401
+
402
+ $image_obj = json_decode( stripcslashes( wp_unslash( $_POST[ $key . '-obj' ] ) ), true ); //phpcs:ignore
403
+ $image_url = isset( $image_obj['sizes'] ) ? $image_obj['sizes'] : array();
404
+
405
+ $image_data = array(
406
+ 'id' => isset( $image_obj['id'] ) ? intval( $image_obj['id'] ) : 0,
407
+ 'url' => array(
408
+ 'thumbnail' => isset( $image_url['thumbnail']['url'] ) ? esc_url_raw( $image_url['thumbnail']['url'] ) : '',
409
+ 'medium' => isset( $image_url['medium']['url'] ) ? esc_url_raw( $image_url['medium']['url'] ) : '',
410
+ 'full' => isset( $image_url['full']['url'] ) ? esc_url_raw( $image_url['full']['url'] ) : '',
411
+ ),
412
+ );
413
+
414
+ $new_meta_value = 0 !== $image_data['id'] ? $image_data : '';
415
+ update_post_meta( $post_id, $key . '-obj', $new_meta_value );
416
+ }
417
+ }
418
+
419
+ break;
420
+
421
  default:
422
  if ( 'FILTER_DEFAULT' === $sanitize_filter ) {
423
  $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
classes/class-cartflows-elementor-compatibility.php CHANGED
@@ -1,100 +1,100 @@
1
- <?php
2
- /**
3
- * Elementor page builder compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- namespace Elementor\Modules\PageTemplates;
9
-
10
- use Elementor\Core\Base\Document;
11
- use Elementor\Plugin;
12
-
13
- /**
14
- * Class for elementor page builder compatibility
15
- */
16
- class Cartflows_Elementor_Compatibility {
17
-
18
- /**
19
- * Member Variable
20
- *
21
- * @var instance
22
- */
23
- private static $instance;
24
-
25
- /**
26
- * Initiator
27
- */
28
- public static function get_instance() {
29
- if ( ! isset( self::$instance ) ) {
30
- self::$instance = new self();
31
- }
32
- return self::$instance;
33
- }
34
-
35
- /**
36
- * Constructor
37
- */
38
- public function __construct() {
39
-
40
- add_filter( 'cartflows_page_template', array( $this, 'get_page_template' ) );
41
-
42
- if ( wcf()->is_woo_active ) {
43
-
44
- // On Editor - Register WooCommerce frontend hooks before the Editor init.
45
- // Priority = 5, in order to allow plugins remove/add their wc hooks on init.
46
- if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] && is_admin() ) { //phpcs:ignore
47
- add_action( 'init', array( $this, 'register_wc_hooks' ), 5 );
48
- }
49
-
50
- add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'maybe_init_cart' ) );
51
- }
52
- }
53
-
54
- /**
55
- * Get page template fiter callback for elementor preview mode
56
- *
57
- * @param string $template page template.
58
- * @return string
59
- */
60
- public function get_page_template( $template ) {
61
-
62
- if ( is_singular() ) {
63
- $document = Plugin::$instance->documents->get_doc_for_frontend( get_the_ID() );
64
-
65
- if ( $document ) {
66
- $template = $document->get_meta( '_wp_page_template' );
67
- }
68
- }
69
-
70
- return $template;
71
- }
72
-
73
- /**
74
- * Rgister wc hookes for elementor preview mode
75
- */
76
- public function register_wc_hooks() {
77
- wc()->frontend_includes();
78
- }
79
-
80
- /**
81
- * Init cart in elementor preview mode
82
- */
83
- public function maybe_init_cart() {
84
-
85
- $has_cart = is_a( WC()->cart, 'WC_Cart' );
86
-
87
- if ( ! $has_cart ) {
88
- $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
89
- WC()->session = new $session_class();
90
- WC()->session->init();
91
- WC()->cart = new \WC_Cart();
92
- WC()->customer = new \WC_Customer( get_current_user_id(), true );
93
- }
94
- }
95
- }
96
-
97
- /**
98
- * Kicking this off by calling 'get_instance()' method
99
- */
100
- Cartflows_Elementor_Compatibility::get_instance();
1
+ <?php
2
+ /**
3
+ * Elementor page builder compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ namespace Elementor\Modules\PageTemplates;
9
+
10
+ use Elementor\Core\Base\Document;
11
+ use Elementor\Plugin;
12
+
13
+ /**
14
+ * Class for elementor page builder compatibility
15
+ */
16
+ class Cartflows_Elementor_Compatibility {
17
+
18
+ /**
19
+ * Member Variable
20
+ *
21
+ * @var instance
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Initiator
27
+ */
28
+ public static function get_instance() {
29
+ if ( ! isset( self::$instance ) ) {
30
+ self::$instance = new self();
31
+ }
32
+ return self::$instance;
33
+ }
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+
40
+ add_filter( 'cartflows_page_template', array( $this, 'get_page_template' ) );
41
+
42
+ if ( wcf()->is_woo_active ) {
43
+
44
+ // On Editor - Register WooCommerce frontend hooks before the Editor init.
45
+ // Priority = 5, in order to allow plugins remove/add their wc hooks on init.
46
+ if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] && is_admin() ) { //phpcs:ignore
47
+ add_action( 'init', array( $this, 'register_wc_hooks' ), 5 );
48
+ }
49
+
50
+ add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'maybe_init_cart' ) );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Get page template fiter callback for elementor preview mode
56
+ *
57
+ * @param string $template page template.
58
+ * @return string
59
+ */
60
+ public function get_page_template( $template ) {
61
+
62
+ if ( is_singular() ) {
63
+ $document = Plugin::$instance->documents->get_doc_for_frontend( get_the_ID() );
64
+
65
+ if ( $document ) {
66
+ $template = $document->get_meta( '_wp_page_template' );
67
+ }
68
+ }
69
+
70
+ return $template;
71
+ }
72
+
73
+ /**
74
+ * Rgister wc hookes for elementor preview mode
75
+ */
76
+ public function register_wc_hooks() {
77
+ wc()->frontend_includes();
78
+ }
79
+
80
+ /**
81
+ * Init cart in elementor preview mode
82
+ */
83
+ public function maybe_init_cart() {
84
+
85
+ $has_cart = is_a( WC()->cart, 'WC_Cart' );
86
+
87
+ if ( ! $has_cart ) {
88
+ $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
89
+ WC()->session = new $session_class();
90
+ WC()->session->init();
91
+ WC()->cart = new \WC_Cart();
92
+ WC()->customer = new \WC_Customer( get_current_user_id(), true );
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Kicking this off by calling 'get_instance()' method
99
+ */
100
+ Cartflows_Elementor_Compatibility::get_instance();
classes/class-cartflows-frontend.php CHANGED
@@ -43,6 +43,8 @@ class Cartflows_Frontend {
43
  /* Modify the checkout order received url to go thank you page in our flow */
44
  add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
45
 
 
 
46
  }
47
 
48
  /**
@@ -325,8 +327,6 @@ class Cartflows_Frontend {
325
  if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
326
  $this->remove_flatsome_action();
327
  }
328
-
329
- add_action( 'wp_head', array( $this, 'facebook_pixel_init' ) );
330
  }
331
  }
332
 
@@ -340,7 +340,7 @@ class Cartflows_Frontend {
340
 
341
  $facebook_id = $facebook_settings['facebook_pixel_id'];
342
  echo '<!-- Facebook Pixel Script By CartFlows -->';
343
- echo "<script type='text/javascript'>
344
  !function(f,b,e,v,n,t,s)
345
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
346
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
@@ -351,6 +351,18 @@ class Cartflows_Frontend {
351
  'https://connect.facebook.net/en_US/fbevents.js');
352
  </script>
353
  <noscript><img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id=<?php echo $facebook_id; ?>&ev=PageView&noscript=1'/></noscript>";
 
 
 
 
 
 
 
 
 
 
 
 
354
  echo '<!-- End Facebook Pixel Script By CartFlows -->';
355
  }
356
 
43
  /* Modify the checkout order received url to go thank you page in our flow */
44
  add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
45
 
46
+ add_action( 'wp_head', array( $this, 'facebook_pixel_init' ) );
47
+
48
  }
49
 
50
  /**
327
  if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
328
  $this->remove_flatsome_action();
329
  }
 
 
330
  }
331
  }
332
 
340
 
341
  $facebook_id = $facebook_settings['facebook_pixel_id'];
342
  echo '<!-- Facebook Pixel Script By CartFlows -->';
343
+ $fb_script = "<script type='text/javascript'>
344
  !function(f,b,e,v,n,t,s)
345
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
346
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
351
  'https://connect.facebook.net/en_US/fbevents.js');
352
  </script>
353
  <noscript><img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id=<?php echo $facebook_id; ?>&ev=PageView&noscript=1'/></noscript>";
354
+
355
+ $fb_page_view = "<script type='text/javascript'>
356
+ fbq('init', $facebook_id);
357
+ fbq('track', 'PageView', {'plugin': 'CartFlows'});
358
+ </script>";
359
+
360
+ if ( 'enable' === $facebook_settings['facebook_pixel_tracking_for_site'] && ! wcf()->utils->is_step_post_type() ) {
361
+ echo $fb_script;
362
+ echo $fb_page_view;
363
+ } else {
364
+ echo $fb_script;
365
+ }
366
  echo '<!-- End Facebook Pixel Script By CartFlows -->';
367
  }
368
 
classes/class-cartflows-functions.php CHANGED
@@ -1,523 +1,523 @@
1
- <?php
2
- /**
3
- * CartFlows Functions.
4
- *
5
- * @package CARTFLOWS
6
- */
7
-
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit; // Exit if accessed directly.
10
- }
11
-
12
- /**
13
- * Fatal error mb_strpos fallback.
14
- *
15
- * @param string $string string where to find.
16
- * @param string $search string to search.
17
- * @since 1.0.0
18
- */
19
- function wcf_mb_strpos( $string, $search ) {
20
-
21
- if ( function_exists( 'mb_strpos' ) ) {
22
- return mb_strpos( $string, $search, 0, 'utf-8' );
23
- } else {
24
- return strpos( $string, $search );
25
- }
26
- }
27
-
28
- /**
29
- * Check if cartflows pro activated.
30
- *
31
- * @since 1.0.0
32
- */
33
- function _is_cartflows_pro() {
34
-
35
- if ( defined( 'CARTFLOWS_PRO_FILE' ) ) {
36
- return true;
37
- }
38
-
39
- return false;
40
-
41
- }
42
-
43
- /**
44
- * Returns pro version number.
45
- *
46
- * @param int $version version number.
47
- * @since 1.0.0
48
- */
49
- function _is_cartflows_pro_ver_less_than( $version ) {
50
-
51
- if ( defined( 'CARTFLOWS_PRO_VER' ) && version_compare( CARTFLOWS_PRO_VER, $version, '<' ) ) {
52
- return true;
53
- }
54
-
55
- return false;
56
- }
57
-
58
- /**
59
- * Returns step id.
60
- *
61
- * @since 1.0.0
62
- */
63
- function _get_wcf_post_id() {
64
-
65
- global $post;
66
-
67
- if ( isset( $post->ID ) ) {
68
- return $post->ID;
69
- }
70
-
71
- return 0;
72
- }
73
-
74
- /**
75
- * Returns step id.
76
- *
77
- * @since 1.0.0
78
- */
79
- function _get_wcf_step_id() {
80
-
81
- if ( wcf()->utils->is_step_post_type() ) {
82
-
83
- global $post;
84
-
85
- return $post->ID;
86
- }
87
-
88
- return false;
89
- }
90
-
91
- /**
92
- * Check if it is a landing page?
93
- *
94
- * @since 1.0.0
95
- */
96
- function _is_wcf_landing_type() {
97
-
98
- if ( wcf()->utils->is_step_post_type() ) {
99
-
100
- global $post;
101
-
102
- if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
103
-
104
- return true;
105
- }
106
- }
107
-
108
- return false;
109
- }
110
-
111
- /**
112
- * Returns landing id.
113
- *
114
- * @since 1.0.0
115
- */
116
- function _get_wcf_landing_id() {
117
-
118
- if ( _is_wcf_landing_type() ) {
119
-
120
- global $post;
121
-
122
- return $post->ID;
123
- }
124
-
125
- return false;
126
- }
127
-
128
- /**
129
- * Is custom checkout?
130
- *
131
- * @param int $checkout_id checkout ID.
132
- * @since 1.0.0
133
- */
134
- function _is_wcf_meta_custom_checkout( $checkout_id ) {
135
-
136
- $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' );
137
-
138
- if ( 'yes' === $is_custom ) {
139
-
140
- return true;
141
- }
142
-
143
- return false;
144
- }
145
-
146
- /**
147
- * Check if page is cartflow checkout.
148
- *
149
- * @since 1.0.0
150
- * @return bool
151
- */
152
- function _is_wcf_checkout_type() {
153
-
154
- if ( wcf()->utils->is_step_post_type() ) {
155
-
156
- global $post;
157
-
158
- if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
159
-
160
- return true;
161
- }
162
- }
163
-
164
- return false;
165
- }
166
-
167
- /**
168
- * Check if AJAX call is in progress.
169
- *
170
- * @since 1.0.0
171
- * @return bool
172
- */
173
- function _is_wcf_doing_checkout_ajax() {
174
-
175
- if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { //phpcs:ignore
176
-
177
- if ( isset( $_GET['wc-ajax'] ) && //phpcs:ignore
178
- 'checkout' === $_GET['wc-ajax'] && //phpcs:ignore
179
- isset( $_POST['_wcf_checkout_id'] ) //phpcs:ignore
180
- ) {
181
- return true;
182
- }
183
- }
184
-
185
- return false;
186
- }
187
-
188
- /**
189
- * Check if optin AJAX call is in progress.
190
- *
191
- * @since 1.0.0
192
- * @return bool
193
- */
194
- function _is_wcf_doing_optin_ajax() {
195
-
196
- if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { //phpcs:ignore
197
-
198
- if ( isset( $_GET['wc-ajax'] ) && //phpcs:ignore
199
- 'checkout' === $_GET['wc-ajax'] && //phpcs:ignore
200
- isset( $_POST['_wcf_optin_id'] ) //phpcs:ignore
201
- ) {
202
- return true;
203
- }
204
- }
205
-
206
- return false;
207
- }
208
-
209
- /**
210
- * Returns checkout ID.
211
- *
212
- * @since 1.0.0
213
- * @return int/bool
214
- */
215
- function _get_wcf_checkout_id() {
216
-
217
- if ( _is_wcf_checkout_type() ) {
218
-
219
- global $post;
220
-
221
- return $post->ID;
222
- }
223
-
224
- return false;
225
- }
226
-
227
- /**
228
- * Check if it is checkout shortcode.
229
- *
230
- * @since 1.0.0
231
- * @return bool
232
- */
233
- function _is_wcf_checkout_shortcode() {
234
-
235
- global $post;
236
-
237
- if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) {
238
-
239
- return true;
240
- }
241
-
242
- return false;
243
- }
244
-
245
- /**
246
- * Check if it is checkout shortcode.
247
- *
248
- * @since 1.0.0
249
- * @param string $content shortcode content.
250
- * @return bool
251
- */
252
- function _get_wcf_checkout_id_from_shortcode( $content = '' ) {
253
-
254
- $checkout_id = 0;
255
-
256
- if ( ! empty( $content ) ) {
257
-
258
- $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) );
259
-
260
- preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches );
261
-
262
- if ( ! empty( $regex_matches ) ) {
263
-
264
- if ( 'cartflows_checkout' == $regex_matches[2] ) {
265
-
266
- $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) );
267
- $attribure_str = str_replace( '"', '', $attribure_str );
268
-
269
- $attributes = wp_parse_args( $attribure_str );
270
-
271
- if ( isset( $attributes['id'] ) ) {
272
- $checkout_id = $attributes['id'];
273
- }
274
- }
275
- }
276
- }
277
-
278
- return $checkout_id;
279
- }
280
-
281
- /**
282
- * Check if post type is upsell.
283
- *
284
- * @since 1.0.0
285
- * @return bool
286
- */
287
- function _is_wcf_upsell_type() {
288
-
289
- if ( wcf()->utils->is_step_post_type() ) {
290
-
291
- global $post;
292
-
293
- if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
294
-
295
- return true;
296
- }
297
- }
298
-
299
- return false;
300
- }
301
-
302
- /**
303
- * Returns upsell ID.
304
- *
305
- * @since 1.0.0
306
- * @return int/bool
307
- */
308
- function _get_wcf_upsell_id() {
309
-
310
- if ( _is_wcf_upsell_type() ) {
311
-
312
- global $post;
313
-
314
- return $post->ID;
315
- }
316
-
317
- return false;
318
- }
319
-
320
- /**
321
- * Check if post is of type downsell.
322
- *
323
- * @since 1.0.0
324
- * @return int/bool
325
- */
326
- function _is_wcf_downsell_type() {
327
-
328
- if ( wcf()->utils->is_step_post_type() ) {
329
-
330
- global $post;
331
-
332
- if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
333
-
334
- return true;
335
- }
336
- }
337
-
338
- return false;
339
- }
340
-
341
- /**
342
- * Get downsell page ID.
343
- *
344
- * @since 1.0.0
345
- * @return int/bool
346
- */
347
- function _get_wcf_downsell_id() {
348
-
349
- if ( _is_wcf_downsell_type() ) {
350
-
351
- global $post;
352
-
353
- return $post->ID;
354
- }
355
-
356
- return false;
357
- }
358
-
359
- /**
360
- * Check if page is of thank you type.
361
- *
362
- * @since 1.0.0
363
- * @return int/bool
364
- */
365
- function _is_wcf_thankyou_type() {
366
-
367
- if ( wcf()->utils->is_step_post_type() ) {
368
-
369
- global $post;
370
-
371
- if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
372
-
373
- return true;
374
- }
375
- }
376
-
377
- return false;
378
- }
379
-
380
- /**
381
- * Get thank you page ID.
382
- *
383
- * @since 1.0.0
384
- * @return int/bool
385
- */
386
- function _get_wcf_thankyou_id() {
387
-
388
- if ( _is_wcf_thankyou_type() ) {
389
-
390
- global $post;
391
-
392
- return $post->ID;
393
- }
394
-
395
- return false;
396
- }
397
-
398
-
399
- /**
400
- * Check if post type is upsell.
401
- *
402
- * @since 1.0.0
403
- * @return bool
404
- */
405
- function _is_wcf_base_offer_type() {
406
-
407
- if ( wcf()->utils->is_step_post_type() ) {
408
-
409
- global $post;
410
-
411
- $step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
412
-
413
- if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
414
-
415
- return true;
416
- }
417
- }
418
-
419
- return false;
420
- }
421
-
422
- /**
423
- * Returns upsell ID.
424
- *
425
- * @since 1.0.0
426
- * @return int/bool
427
- */
428
- function _get_wcf_base_offer_id() {
429
-
430
- if ( _is_wcf_base_offer_type() ) {
431
-
432
- global $post;
433
-
434
- return $post->ID;
435
- }
436
-
437
- return false;
438
- }
439
-
440
- /**
441
- * Check if page is of optin type.
442
- *
443
- * @since 1.0.0
444
- * @return int/bool
445
- */
446
- function _is_wcf_optin_type() {
447
-
448
- if ( wcf()->utils->is_step_post_type() ) {
449
-
450
- global $post;
451
-
452
- if ( 'optin' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
453
-
454
- return true;
455
- }
456
- }
457
-
458
- return false;
459
- }
460
-
461
- /**
462
- * Get optin page ID.
463
- *
464
- * @since 1.0.0
465
- * @return int/bool
466
- */
467
- function _get_wcf_optin_id() {
468
-
469
- if ( _is_wcf_optin_type() ) {
470
-
471
- global $post;
472
-
473
- return $post->ID;
474
- }
475
-
476
- return false;
477
- }
478
-
479
- /**
480
- * Define a constant if it is not already defined.
481
- *
482
- * @since 3.0.0
483
- * @param string $name Constant name.
484
- * @param mixed $value Value.
485
- */
486
- function wcf_maybe_define_constant( $name, $value ) {
487
- if ( ! defined( $name ) ) {
488
- define( $name, $value );
489
- }
490
- }
491
-
492
-
493
- if ( ! function_exists( 'wp_body_open' ) ) {
494
- /**
495
- * Fire the wp_body_open action.
496
- *
497
- * Added for backwards compatibility to support WordPress versions prior to 5.2.0.
498
- */
499
- function wp_body_open() {
500
- /**
501
- * Triggered after the opening <body> tag.
502
- */
503
- do_action( 'wp_body_open' );
504
- }
505
- }
506
-
507
- /**
508
- * Check if type is optin by id.
509
- *
510
- * @param int $post_id post id.
511
- *
512
- * @return int/bool
513
- * @since 1.0.0
514
- */
515
- function _wcf_check_is_optin_by_id( $post_id ) {
516
-
517
- if ( 'optin' === get_post_meta( $post_id, 'wcf-step-type', true ) ) {
518
-
519
- return true;
520
- }
521
-
522
- return false;
523
- }
1
+ <?php
2
+ /**
3
+ * CartFlows Functions.
4
+ *
5
+ * @package CARTFLOWS
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Fatal error mb_strpos fallback.
14
+ *
15
+ * @param string $string string where to find.
16
+ * @param string $search string to search.
17
+ * @since 1.0.0
18
+ */
19
+ function wcf_mb_strpos( $string, $search ) {
20
+
21
+ if ( function_exists( 'mb_strpos' ) ) {
22
+ return mb_strpos( $string, $search, 0, 'utf-8' );
23
+ } else {
24
+ return strpos( $string, $search );
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Check if cartflows pro activated.
30
+ *
31
+ * @since 1.0.0
32
+ */
33
+ function _is_cartflows_pro() {
34
+
35
+ if ( defined( 'CARTFLOWS_PRO_FILE' ) ) {
36
+ return true;
37
+ }
38
+
39
+ return false;
40
+
41
+ }
42
+
43
+ /**
44
+ * Returns pro version number.
45
+ *
46
+ * @param int $version version number.
47
+ * @since 1.0.0
48
+ */
49
+ function _is_cartflows_pro_ver_less_than( $version ) {
50
+
51
+ if ( defined( 'CARTFLOWS_PRO_VER' ) && version_compare( CARTFLOWS_PRO_VER, $version, '<' ) ) {
52
+ return true;
53
+ }
54
+
55
+ return false;
56
+ }
57
+
58
+ /**
59
+ * Returns step id.
60
+ *
61
+ * @since 1.0.0
62
+ */
63
+ function _get_wcf_post_id() {
64
+
65
+ global $post;
66
+
67
+ if ( isset( $post->ID ) ) {
68
+ return $post->ID;
69
+ }
70
+
71
+ return 0;
72
+ }
73
+
74
+ /**
75
+ * Returns step id.
76
+ *
77
+ * @since 1.0.0
78
+ */
79
+ function _get_wcf_step_id() {
80
+
81
+ if ( wcf()->utils->is_step_post_type() ) {
82
+
83
+ global $post;
84
+
85
+ return $post->ID;
86
+ }
87
+
88
+ return false;
89
+ }
90
+
91
+ /**
92
+ * Check if it is a landing page?
93
+ *
94
+ * @since 1.0.0
95
+ */
96
+ function _is_wcf_landing_type() {
97
+
98
+ if ( wcf()->utils->is_step_post_type() ) {
99
+
100
+ global $post;
101
+
102
+ if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
103
+
104
+ return true;
105
+ }
106
+ }
107
+
108
+ return false;
109
+ }
110
+
111
+ /**
112
+ * Returns landing id.
113
+ *
114
+ * @since 1.0.0
115
+ */
116
+ function _get_wcf_landing_id() {
117
+
118
+ if ( _is_wcf_landing_type() ) {
119
+
120
+ global $post;
121
+
122
+ return $post->ID;
123
+ }
124
+
125
+ return false;
126
+ }
127
+
128
+ /**
129
+ * Is custom checkout?
130
+ *
131
+ * @param int $checkout_id checkout ID.
132
+ * @since 1.0.0
133
+ */
134
+ function _is_wcf_meta_custom_checkout( $checkout_id ) {
135
+
136
+ $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' );
137
+
138
+ if ( 'yes' === $is_custom ) {
139
+
140
+ return true;
141
+ }
142
+
143
+ return false;
144
+ }
145
+
146
+ /**
147
+ * Check if page is cartflow checkout.
148
+ *
149
+ * @since 1.0.0
150
+ * @return bool
151
+ */
152
+ function _is_wcf_checkout_type() {
153
+
154
+ if ( wcf()->utils->is_step_post_type() ) {
155
+
156
+ global $post;
157
+
158
+ if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
159
+
160
+ return true;
161
+ }
162
+ }
163
+
164
+ return false;
165
+ }
166
+
167
+ /**
168
+ * Check if AJAX call is in progress.
169
+ *
170
+ * @since 1.0.0
171
+ * @return bool
172
+ */
173
+ function _is_wcf_doing_checkout_ajax() {
174
+
175
+ if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { //phpcs:ignore
176
+
177
+ if ( isset( $_GET['wc-ajax'] ) && //phpcs:ignore
178
+ 'checkout' === $_GET['wc-ajax'] && //phpcs:ignore
179
+ isset( $_POST['_wcf_checkout_id'] ) //phpcs:ignore
180
+ ) {
181
+ return true;
182
+ }
183
+ }
184
+
185
+ return false;
186
+ }
187
+
188
+ /**
189
+ * Check if optin AJAX call is in progress.
190
+ *
191
+ * @since 1.0.0
192
+ * @return bool
193
+ */
194
+ function _is_wcf_doing_optin_ajax() {
195
+
196
+ if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { //phpcs:ignore
197
+
198
+ if ( isset( $_GET['wc-ajax'] ) && //phpcs:ignore
199
+ 'checkout' === $_GET['wc-ajax'] && //phpcs:ignore
200
+ isset( $_POST['_wcf_optin_id'] ) //phpcs:ignore
201
+ ) {
202
+ return true;
203
+ }
204
+ }
205
+
206
+ return false;
207
+ }
208
+
209
+ /**
210
+ * Returns checkout ID.
211
+ *
212
+ * @since 1.0.0
213
+ * @return int/bool
214
+ */
215
+ function _get_wcf_checkout_id() {
216
+
217
+ if ( _is_wcf_checkout_type() ) {
218
+
219
+ global $post;
220
+
221
+ return $post->ID;
222
+ }
223
+
224
+ return false;
225
+ }
226
+
227
+ /**
228
+ * Check if it is checkout shortcode.
229
+ *
230
+ * @since 1.0.0
231
+ * @return bool
232
+ */
233
+ function _is_wcf_checkout_shortcode() {
234
+
235
+ global $post;
236
+
237
+ if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) {
238
+
239
+ return true;
240
+ }
241
+
242
+ return false;
243
+ }
244
+
245
+ /**
246
+ * Check if it is checkout shortcode.
247
+ *
248
+ * @since 1.0.0
249
+ * @param string $content shortcode content.
250
+ * @return bool
251
+ */
252
+ function _get_wcf_checkout_id_from_shortcode( $content = '' ) {
253
+
254
+ $checkout_id = 0;
255
+
256
+ if ( ! empty( $content ) ) {
257
+
258
+ $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) );
259
+
260
+ preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches );
261
+
262
+ if ( ! empty( $regex_matches ) ) {
263
+
264
+ if ( 'cartflows_checkout' == $regex_matches[2] ) {
265
+
266
+ $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) );
267
+ $attribure_str = str_replace( '"', '', $attribure_str );
268
+
269
+ $attributes = wp_parse_args( $attribure_str );
270
+
271
+ if ( isset( $attributes['id'] ) ) {
272
+ $checkout_id = $attributes['id'];
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ return $checkout_id;
279
+ }
280
+
281
+ /**
282
+ * Check if post type is upsell.
283
+ *
284
+ * @since 1.0.0
285
+ * @return bool
286
+ */
287
+ function _is_wcf_upsell_type() {
288
+
289
+ if ( wcf()->utils->is_step_post_type() ) {
290
+
291
+ global $post;
292
+
293
+ if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
294
+
295
+ return true;
296
+ }
297
+ }
298
+
299
+ return false;
300
+ }
301
+
302
+ /**
303
+ * Returns upsell ID.
304
+ *
305
+ * @since 1.0.0
306
+ * @return int/bool
307
+ */
308
+ function _get_wcf_upsell_id() {
309
+
310
+ if ( _is_wcf_upsell_type() ) {
311
+
312
+ global $post;
313
+
314
+ return $post->ID;
315
+ }
316
+
317
+ return false;
318
+ }
319
+
320
+ /**
321
+ * Check if post is of type downsell.
322
+ *
323
+ * @since 1.0.0
324
+ * @return int/bool
325
+ */
326
+ function _is_wcf_downsell_type() {
327
+
328
+ if ( wcf()->utils->is_step_post_type() ) {
329
+
330
+ global $post;
331
+
332
+ if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
333
+
334
+ return true;
335
+ }
336
+ }
337
+
338
+ return false;
339
+ }
340
+
341
+ /**
342
+ * Get downsell page ID.
343
+ *
344
+ * @since 1.0.0
345
+ * @return int/bool
346
+ */
347
+ function _get_wcf_downsell_id() {
348
+
349
+ if ( _is_wcf_downsell_type() ) {
350
+
351
+ global $post;
352
+
353
+ return $post->ID;
354
+ }
355
+
356
+ return false;
357
+ }
358
+
359
+ /**
360
+ * Check if page is of thank you type.
361
+ *
362
+ * @since 1.0.0
363
+ * @return int/bool
364
+ */
365
+ function _is_wcf_thankyou_type() {
366
+
367
+ if ( wcf()->utils->is_step_post_type() ) {
368
+
369
+ global $post;
370
+
371
+ if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
372
+
373
+ return true;
374
+ }
375
+ }
376
+
377
+ return false;
378
+ }
379
+
380
+ /**
381
+ * Get thank you page ID.
382
+ *
383
+ * @since 1.0.0
384
+ * @return int/bool
385
+ */
386
+ function _get_wcf_thankyou_id() {
387
+
388
+ if ( _is_wcf_thankyou_type() ) {
389
+
390
+ global $post;
391
+
392
+ return $post->ID;
393
+ }
394
+
395
+ return false;
396
+ }
397
+
398
+
399
+ /**
400
+ * Check if post type is upsell.
401
+ *
402
+ * @since 1.0.0
403
+ * @return bool
404
+ */
405
+ function _is_wcf_base_offer_type() {
406
+
407
+ if ( wcf()->utils->is_step_post_type() ) {
408
+
409
+ global $post;
410
+
411
+ $step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
412
+
413
+ if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
414
+
415
+ return true;
416
+ }
417
+ }
418
+
419
+ return false;
420
+ }
421
+
422
+ /**
423
+ * Returns upsell ID.
424
+ *
425
+ * @since 1.0.0
426
+ * @return int/bool
427
+ */
428
+ function _get_wcf_base_offer_id() {
429
+
430
+ if ( _is_wcf_base_offer_type() ) {
431
+
432
+ global $post;
433
+
434
+ return $post->ID;
435
+ }
436
+
437
+ return false;
438
+ }
439
+
440
+ /**
441
+ * Check if page is of optin type.
442
+ *
443
+ * @since 1.0.0
444
+ * @return int/bool
445
+ */
446
+ function _is_wcf_optin_type() {
447
+
448
+ if ( wcf()->utils->is_step_post_type() ) {
449
+
450
+ global $post;
451
+
452
+ if ( 'optin' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
453
+
454
+ return true;
455
+ }
456
+ }
457
+
458
+ return false;
459
+ }
460
+
461
+ /**
462
+ * Get optin page ID.
463
+ *
464
+ * @since 1.0.0
465
+ * @return int/bool
466
+ */
467
+ function _get_wcf_optin_id() {
468
+
469
+ if ( _is_wcf_optin_type() ) {
470
+
471
+ global $post;
472
+
473
+ return $post->ID;
474
+ }
475
+
476
+ return false;
477
+ }
478
+
479
+ /**
480
+ * Define a constant if it is not already defined.
481
+ *
482
+ * @since 3.0.0
483
+ * @param string $name Constant name.
484
+ * @param mixed $value Value.
485
+ */
486
+ function wcf_maybe_define_constant( $name, $value ) {
487
+ if ( ! defined( $name ) ) {
488
+ define( $name, $value );
489
+ }
490
+ }
491
+
492
+
493
+ if ( ! function_exists( 'wp_body_open' ) ) {
494
+ /**
495
+ * Fire the wp_body_open action.
496
+ *
497
+ * Added for backwards compatibility to support WordPress versions prior to 5.2.0.
498
+ */
499
+ function wp_body_open() {
500
+ /**
501
+ * Triggered after the opening <body> tag.
502
+ */
503
+ do_action( 'wp_body_open' );
504
+ }
505
+ }
506
+
507
+ /**
508
+ * Check if type is optin by id.
509
+ *
510
+ * @param int $post_id post id.
511
+ *
512
+ * @return int/bool
513
+ * @since 1.0.0
514
+ */
515
+ function _wcf_check_is_optin_by_id( $post_id ) {
516
+
517
+ if ( 'optin' === get_post_meta( $post_id, 'wcf-step-type', true ) ) {
518
+
519
+ return true;
520
+ }
521
+
522
+ return false;
523
+ }
classes/class-cartflows-helper.php CHANGED
@@ -628,6 +628,7 @@ class Cartflows_Helper {
628
  'facebook_pixel_add_payment_info' => 'enable',
629
  'facebook_pixel_purchase_complete' => 'enable',
630
  'facebook_pixel_tracking' => 'disable',
 
631
  );
632
 
633
  $facebook = self::get_admin_settings_option( '_cartflows_facebook', false, false );
@@ -752,4 +753,25 @@ class Cartflows_Helper {
752
  return $params;
753
  }
754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  }
628
  'facebook_pixel_add_payment_info' => 'enable',
629
  'facebook_pixel_purchase_complete' => 'enable',
630
  'facebook_pixel_tracking' => 'disable',
631
+ 'facebook_pixel_tracking_for_site' => 'disable',
632
  );
633
 
634
  $facebook = self::get_admin_settings_option( '_cartflows_facebook', false, false );
753
  return $params;
754
  }
755
 
756
+ /**
757
+ * Get the image url of size.
758
+ *
759
+ * @param int $post_id post id.
760
+ * @param array $key key.
761
+ * @param string $size image size.
762
+ *
763
+ * @return array
764
+ */
765
+ public static function get_image_url( $post_id, $key, $size = false ) {
766
+
767
+ $url = get_post_meta( $post_id, $key, true );
768
+ $img_obj = get_post_meta( $post_id, $key . '-obj', true );
769
+ if ( is_array( $img_obj ) && ! empty( $img_obj ) && false !== $size ) {
770
+
771
+ $url = ! empty( $img_obj['url'][ $size ] ) ? $img_obj['url'][ $size ] : $url;
772
+ }
773
+
774
+ return $url;
775
+ }
776
+
777
  }
classes/class-cartflows-importer.php CHANGED
@@ -1,1694 +1,1694 @@
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
- public 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
- public 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
- public function export_flow() {
101
-
102
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
- wp_die( esc_html__( 'No post to export has been supplied!', 'cartflows' ) );
104
- }
105
-
106
- if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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 . '-' . gmdate( 'm-d-Y' ) . '.json' );
120
- header( 'Expires: 0' );
121
-
122
- echo wp_json_encode( $flows );
123
- exit;
124
- }
125
-
126
- /**
127
- * Export flow markup
128
- *
129
- * @since 1.1.4
130
- */
131
- public 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
- public 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
- public function export_json() {
150
- if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
- return;
152
- }
153
-
154
- if ( isset( $_POST['cartflows-action-nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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-' . gmdate( 'm-d-Y' ) . '.json' );
168
- header( 'Expires: 0' );
169
-
170
- echo wp_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
- public 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, true ) ) {
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
- public 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
- public function import_json() {
277
- if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
- return;
279
- }
280
-
281
- if ( isset( $_POST['cartflows-action-nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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']; //phpcs:ignore
290
- $file_info = explode( '.', $filename );
291
- $extension = end( $file_info );
292
-
293
- if ( 'json' != $extension ) {
294
- wp_die( esc_html__( 'Please upload a valid .json file', 'cartflows' ) );
295
- }
296
-
297
- $file = $_FILES['file']['tmp_name']; //phpcs:ignore
298
-
299
- if ( empty( $file ) ) {
300
- wp_die( esc_html__( '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 );//phpcs:ignore
305
-
306
- $this->import_from_json_data( $flows );
307
-
308
- add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
309
- }
310
-
311
- /**
312
- * Import flow from the JSON data
313
- *
314
- * @since x.x.x
315
- * @param array $flows JSON array.
316
- * @return void
317
- */
318
- public function import_from_json_data( $flows ) {
319
- if ( $flows ) {
320
-
321
- foreach ( $flows as $key => $flow ) {
322
-
323
- $flow_title = $flow['title'];
324
- if ( post_exists( $flow['title'] ) ) {
325
- $flow_title = $flow['title'] . ' Copy';
326
- }
327
-
328
- // Create post object.
329
- $new_flow_args = apply_filters(
330
- 'cartflows_flow_importer_args',
331
- array(
332
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
333
- 'post_title' => $flow_title,
334
- 'post_status' => 'draft',
335
- )
336
- );
337
-
338
- // Insert the post into the database.
339
- $flow_id = wp_insert_post( $new_flow_args );
340
-
341
- /**
342
- * Fire after flow import
343
- *
344
- * @since x.x.x
345
- * @param int $flow_id Flow ID.
346
- * @param array $new_flow_args Flow post args.
347
- * @param array $flows Flow JSON data.
348
- */
349
- do_action( 'cartflows_flow_imported', $flow_id, $new_flow_args, $flows );
350
-
351
- if ( $flow['steps'] ) {
352
- foreach ( $flow['steps'] as $key => $step ) {
353
-
354
- $new_step_args = apply_filters(
355
- 'cartflows_step_importer_args',
356
- array(
357
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
358
- 'post_title' => $step['title'],
359
- 'post_status' => 'publish',
360
- 'meta_input' => $step['meta'],
361
- 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
362
- )
363
- );
364
-
365
- $new_step_id = wp_insert_post( $new_step_args );
366
-
367
- /**
368
- * Fire after step import
369
- *
370
- * @since x.x.x
371
- * @param int $new_step_id step ID.
372
- * @param int $flow_id flow ID.
373
- * @param array $new_step_args Step post args.
374
- * @param array $flow_steps Flow steps.
375
- * @param array $flows All flows JSON data.
376
- */
377
- do_action( 'cartflows_step_imported', $new_step_id, $flow_id, $new_step_args, $flow['steps'], $flows );
378
-
379
- // Insert post meta.
380
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
381
-
382
- $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
383
- $current_term = term_exists( $step['type'], $step_taxonomy );
384
-
385
- // // Set type object.
386
- $data = get_term( $current_term['term_id'], $step_taxonomy );
387
- $step_slug = $data->slug;
388
- wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
389
-
390
- // Set type.
391
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
392
-
393
- // Set flow.
394
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
395
-
396
- self::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
397
-
398
- if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
399
-
400
- // Download and replace images.
401
- $content = $this->get_content( $step['post_content'] );
402
-
403
- // Update post content.
404
- wp_update_post(
405
- array(
406
- 'ID' => $new_step_id,
407
- 'post_content' => $content,
408
- )
409
- );
410
- }
411
- }
412
- }
413
- }
414
- }
415
- }
416
-
417
- /**
418
- * Download and Replace hotlink images
419
- *
420
- * @since x.x.x
421
- *
422
- * @param string $content Mixed post content.
423
- * @return array Hotlink image array.
424
- */
425
- public function get_content( $content = '' ) {
426
-
427
- $all_links = wp_extract_urls( $content );
428
- $image_links = array();
429
- $image_map = array();
430
-
431
- // Not have any link.
432
- if ( empty( $all_links ) ) {
433
- return $content;
434
- }
435
-
436
- foreach ( $all_links as $key => $link ) {
437
- if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
438
- $image_links[] = $link;
439
- }
440
- }
441
-
442
- // Not have any image link.
443
- if ( empty( $image_links ) ) {
444
- return $content;
445
- }
446
-
447
- foreach ( $image_links as $key => $image_url ) {
448
-
449
- // Download remote image.
450
- $image = array(
451
- 'url' => $image_url,
452
- 'id' => wp_rand( 000, 999 ),
453
- );
454
- $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
455
-
456
- // Old and New image mapping links.
457
- $image_map[ $image_url ] = $downloaded_image['url'];
458
- }
459
-
460
- // Replace old image links with new image links.
461
- foreach ( $image_map as $old_url => $new_url ) {
462
- $content = str_replace( $old_url, $new_url, $content );
463
- }
464
-
465
- return $content;
466
-
467
- }
468
-
469
- /**
470
- * Imported notice
471
- *
472
- * @since 1.1.4
473
- */
474
- public function imported_successfully() {
475
- ?>
476
- <div class="notice notice-success">
477
- <p><?php esc_html_e( 'Successfully imported flows.', 'cartflows' ); ?></p>
478
- </div>
479
- <?php
480
- }
481
-
482
- /**
483
- * Clear Cache.
484
- *
485
- * @since 1.0.0
486
- */
487
- public function clear_cache() {
488
- // Clear 'Elementor' file cache.
489
- if ( class_exists( '\Elementor\Plugin' ) ) {
490
- Elementor\Plugin::$instance->files_manager->clear_cache();
491
- }
492
- }
493
-
494
- /**
495
- * JS Templates
496
- *
497
- * @since 1.0.0
498
- *
499
- * @return void
500
- */
501
- public function js_templates() {
502
-
503
- // Loading Templates.
504
- ?>
505
- <script type="text/template" id="tmpl-cartflows-step-loading">
506
- <div class="template-message-block cartflows-step-loading">
507
- <h2>
508
- <span class="spinner"></span>
509
- <?php esc_html_e( 'Loading Steps', 'cartflows' ); ?>
510
- </h2>
511
- <p class="description"><?php esc_html_e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
512
- </div>
513
- </script>
514
-
515
- <?php
516
- // Search Templates.
517
- ?>
518
- <script type="text/template" id="tmpl-cartflows-searching-templates">
519
- <div class="template-message-block cartflows-searching-templates">
520
- <h2>
521
- <span class="spinner"></span>
522
- <?php esc_html_e( 'Searching Template..', 'cartflows' ); ?>
523
- </h2>
524
- <p class="description"><?php esc_html_e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
525
- </div>
526
- </script>
527
-
528
- <?php
529
- // CartFlows Importing Template.
530
- ?>
531
- <script type="text/template" id="tmpl-cartflows-step-importing">
532
- <div class="template-message-block cartflows-step-importing">
533
- <h2><span class="spinner"></span> <?php esc_html_e( 'Importing..', 'cartflows' ); ?></h2>
534
- </div>
535
- </script>
536
-
537
- <?php
538
- // CartFlows Imported.
539
- ?>
540
- <script type="text/template" id="tmpl-cartflows-step-imported">
541
- <div class="template-message-block cartflows-step-imported">
542
- <h2><span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Imported', 'cartflows' ); ?></h2>
543
- <p class="description"><?php esc_html_e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
544
- </script>
545
-
546
- <?php
547
- // No templates.
548
- ?>
549
- <script type="text/template" id="tmpl-cartflows-no-steps">
550
- <div class="cartflows-no-steps">
551
- <div class="template-message-block">
552
- <h2><?php esc_html_e( 'Coming Soon!', 'cartflows' ); ?></h2>
553
- <p class="description"></p>
554
- </div>
555
- </div>
556
- </script>
557
-
558
- <?php
559
- // No templates.
560
- ?>
561
- <script type="text/template" id="tmpl-cartflows-no-flows">
562
- <div class="cartflows-no-flows">
563
- <div class="template-message-block">
564
- <h2><?php esc_html_e( 'Coming Soon!', 'cartflows' ); ?></h2>
565
- <p class="description"></p>
566
- </div>
567
- </div>
568
- </script>
569
-
570
- <?php
571
- // Error handling.
572
- ?>
573
- <script type="text/template" id="tmpl-templator-error">
574
- <div class="notice notice-error"><p>{{ data }}</p></div>
575
- </script>
576
-
577
- <?php
578
- // Redirect to Elementor.
579
- ?>
580
- <script type="text/template" id="tmpl-templator-redirect-to-elementor">
581
- <div class="template-message-block templator-redirect-to-elementor">
582
- <h2><span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Imported', 'cartflows' ); ?></h2>
583
- <p class="description"><?php esc_html_e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php esc_html_e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
584
- </script>
585
-
586
- <?php
587
- /**
588
- * Responsive Buttons
589
- */
590
- ?>
591
- <script type="text/template" id="tmpl-cartflows-responsive-view">
592
- <span class="responsive-view">
593
- <span class="actions">
594
- <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
595
- <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
596
- <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
597
- </span>
598
- </span>
599
- </script>
600
-
601
- <?php
602
- // Templates data.
603
- ?>
604
- <script type="text/template" id="tmpl-cartflows-flows-list">
605
-
606
- <# console.log( data.items.length ) #>
607
- <# console.log( data.items ) #>
608
- <# if ( data.items.length ) { #>
609
- <# for ( key in data.items ) { #>
610
- <#
611
- var flow_steps = [];
612
- if( data.items[ key ].flow_steps ) {
613
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
614
- return value['id'];
615
- });
616
- }
617
- #>
618
- <div class="inner">
619
- <div class="template">
620
- <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 }}">
621
- <div class="template-screenshot">
622
- <# if( data.items[ key ].featured_image_url ) { #>
623
- <img src="{{ data.items[ key ].featured_image_url }}" />
624
- <# } else { #>
625
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
626
- <# } #>
627
- </div>
628
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
629
- <span class="wcf-flow-type pro"><?php esc_html_e( 'Pro', 'cartflows' ); ?></span>
630
- <# } #>
631
- <# if( data.items[ key ].woo_required ) { #>
632
- <div class="notice notice-info" style="width: auto;">
633
- <p class="wcf-learn-how">
634
- Install/Activate WooCommerce to use this template.
635
- <a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank">
636
- <strong><?php esc_html_e( 'Learn How', 'cartflows' ); ?></strong>
637
- <i class="dashicons dashicons-external"></i>
638
- </a>
639
- </p>
640
- </div>
641
- <# } else { #>
642
- <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>
643
- <# } #>
644
-
645
- </span>
646
- <div class="template-id-container">
647
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
648
- <div class="template-actions">
649
-
650
- <#
651
- if( data.items[ key ].page_builder.slug ) {
652
- required_plugin_group = data.items[ key ].page_builder.slug;
653
- } else {
654
- required_plugin_group = '';
655
- }
656
-
657
- 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 ) {
658
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
659
- } else {
660
- import_btn_title = 'Import';
661
- } #>
662
-
663
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
664
- <# if( ! data.items[ key ].woo_required ) { #>
665
- <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>
666
- <# } else { #>
667
- <a href='#' class='wcf-activate-wc button-primary'>Install & activate Woo</a>
668
- <# } #>
669
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
670
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Activate License', 'cartflows' ); ?></a>
671
- <# } else { #>
672
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php esc_html_e( 'Get Pro', 'cartflows' ); ?></a>
673
- <# } #>
674
- </div>
675
- </div>
676
- </div>
677
- </div>
678
- <# } #>
679
- <# } #>
680
- </script>
681
-
682
- <?php
683
- // Empty Step.
684
- ?>
685
- <script type="text/template" id="tmpl-cartflows-create-blank-step">
686
- <div class="inner">
687
- <div class="template">
688
- <span class="thumbnail site-preview cartflows-flow-preview">
689
- <div class="template-screenshot">
690
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
691
- </div>
692
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
693
- </span>
694
- <div class="template-id-container">
695
- <h3 class="template-name"> Blank </h3>
696
- <div class="template-actions">
697
- <a href="#" class="button button-primary cartflows-step-import-blank"><?php esc_html_e( 'Create', 'cartflows' ); ?></a>
698
- </div>
699
- </div>
700
- </div>
701
- </div>
702
- </script>
703
-
704
- <?php
705
- // Templates data.
706
- ?>
707
- <script type="text/template" id="tmpl-cartflows-steps-list">
708
- <# if ( data.items.length ) { #>
709
- <# for ( key in data.items ) { #>
710
- <#
711
- var flow_steps = [];
712
- if( data.items[ key ].flow_steps ) {
713
- flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
714
- return value['id'];
715
- });
716
- }
717
- #>
718
- <div class="inner">
719
- <div class="template">
720
- <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 }}">
721
- <div class="template-screenshot">
722
- <# if( data.items[ key ].featured_image_url ) { #>
723
- <img src="{{ data.items[ key ].featured_image_url }}" />
724
- <# } else { #>
725
- <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
726
- <# } #>
727
- </div>
728
- <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
729
-
730
- <# if( data.items[ key ].woo_required ) { #>
731
- <div class="notice notice-info" style="width: auto;">
732
- <p class="wcf-learn-how">
733
- Install/Activate WooCommerce to use this template.
734
- <a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank">
735
- <strong><?php esc_html_e( 'Learn How', 'cartflows' ); ?></strong>
736
- <i class="dashicons dashicons-external"></i>
737
- </a>
738
- </p>
739
- </div>
740
- <# } else { #>
741
- <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>
742
- <# } #>
743
-
744
- <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
745
- <span class="wcf-flow-type pro"><?php esc_html_e( 'Pro', 'cartflows' ); ?></span>
746
- <# } #>
747
- </span>
748
- <div class="template-id-container">
749
- <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
750
- <div class="template-actions">
751
-
752
- <#
753
-
754
- var step_slug = data.items[ key ].step_type.slug || '';
755
- var step_title = data.items[ key ].step_type.name || '';
756
- var import_btn_title = 'Import';
757
-
758
- var required_plugin_group = '';
759
- if( data.items[ key ].page_builder ) {
760
- required_plugin_group = data.items[ key ].page_builder.slug;
761
-
762
- 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 ) {
763
- import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
764
- }
765
- }
766
- #>
767
-
768
- <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
769
-
770
- <# if( ! data.items[ key ].woo_required ) { #>
771
- <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>
772
- <# } else { #>
773
- <a href='#' class='wcf-activate-wc button-primary'>Install & activate Woo</a>
774
- <# } #>
775
-
776
- <# } else if( CartFlowsImportVars._is_pro_active ) { #>
777
- <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Activate License', 'cartflows' ); ?></a>
778
- <# } else { #>
779
- <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php esc_html_e( 'Get Pro', 'cartflows' ); ?></a>
780
- <# } #>
781
- </div>
782
- </div>
783
- </div>
784
- </div>
785
- <# } #>
786
- <# } #>
787
- </script>
788
-
789
- <?php
790
- /**
791
- * TMPL - Website Unreachable
792
- */
793
- ?>
794
- <script type="text/template" id="tmpl-cartflows-website-unreachable">
795
- <div class="postbox cartflows-website-unreachable">
796
- <h2><?php esc_html_e( 'Under Maintenance..', 'cartflows' ); ?></h2>
797
- <p><?php esc_html_e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
798
- <p><?php esc_html_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>
799
- </div>
800
- </script>
801
-
802
- <?php
803
- /**
804
- * TMPL - Filters
805
- */
806
- ?>
807
- <script type="text/template" id="tmpl-cartflows-page-builder-notice">
808
- <?php
809
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
810
- $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
811
- $title = $page_builder['title'];
812
-
813
- $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
814
- $theme_status = '';
815
- if ( 'divi' === $default_page_builder ) {
816
-
817
- $theme_status = $page_builder['theme-status'];
818
- $plugin_status = $page_builder['plugin-status'];
819
-
820
- if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
821
- $plugin_string = 'Please activate ' . esc_html( $title );
822
- } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
823
- $plugin_string = 'Please install and activate ' . esc_html( $title );
824
- }
825
- }
826
- ?>
827
- <div class="wcf-page-builder-message">
828
- <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>
829
- <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>
830
- <p>We plan to add design templates made with more page builder shortly!</p>
831
- </div>
832
- </script>
833
-
834
- <?php
835
- /**
836
- * TMPL - Filters
837
- */
838
- ?>
839
- <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
840
- <# if ( data ) { #>
841
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
842
- <# if ( data.args.show_all ) { #>
843
- <option value="all"> <?php esc_html_e( 'All', 'cartflows' ); ?> </option>
844
- <# } #>
845
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
846
- <option value=""> <?php esc_html_e( 'Select Step Type', 'cartflows' ); ?> </option>
847
- <# } #>
848
- <# var step_slug_data = []; #>
849
- <# for ( key in data.items ) { #>
850
- <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>
851
-
852
- <# step_slug_data.push( data.items[ key ].slug ); #>
853
-
854
- <# } #>
855
- <# if( step_slug_data.indexOf("optin") === -1){ #>
856
- <option value='0' data-group='0' class="Optin (Woo)" data-slug="optin" data-title="Optin (Woo)">Optin (Woo)</option>
857
- <# } #>
858
- </select>
859
- <# } #>
860
- </script>
861
-
862
- <script type="text/template" id="tmpl-cartflows-term-filters">
863
-
864
- <# if ( data ) { #>
865
-
866
- <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
867
- <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
868
-
869
- <# if ( data.args.show_all ) { #>
870
- <li>
871
- <a href="#" data-group="all"> All </a>
872
- </li>
873
- <# } #>
874
-
875
- <# for ( key in data.items ) { #>
876
- <li>
877
- <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>
878
- </li>
879
- <# } #>
880
-
881
- </ul>
882
-
883
- <?php
884
-
885
- /**
886
- <# } else { #>
887
- <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
888
-
889
- <# if ( data.args.show_all ) { #>
890
- <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
891
- <# } #>
892
-
893
- <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
894
- <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
895
- <# } #>
896
-
897
- <# for ( key in data.items ) { #>
898
- <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>
899
- <# } #>
900
-
901
- </select>
902
- */
903
- ?>
904
-
905
- <?php /* <# } #> */ ?>
906
-
907
- <# } #>
908
- </script>
909
-
910
- <?php
911
- // Step Type.
912
- ?>
913
- <script type="text/template" id="tmpl-cartflows-step-types">
914
- <ul class="wcf-tab nav-tabs">
915
- <# if( data.items_count ) { #>
916
- <# for( key in data.items ) { #>
917
- <# console.log( data.items[ key ].id ) #>
918
- <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
919
- <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
920
- </li>
921
- <# } #>
922
- <# } #>
923
- </ul>
924
- </script>
925
-
926
- <?php
927
- // Add to library button.
928
- ?>
929
- <script type="text/template" id="tmpl-templator-add-to-library">
930
- <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>
931
- </script>
932
- <?php
933
- }
934
-
935
- /**
936
- * Enqueue scripts
937
- *
938
- * @since 1.0.0
939
- *
940
- * @hook admin_enqueue_scripts
941
- * @param string $hook Current page hook.
942
- */
943
- public function scripts( $hook = '' ) {
944
-
945
- if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
946
- return;
947
- }
948
-
949
- wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
950
- wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
951
- wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
952
- wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
953
-
954
- $installed_plugins = get_plugins();
955
- $is_wc_installed = isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? 'yes' : 'no';
956
- $is_wc_activated = wcf()->is_woo_active ? 'yes' : 'no';
957
-
958
- $localize_vars = array(
959
- '_is_pro_active' => _is_cartflows_pro(),
960
- 'is_wc_installed' => $is_wc_installed,
961
- 'is_wc_activated' => $is_wc_activated,
962
-
963
- // Flow and its rest fields.
964
- 'flow' => CARTFLOWS_FLOW_POST_TYPE,
965
- 'flow_fields' => array(
966
- 'id',
967
- 'title',
968
- 'flow_type',
969
- 'page_builder',
970
- 'flow_steps',
971
- 'licence_status',
972
- 'featured_image_url',
973
- 'featured_media', // @required for field `featured_image_url`.
974
- ),
975
-
976
- // Flow type and rest fields.
977
- 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
978
- 'flow_type_fields' => array(
979
- 'id',
980
- 'name',
981
- 'slug',
982
- ),
983
-
984
- // Flow page builder and rest fields.
985
- 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
986
- 'flow_page_builder_fields' => array(
987
- 'id',
988
- 'name',
989
- 'slug',
990
- ),
991
-
992
- // Step page builder and rest fields.
993
- 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
994
- 'step_page_builder_fields' => array(
995
- 'id',
996
- 'name',
997
- 'slug',
998
- ),
999
-
1000
- // Step and its rest fields.
1001
- 'step' => CARTFLOWS_STEP_POST_TYPE,
1002
- 'step_fields' => array(
1003
- 'title',
1004
- 'featured_image_url',
1005
- 'featured_media', // @required for field `featured_image_url`.
1006
- 'id',
1007
- 'flow_type',
1008
- 'step_type',
1009
- 'page_builder',
1010
- 'licence_status',
1011
- ),
1012
-
1013
- // Step type and its rest fields.
1014
- 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
1015
- 'step_type_fields' => array(
1016
- 'id',
1017
- 'name',
1018
- 'slug',
1019
- ),
1020
-
1021
- 'domain_url' => CARTFLOWS_DOMAIN_URL,
1022
- 'server_url' => CARTFLOWS_TEMPLATES_URL,
1023
- 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
1024
- 'site_url' => site_url(),
1025
- 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
1026
- 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
1027
- 'admin_url' => admin_url(),
1028
- 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
1029
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1030
- 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false, //phpcs:ignore
1031
-
1032
- 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
1033
-
1034
- 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
1035
- );
1036
-
1037
- $localize_vars['cartflows_activate_plugin_nonce'] = wp_create_nonce( 'cartflows_activate_plugin' );
1038
-
1039
- // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
1040
- // wp_die( );
1041
- // Add thickbox.
1042
- add_thickbox();
1043
-
1044
- wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
1045
- wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
1046
- }
1047
-
1048
- /**
1049
- * Load Template
1050
- *
1051
- * @since 1.0.0
1052
- *
1053
- * @hook cartflows_load_steps
1054
- * @return void
1055
- */
1056
- public function load_templates() {
1057
-
1058
- check_ajax_referer( 'cf-load-steps', 'security' );
1059
-
1060
- $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array(); //phpcs:ignore
1061
- $templates = CartFlows_API::get_instance()->get_templates( $args );
1062
-
1063
- if ( $templates['templates_count'] ) {
1064
- wp_send_json_success( $templates );
1065
- } else {
1066
- wp_send_json_error( $templates );
1067
- }
1068
- wp_die();
1069
- }
1070
-
1071
- /**
1072
- * Import.
1073
- *
1074
- * @since 1.0.0
1075
- *
1076
- * @hook wp_ajax_cartflows_import_flow_step
1077
- * @return void
1078
- */
1079
- public function import_flow() {
1080
-
1081
- check_ajax_referer( 'cf-import-flow-step', 'security' );
1082
-
1083
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1084
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1085
-
1086
- wcf()->logger->import_log( '------------------------------------' );
1087
- wcf()->logger->import_log( 'STARTED! Importing FLOW' );
1088
- wcf()->logger->import_log( '------------------------------------' );
1089
- wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
1090
-
1091
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1092
-
1093
- $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1094
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1095
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1096
- $post_content = $response['data']['divi_content'];
1097
- }
1098
- }
1099
-
1100
- if ( false === $response['success'] ) {
1101
- wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1102
- wp_send_json_error( $response );
1103
- }
1104
-
1105
- wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . wp_json_encode( $response ) );
1106
-
1107
- $new_step_id = wp_insert_post(
1108
- array(
1109
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1110
- 'post_title' => $response['title'],
1111
- 'post_content' => $post_content,
1112
- 'post_status' => 'publish',
1113
- )
1114
- );
1115
-
1116
- if ( is_wp_error( $new_step_id ) ) {
1117
- wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1118
- wp_send_json_error( $new_step_id );
1119
- }
1120
-
1121
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1122
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1123
- update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1124
- }
1125
- }
1126
-
1127
- /* Imported Step */
1128
- update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1129
-
1130
- wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );//phpcs:ignore
1131
- // insert post meta.
1132
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1133
- wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1134
-
1135
- /**
1136
- * Import & Set type.
1137
- */
1138
- $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1139
-
1140
- $term_slug = '';
1141
- if ( $term ) {
1142
-
1143
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1144
- $term_exist = term_exists( $term->slug, $taxonomy );
1145
-
1146
- if ( empty( $term_exist ) ) {
1147
- $terms = array(
1148
- array(
1149
- 'name' => $term->name,
1150
- 'slug' => $term->slug,
1151
- ),
1152
- );
1153
-
1154
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1155
- wcf()->logger->import_log( '(✓) Created new term name ' . $term->name . ' | term slug ' . $term->slug );
1156
- }
1157
-
1158
- $current_term = term_exists( $term->slug, $taxonomy );
1159
-
1160
- // Set type object.
1161
- $data = get_term( $current_term['term_id'], $taxonomy );
1162
- $term_slug = $data->slug;
1163
- $term_name = $data->name;
1164
- wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1165
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1166
-
1167
- // Set type.
1168
- update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1169
- wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1170
- }
1171
-
1172
- // Set flow.
1173
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1174
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1175
-
1176
- /**
1177
- * Update steps for the current flow.
1178
- */
1179
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1180
-
1181
- if ( ! is_array( $flow_steps ) ) {
1182
- $flow_steps = array();
1183
- }
1184
-
1185
- $flow_steps[] = array(
1186
- 'id' => $new_step_id,
1187
- 'title' => $response['title'],
1188
- 'type' => $term_slug,
1189
- );
1190
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1191
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . wp_json_encode( $flow_steps ) );
1192
-
1193
- // Import Post Meta.
1194
- self::import_post_meta( $new_step_id, $response );
1195
-
1196
- wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1197
- wcf()->logger->import_log( '------------------------------------' );
1198
- wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1199
- wcf()->logger->import_log( '------------------------------------' );
1200
-
1201
- do_action( 'cartflows_import_complete' );
1202
- wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1203
-
1204
- // Batch Process.
1205
- do_action( 'cartflows_after_template_import', $new_step_id, $response );
1206
-
1207
- /**
1208
- * End
1209
- */
1210
- wp_send_json_success( $new_step_id );
1211
- }
1212
-
1213
- /**
1214
- * Import Step.
1215
- *
1216
- * @since 1.0.0
1217
- * @hook wp_ajax_cartflows_step_import
1218
- *
1219
- * @return void
1220
- */
1221
- public function create_default_flow() {
1222
-
1223
- check_ajax_referer( 'cf-default-flow', 'security' );
1224
-
1225
- // Create post object.
1226
- $new_flow_post = array(
1227
- 'post_content' => '',
1228
- 'post_status' => 'publish',
1229
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1230
- );
1231
-
1232
- // Insert the post into the database.
1233
- $flow_id = wp_insert_post( $new_flow_post );
1234
-
1235
- if ( is_wp_error( $flow_id ) ) {
1236
- wp_send_json_error( $flow_id->get_error_message() );
1237
- }
1238
-
1239
- $flow_steps = array();
1240
-
1241
- if ( wcf()->is_woo_active ) {
1242
- $steps_data = array(
1243
- 'sales' => array(
1244
- 'title' => __( 'Sales Landing', 'cartflows' ),
1245
- 'type' => 'landing',
1246
- ),
1247
- 'order-form' => array(
1248
- 'title' => __( 'Checkout (Woo)', 'cartflows' ),
1249
- 'type' => 'checkout',
1250
- ),
1251
- 'order-confirmation' => array(
1252
- 'title' => __( 'Thank You (Woo)', 'cartflows' ),
1253
- 'type' => 'thankyou',
1254
- ),
1255
- );
1256
-
1257
- } else {
1258
- $steps_data = array(
1259
- 'landing' => array(
1260
- 'title' => __( 'Landing', 'cartflows' ),
1261
- 'type' => 'landing',
1262
- ),
1263
- 'thankyou' => array(
1264
- 'title' => __( 'Thank You', 'cartflows' ),
1265
- 'type' => 'landing',
1266
- ),
1267
- );
1268
- }
1269
-
1270
- foreach ( $steps_data as $slug => $data ) {
1271
-
1272
- $post_content = '';
1273
- $step_type = trim( $data['type'] );
1274
-
1275
- $step_id = wp_insert_post(
1276
- array(
1277
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1278
- 'post_title' => $data['title'],
1279
- 'post_content' => $post_content,
1280
- 'post_status' => 'publish',
1281
- )
1282
- );
1283
-
1284
- if ( is_wp_error( $step_id ) ) {
1285
- wp_send_json_error( $step_id->get_error_message() );
1286
- }
1287
-
1288
- if ( $step_id ) {
1289
-
1290
- $flow_steps[] = array(
1291
- 'id' => $step_id,
1292
- 'title' => $data['title'],
1293
- 'type' => $step_type,
1294
- );
1295
-
1296
- // insert post meta.
1297
- update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1298
- update_post_meta( $step_id, 'wcf-step-type', $step_type );
1299
-
1300
- wp_set_object_terms( $step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
1301
- wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1302
-
1303
- update_post_meta( $step_id, '_wp_page_template', 'cartflows-default' );
1304
- }
1305
- }
1306
-
1307
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1308
-
1309
- wp_send_json_success( $flow_id );
1310
- }
1311
-
1312
- /**
1313
- * Create Flow
1314
- *
1315
- * @return void
1316
- */
1317
- public function create_flow() {
1318
-
1319
- check_ajax_referer( 'cf-create-flow', 'security' );
1320
-
1321
- // Create post object.
1322
- $new_flow_post = array(
1323
- 'post_content' => '',
1324
- 'post_status' => 'publish',
1325
- 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1326
- );
1327
-
1328
- // Insert the post into the database.
1329
- $flow_id = wp_insert_post( $new_flow_post );
1330
-
1331
- if ( is_wp_error( $flow_id ) ) {
1332
- wp_send_json_error( $flow_id->get_error_message() );
1333
- }
1334
-
1335
- /* Imported Flow */
1336
- update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1337
-
1338
- wp_send_json_success( $flow_id );
1339
- }
1340
-
1341
- /**
1342
- * Create Step
1343
- *
1344
- * @return void
1345
- */
1346
- public function import_step() {
1347
-
1348
- check_ajax_referer( 'cf-step-import', 'security' );
1349
-
1350
- $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1351
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1352
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( wp_unslash( $_POST['step_title'] ) ) : '';
1353
- $step_type = isset( $_POST['step_type'] ) ? sanitize_title( wp_unslash( $_POST['step_type'] ) ) : '';
1354
- $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( wp_unslash( $_POST['step_custom_title'] ) ) : $step_title;
1355
-
1356
- $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1357
-
1358
- $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1359
-
1360
- wcf()->logger->import_log( '------------------------------------' );
1361
- wcf()->logger->import_log( 'STARTED! Importing STEP' );
1362
- wcf()->logger->import_log( '------------------------------------' );
1363
-
1364
- if ( empty( $template_id ) || empty( $post_id ) ) {
1365
- /* translators: %s: template ID */
1366
- $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1367
- wcf()->logger->import_log( $data );
1368
- wp_send_json_error( $data );
1369
- }
1370
-
1371
- wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1372
-
1373
- $response = CartFlows_API::get_instance()->get_template( $template_id );
1374
-
1375
- if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1376
- if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1377
- update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1378
-
1379
- wp_update_post(
1380
- array(
1381
- 'ID' => $post_id,
1382
- 'post_content' => $response['data']['divi_content'],
1383
- )
1384
- );
1385
- }
1386
- }
1387
-
1388
- /* Imported Step */
1389
- update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1390
-
1391
- // Import Post Meta.
1392
- self::import_post_meta( $post_id, $response );
1393
-
1394
- do_action( 'cartflows_import_complete' );
1395
-
1396
- // Batch Process.
1397
- do_action( 'cartflows_after_template_import', $post_id, $response );
1398
-
1399
- wcf()->logger->import_log( '------------------------------------' );
1400
- wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1401
- wcf()->logger->import_log( '------------------------------------' );
1402
-
1403
- wp_send_json_success( $post_id );
1404
- }
1405
-
1406
- /**
1407
- * Import Step.
1408
- *
1409
- * @since 1.0.0
1410
- * @hook wp_ajax_cartflows_step_create_blank
1411
- *
1412
- * @return void
1413
- */
1414
- public function step_create_blank() {
1415
-
1416
- check_ajax_referer( 'cf-step-create-blank', 'security' );
1417
-
1418
- $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1419
- $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( wp_unslash( $_POST['step_type'] ) ) : '';
1420
- $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( wp_unslash( $_POST['step_title'] ) ) : '';
1421
-
1422
- if ( empty( $flow_id ) || empty( $step_type ) ) {
1423
- /* translators: %s: flow ID */
1424
- $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1425
- wcf()->logger->import_log( $data );
1426
- wp_send_json_error( $data );
1427
- }
1428
-
1429
- wcf()->logger->import_log( '------------------------------------' );
1430
- wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1431
-
1432
- $step_type_title = str_replace( '-', ' ', $step_type );
1433
- $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1434
-
1435
- $new_step_id = wp_insert_post(
1436
- array(
1437
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1438
- 'post_title' => $step_title,
1439
- 'post_content' => '',
1440
- 'post_status' => 'publish',
1441
- )
1442
- );
1443
-
1444
- // insert post meta.
1445
- update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1446
-
1447
- $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1448
- $term_exist = term_exists( $step_type_slug, $taxonomy );
1449
-
1450
- if ( empty( $term_exist ) ) {
1451
- $terms = array(
1452
- array(
1453
- 'name' => $step_type_title,
1454
- 'slug' => $step_type_slug,
1455
- ),
1456
- );
1457
-
1458
- Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1459
- wcf()->logger->import_log( '(✓) Created new term name ' . $step_type_title . ' | term slug ' . $step_type_slug );
1460
- }
1461
-
1462
- $current_term = term_exists( $step_type_slug, $taxonomy );
1463
-
1464
- // Set type object.
1465
- $data = get_term( $current_term['term_id'], $taxonomy );
1466
- $step_slug = $data->slug;
1467
- wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1468
- wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1469
-
1470
- // Set Default page Layout.
1471
- update_post_meta( $new_step_id, '_wp_page_template', 'cartflows-default' );
1472
-
1473
- // Set type.
1474
- update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1475
- wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1476
-
1477
- // Set flow.
1478
- wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1479
- wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1480
-
1481
- self::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1482
-
1483
- wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1484
- wcf()->logger->import_log( '------------------------------------' );
1485
-
1486
- wp_send_json_success( $new_step_id );
1487
- }
1488
-
1489
- /**
1490
- * Import Post Meta
1491
- *
1492
- * @since 1.0.0
1493
- *
1494
- * @param integer $post_id Post ID.
1495
- * @param array $response Post meta.
1496
- * @return void
1497
- */
1498
- public static function import_post_meta( $post_id, $response ) {
1499
-
1500
- $metadata = (array) $response['post_meta'];
1501
-
1502
- foreach ( $metadata as $meta_key => $meta_value ) {
1503
- $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1504
-
1505
- if ( $meta_value ) {
1506
-
1507
- if ( is_serialized( $meta_value, true ) ) {
1508
- $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1509
- } elseif ( is_array( $meta_value ) ) {
1510
- $raw_data = json_decode( stripslashes( $meta_value ), true );
1511
- } else {
1512
- $raw_data = $meta_value;
1513
- }
1514
-
1515
- if ( '_elementor_data' === $meta_key ) {
1516
- if ( is_array( $raw_data ) ) {
1517
- $raw_data = wp_slash( wp_json_encode( $raw_data ) );
1518
- } else {
1519
- $raw_data = wp_slash( $raw_data );
1520
- }
1521
- }
1522
- if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1523
- if ( is_array( $raw_data ) ) {
1524
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . wp_json_encode( $raw_data ) );
1525
- } else {
1526
- if ( ! is_object( $raw_data ) ) {
1527
- wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1528
- }
1529
- }
1530
- }
1531
-
1532
- update_post_meta( $post_id, $meta_key, $raw_data );
1533
- }
1534
- }
1535
- }
1536
-
1537
- /**
1538
- * Import Template for Elementor
1539
- *
1540
- * @since 1.0.0
1541
- *
1542
- * @param integer $post_id Post ID.
1543
- * @param array $response Post meta.
1544
- * @param array $page_build_data Page build data.
1545
- * @return void
1546
- */
1547
- public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1548
- if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1549
- $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1550
- wcf()->logger->import_log( $data );
1551
- wp_send_json_error( $data );
1552
- }
1553
-
1554
- require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1555
-
1556
- wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1557
-
1558
- $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1559
- $obj->import_single_template( $post_id );
1560
-
1561
- wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1562
- }
1563
-
1564
- /**
1565
- * Supported post types
1566
- *
1567
- * @since 1.0.0
1568
- *
1569
- * @return array Supported post types.
1570
- */
1571
- public static function supported_post_types() {
1572
- return apply_filters(
1573
- 'cartflows_supported_post_types',
1574
- array(
1575
- CARTFLOWS_FLOW_POST_TYPE,
1576
- )
1577
- );
1578
- }
1579
-
1580
- /**
1581
- * Check supported post type
1582
- *
1583
- * @since 1.0.0
1584
- *
1585
- * @param string $post_type Post type.
1586
- * @return boolean Supported post type status.
1587
- */
1588
- public static function is_supported_post( $post_type = '' ) {
1589
-
1590
- if ( in_array( $post_type, self::supported_post_types(), true ) ) {
1591
- return true;
1592
- }
1593
-
1594
- return false;
1595
- }
1596
-
1597
- /**
1598
- * Set steps to the flow
1599
- *
1600
- * @param integer $flow_id Flow ID.
1601
- * @param integer $new_step_id New step ID.
1602
- * @param string $step_title Flow Type.
1603
- * @param string $step_slug Flow Type.
1604
- */
1605
- public function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1606
- // Update steps for the current flow.
1607
- $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1608
-
1609
- if ( ! is_array( $flow_steps ) ) {
1610
- $flow_steps = array();
1611
- }
1612
-
1613
- $flow_steps[] = array(
1614
- 'id' => $new_step_id,
1615
- 'title' => $step_title,
1616
- 'type' => $step_slug,
1617
- );
1618
- update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1619
- wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . wp_json_encode( $flow_steps ) );
1620
- }
1621
-
1622
- /**
1623
- * Localize variables in admin
1624
- *
1625
- * @param array $vars variables.
1626
- */
1627
- public function localize_vars( $vars ) {
1628
-
1629
- $ajax_actions = array(
1630
- 'cf_step_import',
1631
- 'cf_load_steps',
1632
- 'cf_create_flow',
1633
- 'cf_default_flow',
1634
- 'cf_step_create_blank',
1635
- 'cf_import_flow_step',
1636
- );
1637
-
1638
- foreach ( $ajax_actions as $action ) {
1639
-
1640
- $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1641
- }
1642
-
1643
- return $vars;
1644
- }
1645
-
1646
- /**
1647
- * Ajax action to activate plugin
1648
- */
1649
- public function activate_plugin() {
1650
-
1651
- if ( ! check_ajax_referer( 'cartflows_activate_plugin', 'security', false ) ) {
1652
- wp_send_json_error( esc_html__( 'Action failed. Invalid Security Nonce.', 'cartflows' ) );
1653
- }
1654
-
1655
- if ( ! current_user_can( 'activate_plugins' ) ) {
1656
- wp_send_json_error(
1657
- array(
1658
- 'success' => false,
1659
- 'message' => __( 'User have not plugin install permissions.', 'cartflows' ),
1660
- )
1661
- );
1662
- }
1663
-
1664
- $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_init'] ) ) : '';
1665
-
1666
- $activate = activate_plugin( $plugin_init, '', false, true );
1667
-
1668
- if ( is_wp_error( $activate ) ) {
1669
- wp_send_json_error(
1670
- array(
1671
- 'success' => false,
1672
- 'message' => $activate->get_error_message(),
1673
- 'init' => $plugin_init,
1674
- )
1675
- );
1676
- }
1677
-
1678
- wp_send_json_success(
1679
- array(
1680
- 'success' => true,
1681
- 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1682
- 'init' => $plugin_init,
1683
- )
1684
- );
1685
- }
1686
-
1687
- }
1688
-
1689
- /**
1690
- * Initialize class object with 'get_instance()' method
1691
- */
1692
- CartFlows_Importer::get_instance();
1693
-
1694
- 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
+ public 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
+ public 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
+ public function export_flow() {
101
+
102
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'cartflows_export_flow' == $_REQUEST['action'] ) ) ) {
103
+ wp_die( esc_html__( 'No post to export has been supplied!', 'cartflows' ) );
104
+ }
105
+
106
+ if ( ! isset( $_GET['flow_export_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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 . '-' . gmdate( 'm-d-Y' ) . '.json' );
120
+ header( 'Expires: 0' );
121
+
122
+ echo wp_json_encode( $flows );
123
+ exit;
124
+ }
125
+
126
+ /**
127
+ * Export flow markup
128
+ *
129
+ * @since 1.1.4
130
+ */
131
+ public 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
+ public 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
+ public function export_json() {
150
+ if ( empty( $_POST['cartflows-action'] ) || 'export' != $_POST['cartflows-action'] ) {
151
+ return;
152
+ }
153
+
154
+ if ( isset( $_POST['cartflows-action-nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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-' . gmdate( 'm-d-Y' ) . '.json' );
168
+ header( 'Expires: 0' );
169
+
170
+ echo wp_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
+ public 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, true ) ) {
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
+ public 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
+ public function import_json() {
277
+ if ( empty( $_POST['cartflows-action'] ) || 'import' != $_POST['cartflows-action'] ) {
278
+ return;
279
+ }
280
+
281
+ if ( isset( $_POST['cartflows-action-nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_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']; //phpcs:ignore
290
+ $file_info = explode( '.', $filename );
291
+ $extension = end( $file_info );
292
+
293
+ if ( 'json' != $extension ) {
294
+ wp_die( esc_html__( 'Please upload a valid .json file', 'cartflows' ) );
295
+ }
296
+
297
+ $file = $_FILES['file']['tmp_name']; //phpcs:ignore
298
+
299
+ if ( empty( $file ) ) {
300
+ wp_die( esc_html__( '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 );//phpcs:ignore
305
+
306
+ $this->import_from_json_data( $flows );
307
+
308
+ add_action( 'admin_notices', array( $this, 'imported_successfully' ) );
309
+ }
310
+
311
+ /**
312
+ * Import flow from the JSON data
313
+ *
314
+ * @since x.x.x
315
+ * @param array $flows JSON array.
316
+ * @return void
317
+ */
318
+ public function import_from_json_data( $flows ) {
319
+ if ( $flows ) {
320
+
321
+ foreach ( $flows as $key => $flow ) {
322
+
323
+ $flow_title = $flow['title'];
324
+ if ( post_exists( $flow['title'] ) ) {
325
+ $flow_title = $flow['title'] . ' Copy';
326
+ }
327
+
328
+ // Create post object.
329
+ $new_flow_args = apply_filters(
330
+ 'cartflows_flow_importer_args',
331
+ array(
332
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
333
+ 'post_title' => $flow_title,
334
+ 'post_status' => 'draft',
335
+ )
336
+ );
337
+
338
+ // Insert the post into the database.
339
+ $flow_id = wp_insert_post( $new_flow_args );
340
+
341
+ /**
342
+ * Fire after flow import
343
+ *
344
+ * @since x.x.x
345
+ * @param int $flow_id Flow ID.
346
+ * @param array $new_flow_args Flow post args.
347
+ * @param array $flows Flow JSON data.
348
+ */
349
+ do_action( 'cartflows_flow_imported', $flow_id, $new_flow_args, $flows );
350
+
351
+ if ( $flow['steps'] ) {
352
+ foreach ( $flow['steps'] as $key => $step ) {
353
+
354
+ $new_step_args = apply_filters(
355
+ 'cartflows_step_importer_args',
356
+ array(
357
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
358
+ 'post_title' => $step['title'],
359
+ 'post_status' => 'publish',
360
+ 'meta_input' => $step['meta'],
361
+ 'post_content' => isset( $step['post_content'] ) ? $step['post_content'] : '',
362
+ )
363
+ );
364
+
365
+ $new_step_id = wp_insert_post( $new_step_args );
366
+
367
+ /**
368
+ * Fire after step import
369
+ *
370
+ * @since x.x.x
371
+ * @param int $new_step_id step ID.
372
+ * @param int $flow_id flow ID.
373
+ * @param array $new_step_args Step post args.
374
+ * @param array $flow_steps Flow steps.
375
+ * @param array $flows All flows JSON data.
376
+ */
377
+ do_action( 'cartflows_step_imported', $new_step_id, $flow_id, $new_step_args, $flow['steps'], $flows );
378
+
379
+ // Insert post meta.
380
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
381
+
382
+ $step_taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
383
+ $current_term = term_exists( $step['type'], $step_taxonomy );
384
+
385
+ // // Set type object.
386
+ $data = get_term( $current_term['term_id'], $step_taxonomy );
387
+ $step_slug = $data->slug;
388
+ wp_set_object_terms( $new_step_id, $data->slug, $step_taxonomy );
389
+
390
+ // Set type.
391
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
392
+
393
+ // Set flow.
394
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
395
+
396
+ self::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step['title'], $step_slug );
397
+
398
+ if ( isset( $step['post_content'] ) && ! empty( $step['post_content'] ) ) {
399
+
400
+ // Download and replace images.
401
+ $content = $this->get_content( $step['post_content'] );
402
+
403
+ // Update post content.
404
+ wp_update_post(
405
+ array(
406
+ 'ID' => $new_step_id,
407
+ 'post_content' => $content,
408
+ )
409
+ );
410
+ }
411
+ }
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Download and Replace hotlink images
419
+ *
420
+ * @since x.x.x
421
+ *
422
+ * @param string $content Mixed post content.
423
+ * @return array Hotlink image array.
424
+ */
425
+ public function get_content( $content = '' ) {
426
+
427
+ $all_links = wp_extract_urls( $content );
428
+ $image_links = array();
429
+ $image_map = array();
430
+
431
+ // Not have any link.
432
+ if ( empty( $all_links ) ) {
433
+ return $content;
434
+ }
435
+
436
+ foreach ( $all_links as $key => $link ) {
437
+ if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $link ) ) {
438
+ $image_links[] = $link;
439
+ }
440
+ }
441
+
442
+ // Not have any image link.
443
+ if ( empty( $image_links ) ) {
444
+ return $content;
445
+ }
446
+
447
+ foreach ( $image_links as $key => $image_url ) {
448
+
449
+ // Download remote image.
450
+ $image = array(
451
+ 'url' => $image_url,
452
+ 'id' => wp_rand( 000, 999 ),
453
+ );
454
+ $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
455
+
456
+ // Old and New image mapping links.
457
+ $image_map[ $image_url ] = $downloaded_image['url'];
458
+ }
459
+
460
+ // Replace old image links with new image links.
461
+ foreach ( $image_map as $old_url => $new_url ) {
462
+ $content = str_replace( $old_url, $new_url, $content );
463
+ }
464
+
465
+ return $content;
466
+
467
+ }
468
+
469
+ /**
470
+ * Imported notice
471
+ *
472
+ * @since 1.1.4
473
+ */
474
+ public function imported_successfully() {
475
+ ?>
476
+ <div class="notice notice-success">
477
+ <p><?php esc_html_e( 'Successfully imported flows.', 'cartflows' ); ?></p>
478
+ </div>
479
+ <?php
480
+ }
481
+
482
+ /**
483
+ * Clear Cache.
484
+ *
485
+ * @since 1.0.0
486
+ */
487
+ public function clear_cache() {
488
+ // Clear 'Elementor' file cache.
489
+ if ( class_exists( '\Elementor\Plugin' ) ) {
490
+ Elementor\Plugin::$instance->files_manager->clear_cache();
491
+ }
492
+ }
493
+
494
+ /**
495
+ * JS Templates
496
+ *
497
+ * @since 1.0.0
498
+ *
499
+ * @return void
500
+ */
501
+ public function js_templates() {
502
+
503
+ // Loading Templates.
504
+ ?>
505
+ <script type="text/template" id="tmpl-cartflows-step-loading">
506
+ <div class="template-message-block cartflows-step-loading">
507
+ <h2>
508
+ <span class="spinner"></span>
509
+ <?php esc_html_e( 'Loading Steps', 'cartflows' ); ?>
510
+ </h2>
511
+ <p class="description"><?php esc_html_e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
512
+ </div>
513
+ </script>
514
+
515
+ <?php
516
+ // Search Templates.
517
+ ?>
518
+ <script type="text/template" id="tmpl-cartflows-searching-templates">
519
+ <div class="template-message-block cartflows-searching-templates">
520
+ <h2>
521
+ <span class="spinner"></span>
522
+ <?php esc_html_e( 'Searching Template..', 'cartflows' ); ?>
523
+ </h2>
524
+ <p class="description"><?php esc_html_e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
525
+ </div>
526
+ </script>
527
+
528
+ <?php
529
+ // CartFlows Importing Template.
530
+ ?>
531
+ <script type="text/template" id="tmpl-cartflows-step-importing">
532
+ <div class="template-message-block cartflows-step-importing">
533
+ <h2><span class="spinner"></span> <?php esc_html_e( 'Importing..', 'cartflows' ); ?></h2>
534
+ </div>
535
+ </script>
536
+
537
+ <?php
538
+ // CartFlows Imported.
539
+ ?>
540
+ <script type="text/template" id="tmpl-cartflows-step-imported">
541
+ <div class="template-message-block cartflows-step-imported">
542
+ <h2><span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Imported', 'cartflows' ); ?></h2>
543
+ <p class="description"><?php esc_html_e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
544
+ </script>
545
+
546
+ <?php
547
+ // No templates.
548
+ ?>
549
+ <script type="text/template" id="tmpl-cartflows-no-steps">
550
+ <div class="cartflows-no-steps">
551
+ <div class="template-message-block">
552
+ <h2><?php esc_html_e( 'Coming Soon!', 'cartflows' ); ?></h2>
553
+ <p class="description"></p>
554
+ </div>
555
+ </div>
556
+ </script>
557
+
558
+ <?php
559
+ // No templates.
560
+ ?>
561
+ <script type="text/template" id="tmpl-cartflows-no-flows">
562
+ <div class="cartflows-no-flows">
563
+ <div class="template-message-block">
564
+ <h2><?php esc_html_e( 'Coming Soon!', 'cartflows' ); ?></h2>
565
+ <p class="description"></p>
566
+ </div>
567
+ </div>
568
+ </script>
569
+
570
+ <?php
571
+ // Error handling.
572
+ ?>
573
+ <script type="text/template" id="tmpl-templator-error">
574
+ <div class="notice notice-error"><p>{{ data }}</p></div>
575
+ </script>
576
+
577
+ <?php
578
+ // Redirect to Elementor.
579
+ ?>
580
+ <script type="text/template" id="tmpl-templator-redirect-to-elementor">
581
+ <div class="template-message-block templator-redirect-to-elementor">
582
+ <h2><span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Imported', 'cartflows' ); ?></h2>
583
+ <p class="description"><?php esc_html_e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php esc_html_e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
584
+ </script>
585
+
586
+ <?php
587
+ /**
588
+ * Responsive Buttons
589
+ */
590
+ ?>
591
+ <script type="text/template" id="tmpl-cartflows-responsive-view">
592
+ <span class="responsive-view">
593
+ <span class="actions">
594
+ <a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
595
+ <a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
596
+ <a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
597
+ </span>
598
+ </span>
599
+ </script>
600
+
601
+ <?php
602
+ // Templates data.
603
+ ?>
604
+ <script type="text/template" id="tmpl-cartflows-flows-list">
605
+
606
+ <# console.log( data.items.length ) #>
607
+ <# console.log( data.items ) #>
608
+ <# if ( data.items.length ) { #>
609
+ <# for ( key in data.items ) { #>
610
+ <#
611
+ var flow_steps = [];
612
+ if( data.items[ key ].flow_steps ) {
613
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
614
+ return value['id'];
615
+ });
616
+ }
617
+ #>
618
+ <div class="inner">
619
+ <div class="template">
620
+ <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 }}">
621
+ <div class="template-screenshot">
622
+ <# if( data.items[ key ].featured_image_url ) { #>
623
+ <img src="{{ data.items[ key ].featured_image_url }}" />
624
+ <# } else { #>
625
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
626
+ <# } #>
627
+ </div>
628
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
629
+ <span class="wcf-flow-type pro"><?php esc_html_e( 'Pro', 'cartflows' ); ?></span>
630
+ <# } #>
631
+ <# if( data.items[ key ].woo_required ) { #>
632
+ <div class="notice notice-info" style="width: auto;">
633
+ <p class="wcf-learn-how">
634
+ Install/Activate WooCommerce to use this template.
635
+ <a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank">
636
+ <strong><?php esc_html_e( 'Learn How', 'cartflows' ); ?></strong>
637
+ <i class="dashicons dashicons-external"></i>
638
+ </a>
639
+ </p>
640
+ </div>
641
+ <# } else { #>
642
+ <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>
643
+ <# } #>
644
+
645
+ </span>
646
+ <div class="template-id-container">
647
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
648
+ <div class="template-actions">
649
+
650
+ <#
651
+ if( data.items[ key ].page_builder.slug ) {
652
+ required_plugin_group = data.items[ key ].page_builder.slug;
653
+ } else {
654
+ required_plugin_group = '';
655
+ }
656
+
657
+ 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 ) {
658
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
659
+ } else {
660
+ import_btn_title = 'Import';
661
+ } #>
662
+
663
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
664
+ <# if( ! data.items[ key ].woo_required ) { #>
665
+ <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>
666
+ <# } else { #>
667
+ <a href='#' class='wcf-activate-wc button-primary'>Install & activate Woo</a>
668
+ <# } #>
669
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
670
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Activate License', 'cartflows' ); ?></a>
671
+ <# } else { #>
672
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php esc_html_e( 'Get Pro', 'cartflows' ); ?></a>
673
+ <# } #>
674
+ </div>
675
+ </div>
676
+ </div>
677
+ </div>
678
+ <# } #>
679
+ <# } #>
680
+ </script>
681
+
682
+ <?php
683
+ // Empty Step.
684
+ ?>
685
+ <script type="text/template" id="tmpl-cartflows-create-blank-step">
686
+ <div class="inner">
687
+ <div class="template">
688
+ <span class="thumbnail site-preview cartflows-flow-preview">
689
+ <div class="template-screenshot">
690
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
691
+ </div>
692
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
693
+ </span>
694
+ <div class="template-id-container">
695
+ <h3 class="template-name"> Blank </h3>
696
+ <div class="template-actions">
697
+ <a href="#" class="button button-primary cartflows-step-import-blank"><?php esc_html_e( 'Create', 'cartflows' ); ?></a>
698
+ </div>
699
+ </div>
700
+ </div>
701
+ </div>
702
+ </script>
703
+
704
+ <?php
705
+ // Templates data.
706
+ ?>
707
+ <script type="text/template" id="tmpl-cartflows-steps-list">
708
+ <# if ( data.items.length ) { #>
709
+ <# for ( key in data.items ) { #>
710
+ <#
711
+ var flow_steps = [];
712
+ if( data.items[ key ].flow_steps ) {
713
+ flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
714
+ return value['id'];
715
+ });
716
+ }
717
+ #>
718
+ <div class="inner">
719
+ <div class="template">
720
+ <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 }}">
721
+ <div class="template-screenshot">
722
+ <# if( data.items[ key ].featured_image_url ) { #>
723
+ <img src="{{ data.items[ key ].featured_image_url }}" />
724
+ <# } else { #>
725
+ <img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
726
+ <# } #>
727
+ </div>
728
+ <div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
729
+
730
+ <# if( data.items[ key ].woo_required ) { #>
731
+ <div class="notice notice-info" style="width: auto;">
732
+ <p class="wcf-learn-how">
733
+ Install/Activate WooCommerce to use this template.
734
+ <a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank">
735
+ <strong><?php esc_html_e( 'Learn How', 'cartflows' ); ?></strong>
736
+ <i class="dashicons dashicons-external"></i>
737
+ </a>
738
+ </p>
739
+ </div>
740
+ <# } else { #>
741
+ <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>
742
+ <# } #>
743
+
744
+ <# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
745
+ <span class="wcf-flow-type pro"><?php esc_html_e( 'Pro', 'cartflows' ); ?></span>
746
+ <# } #>
747
+ </span>
748
+ <div class="template-id-container">
749
+ <h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
750
+ <div class="template-actions">
751
+
752
+ <#
753
+
754
+ var step_slug = data.items[ key ].step_type.slug || '';
755
+ var step_title = data.items[ key ].step_type.name || '';
756
+ var import_btn_title = 'Import';
757
+
758
+ var required_plugin_group = '';
759
+ if( data.items[ key ].page_builder ) {
760
+ required_plugin_group = data.items[ key ].page_builder.slug;
761
+
762
+ 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 ) {
763
+ import_btn_title = CartFlowsImportVars.required_plugins[ data.items[ key ].page_builder.slug ].button_title;
764
+ }
765
+ }
766
+ #>
767
+
768
+ <# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
769
+
770
+ <# if( ! data.items[ key ].woo_required ) { #>
771
+ <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>
772
+ <# } else { #>
773
+ <a href='#' class='wcf-activate-wc button-primary'>Install & activate Woo</a>
774
+ <# } #>
775
+
776
+ <# } else if( CartFlowsImportVars._is_pro_active ) { #>
777
+ <a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Activate License', 'cartflows' ); ?></a>
778
+ <# } else { #>
779
+ <a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php esc_html_e( 'Get Pro', 'cartflows' ); ?></a>
780
+ <# } #>
781
+ </div>
782
+ </div>
783
+ </div>
784
+ </div>
785
+ <# } #>
786
+ <# } #>
787
+ </script>
788
+
789
+ <?php
790
+ /**
791
+ * TMPL - Website Unreachable
792
+ */
793
+ ?>
794
+ <script type="text/template" id="tmpl-cartflows-website-unreachable">
795
+ <div class="postbox cartflows-website-unreachable">
796
+ <h2><?php esc_html_e( 'Under Maintenance..', 'cartflows' ); ?></h2>
797
+ <p><?php esc_html_e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly.', 'cartflows' ); ?></p>
798
+ <p><?php esc_html_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>
799
+ </div>
800
+ </script>
801
+
802
+ <?php
803
+ /**
804
+ * TMPL - Filters
805
+ */
806
+ ?>
807
+ <script type="text/template" id="tmpl-cartflows-page-builder-notice">
808
+ <?php
809
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
810
+ $page_builder = Cartflows_Helper::get_required_plugins_for_page_builder( Cartflows_Helper::get_common_setting( 'default_page_builder' ) );
811
+ $title = $page_builder['title'];
812
+
813
+ $plugin_string = '<a href="#" data-slug="' . esc_html( $default_page_builder ) . '" class="wcf-install-plugin">Please click here and activate ' . esc_html( $title ) . '</a>';
814
+ $theme_status = '';
815
+ if ( 'divi' === $default_page_builder ) {
816
+
817
+ $theme_status = $page_builder['theme-status'];
818
+ $plugin_status = $page_builder['plugin-status'];
819
+
820
+ if ( 'deactivate' === $theme_status || 'install' === $plugin_status ) {
821
+ $plugin_string = 'Please activate ' . esc_html( $title );
822
+ } elseif ( ( 'deactivate' === $theme_status || 'not-installed' === $theme_status ) && 'install' === $plugin_status ) {
823
+ $plugin_string = 'Please install and activate ' . esc_html( $title );
824
+ }
825
+ }
826
+ ?>
827
+ <div class="wcf-page-builder-message">
828
+ <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>
829
+ <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>
830
+ <p>We plan to add design templates made with more page builder shortly!</p>
831
+ </div>
832
+ </script>
833
+
834
+ <?php
835
+ /**
836
+ * TMPL - Filters
837
+ */
838
+ ?>
839
+ <script type="text/template" id="tmpl-cartflows-term-filters-dropdown">
840
+ <# if ( data ) { #>
841
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
842
+ <# if ( data.args.show_all ) { #>
843
+ <option value="all"> <?php esc_html_e( 'All', 'cartflows' ); ?> </option>
844
+ <# } #>
845
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
846
+ <option value=""> <?php esc_html_e( 'Select Step Type', 'cartflows' ); ?> </option>
847
+ <# } #>
848
+ <# var step_slug_data = []; #>
849
+ <# for ( key in data.items ) { #>
850
+ <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>
851
+
852
+ <# step_slug_data.push( data.items[ key ].slug ); #>
853
+
854
+ <# } #>
855
+ <# if( step_slug_data.indexOf("optin") === -1){ #>
856
+ <option value='0' data-group='0' class="Optin (Woo)" data-slug="optin" data-title="Optin (Woo)">Optin (Woo)</option>
857
+ <# } #>
858
+ </select>
859
+ <# } #>
860
+ </script>
861
+
862
+ <script type="text/template" id="tmpl-cartflows-term-filters">
863
+
864
+ <# if ( data ) { #>
865
+
866
+ <?php /* <# if ( CartFlowsImportVars.flow_page_builder === data.args.remote_slug || CartFlowsImportVars.step_page_builder === data.args.remote_slug ) { #> */ ?>
867
+ <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
868
+
869
+ <# if ( data.args.show_all ) { #>
870
+ <li>
871
+ <a href="#" data-group="all"> All </a>
872
+ </li>
873
+ <# } #>
874
+
875
+ <# for ( key in data.items ) { #>
876
+ <li>
877
+ <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>
878
+ </li>
879
+ <# } #>
880
+
881
+ </ul>
882
+
883
+ <?php
884
+
885
+ /**
886
+ <# } else { #>
887
+ <select class="{{ data.args.wrapper_class }} {{ data.args.class }}">
888
+
889
+ <# if ( data.args.show_all ) { #>
890
+ <option value="all"> <?php _e( 'All', 'cartflows' ); ?> </option>
891
+ <# } #>
892
+
893
+ <# if ( CartFlowsImportVars.step_type === data.args.remote_slug ) { #>
894
+ <option value=""> <?php _e( 'Select Step Type', 'cartflows' ); ?> </option>
895
+ <# } #>
896
+
897
+ <# for ( key in data.items ) { #>
898
+ <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>
899
+ <# } #>
900
+
901
+ </select>
902
+ */
903
+ ?>
904
+
905
+ <?php /* <# } #> */ ?>
906
+
907
+ <# } #>
908
+ </script>
909
+
910
+ <?php
911
+ // Step Type.
912
+ ?>
913
+ <script type="text/template" id="tmpl-cartflows-step-types">
914
+ <ul class="wcf-tab nav-tabs">
915
+ <# if( data.items_count ) { #>
916
+ <# for( key in data.items ) { #>
917
+ <# console.log( data.items[ key ].id ) #>
918
+ <li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
919
+ <a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
920
+ </li>
921
+ <# } #>
922
+ <# } #>
923
+ </ul>
924
+ </script>
925
+
926
+ <?php
927
+ // Add to library button.
928
+ ?>
929
+ <script type="text/template" id="tmpl-templator-add-to-library">
930
+ <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>
931
+ </script>
932
+ <?php
933
+ }
934
+
935
+ /**
936
+ * Enqueue scripts
937
+ *
938
+ * @since 1.0.0
939
+ *
940
+ * @hook admin_enqueue_scripts
941
+ * @param string $hook Current page hook.
942
+ */
943
+ public function scripts( $hook = '' ) {
944
+
945
+ if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
946
+ return;
947
+ }
948
+
949
+ wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
950
+ wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
951
+ wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
952
+ wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
953
+
954
+ $installed_plugins = get_plugins();
955
+ $is_wc_installed = isset( $installed_plugins['woocommerce/woocommerce.php'] ) ? 'yes' : 'no';
956
+ $is_wc_activated = wcf()->is_woo_active ? 'yes' : 'no';
957
+
958
+ $localize_vars = array(
959
+ '_is_pro_active' => _is_cartflows_pro(),
960
+ 'is_wc_installed' => $is_wc_installed,
961
+ 'is_wc_activated' => $is_wc_activated,
962
+
963
+ // Flow and its rest fields.
964
+ 'flow' => CARTFLOWS_FLOW_POST_TYPE,
965
+ 'flow_fields' => array(
966
+ 'id',
967
+ 'title',
968
+ 'flow_type',
969
+ 'page_builder',
970
+ 'flow_steps',
971
+ 'licence_status',
972
+ 'featured_image_url',
973
+ 'featured_media', // @required for field `featured_image_url`.
974
+ ),
975
+
976
+ // Flow type and rest fields.
977
+ 'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
978
+ 'flow_type_fields' => array(
979
+ 'id',
980
+ 'name',
981
+ 'slug',
982
+ ),
983
+
984
+ // Flow page builder and rest fields.
985
+ 'flow_page_builder' => CARTFLOWS_TAXONOMY_FLOW_PAGE_BUILDER,
986
+ 'flow_page_builder_fields' => array(
987
+ 'id',
988
+ 'name',
989
+ 'slug',
990
+ ),
991
+
992
+ // Step page builder and rest fields.
993
+ 'step_page_builder' => CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER,
994
+ 'step_page_builder_fields' => array(
995
+ 'id',
996
+ 'name',
997
+ 'slug',
998
+ ),
999
+
1000
+ // Step and its rest fields.
1001
+ 'step' => CARTFLOWS_STEP_POST_TYPE,
1002
+ 'step_fields' => array(
1003
+ 'title',
1004
+ 'featured_image_url',
1005
+ 'featured_media', // @required for field `featured_image_url`.
1006
+ 'id',
1007
+ 'flow_type',
1008
+ 'step_type',
1009
+ 'page_builder',
1010
+ 'licence_status',
1011
+ ),
1012
+
1013
+ // Step type and its rest fields.
1014
+ 'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
1015
+ 'step_type_fields' => array(
1016
+ 'id',
1017
+ 'name',
1018
+ 'slug',
1019
+ ),
1020
+
1021
+ 'domain_url' => CARTFLOWS_DOMAIN_URL,
1022
+ 'server_url' => CARTFLOWS_TEMPLATES_URL,
1023
+ 'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
1024
+ 'site_url' => site_url(),
1025
+ 'import_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_importer' ),
1026
+ 'export_url' => admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&page=flow_exporter' ),
1027
+ 'admin_url' => admin_url(),
1028
+ 'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
1029
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1030
+ 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false, //phpcs:ignore
1031
+
1032
+ 'required_plugins' => Cartflows_Helper::get_plugins_groupby_page_builders(),
1033
+
1034
+ 'default_page_builder' => Cartflows_Helper::get_common_setting( 'default_page_builder' ),
1035
+ );
1036
+
1037
+ $localize_vars['cartflows_activate_plugin_nonce'] = wp_create_nonce( 'cartflows_activate_plugin' );
1038
+
1039
+ // var_dump(Cartflows_Helper::get_common_setting( 'default_page_builder' ));
1040
+ // wp_die( );
1041
+ // Add thickbox.
1042
+ add_thickbox();
1043
+
1044
+ wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
1045
+ wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
1046
+ }
1047
+
1048
+ /**
1049
+ * Load Template
1050
+ *
1051
+ * @since 1.0.0
1052
+ *
1053
+ * @hook cartflows_load_steps
1054
+ * @return void
1055
+ */
1056
+ public function load_templates() {
1057
+
1058
+ check_ajax_referer( 'cf-load-steps', 'security' );
1059
+
1060
+ $args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array(); //phpcs:ignore
1061
+ $templates = CartFlows_API::get_instance()->get_templates( $args );
1062
+
1063
+ if ( $templates['templates_count'] ) {
1064
+ wp_send_json_success( $templates );
1065
+ } else {
1066
+ wp_send_json_error( $templates );
1067
+ }
1068
+ wp_die();
1069
+ }
1070
+
1071
+ /**
1072
+ * Import.
1073
+ *
1074
+ * @since 1.0.0
1075
+ *
1076
+ * @hook wp_ajax_cartflows_import_flow_step
1077
+ * @return void
1078
+ */
1079
+ public function import_flow() {
1080
+
1081
+ check_ajax_referer( 'cf-import-flow-step', 'security' );
1082
+
1083
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1084
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1085
+
1086
+ wcf()->logger->import_log( '------------------------------------' );
1087
+ wcf()->logger->import_log( 'STARTED! Importing FLOW' );
1088
+ wcf()->logger->import_log( '------------------------------------' );
1089
+ wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
1090
+
1091
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1092
+
1093
+ $post_content = isset( $response['data']['content']->rendered ) ? $response['data']['content']->rendered : '';
1094
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1095
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1096
+ $post_content = $response['data']['divi_content'];
1097
+ }
1098
+ }
1099
+
1100
+ if ( false === $response['success'] ) {
1101
+ wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
1102
+ wp_send_json_error( $response );
1103
+ }
1104
+
1105
+ wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . wp_json_encode( $response ) );
1106
+
1107
+ $new_step_id = wp_insert_post(
1108
+ array(
1109
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1110
+ 'post_title' => $response['title'],
1111
+ 'post_content' => $post_content,
1112
+ 'post_status' => 'publish',
1113
+ )
1114
+ );
1115
+
1116
+ if ( is_wp_error( $new_step_id ) ) {
1117
+ wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
1118
+ wp_send_json_error( $new_step_id );
1119
+ }
1120
+
1121
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1122
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1123
+ update_post_meta( $new_step_id, 'divi_content', $response['data']['divi_content'] );
1124
+ }
1125
+ }
1126
+
1127
+ /* Imported Step */
1128
+ update_post_meta( $new_step_id, 'cartflows_imported_step', 'yes' );
1129
+
1130
+ wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );//phpcs:ignore
1131
+ // insert post meta.
1132
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1133
+ wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
1134
+
1135
+ /**
1136
+ * Import & Set type.
1137
+ */
1138
+ $term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
1139
+
1140
+ $term_slug = '';
1141
+ if ( $term ) {
1142
+
1143
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1144
+ $term_exist = term_exists( $term->slug, $taxonomy );
1145
+
1146
+ if ( empty( $term_exist ) ) {
1147
+ $terms = array(
1148
+ array(
1149
+ 'name' => $term->name,
1150
+ 'slug' => $term->slug,
1151
+ ),
1152
+ );
1153
+
1154
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1155
+ wcf()->logger->import_log( '(✓) Created new term name ' . $term->name . ' | term slug ' . $term->slug );
1156
+ }
1157
+
1158
+ $current_term = term_exists( $term->slug, $taxonomy );
1159
+
1160
+ // Set type object.
1161
+ $data = get_term( $current_term['term_id'], $taxonomy );
1162
+ $term_slug = $data->slug;
1163
+ $term_name = $data->name;
1164
+ wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1165
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
1166
+
1167
+ // Set type.
1168
+ update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
1169
+ wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
1170
+ }
1171
+
1172
+ // Set flow.
1173
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1174
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1175
+
1176
+ /**
1177
+ * Update steps for the current flow.
1178
+ */
1179
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1180
+
1181
+ if ( ! is_array( $flow_steps ) ) {
1182
+ $flow_steps = array();
1183
+ }
1184
+
1185
+ $flow_steps[] = array(
1186
+ 'id' => $new_step_id,
1187
+ 'title' => $response['title'],
1188
+ 'type' => $term_slug,
1189
+ );
1190
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1191
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . wp_json_encode( $flow_steps ) );
1192
+
1193
+ // Import Post Meta.
1194
+ self::import_post_meta( $new_step_id, $response );
1195
+
1196
+ wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
1197
+ wcf()->logger->import_log( '------------------------------------' );
1198
+ wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
1199
+ wcf()->logger->import_log( '------------------------------------' );
1200
+
1201
+ do_action( 'cartflows_import_complete' );
1202
+ wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
1203
+
1204
+ // Batch Process.
1205
+ do_action( 'cartflows_after_template_import', $new_step_id, $response );
1206
+
1207
+ /**
1208
+ * End
1209
+ */
1210
+ wp_send_json_success( $new_step_id );
1211
+ }
1212
+
1213
+ /**
1214
+ * Import Step.
1215
+ *
1216
+ * @since 1.0.0
1217
+ * @hook wp_ajax_cartflows_step_import
1218
+ *
1219
+ * @return void
1220
+ */
1221
+ public function create_default_flow() {
1222
+
1223
+ check_ajax_referer( 'cf-default-flow', 'security' );
1224
+
1225
+ // Create post object.
1226
+ $new_flow_post = array(
1227
+ 'post_content' => '',
1228
+ 'post_status' => 'publish',
1229
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1230
+ );
1231
+
1232
+ // Insert the post into the database.
1233
+ $flow_id = wp_insert_post( $new_flow_post );
1234
+
1235
+ if ( is_wp_error( $flow_id ) ) {
1236
+ wp_send_json_error( $flow_id->get_error_message() );
1237
+ }
1238
+
1239
+ $flow_steps = array();
1240
+
1241
+ if ( wcf()->is_woo_active ) {
1242
+ $steps_data = array(
1243
+ 'sales' => array(
1244
+ 'title' => __( 'Sales Landing', 'cartflows' ),
1245
+ 'type' => 'landing',
1246
+ ),
1247
+ 'order-form' => array(
1248
+ 'title' => __( 'Checkout (Woo)', 'cartflows' ),
1249
+ 'type' => 'checkout',
1250
+ ),
1251
+ 'order-confirmation' => array(
1252
+ 'title' => __( 'Thank You (Woo)', 'cartflows' ),
1253
+ 'type' => 'thankyou',
1254
+ ),
1255
+ );
1256
+
1257
+ } else {
1258
+ $steps_data = array(
1259
+ 'landing' => array(
1260
+ 'title' => __( 'Landing', 'cartflows' ),
1261
+ 'type' => 'landing',
1262
+ ),
1263
+ 'thankyou' => array(
1264
+ 'title' => __( 'Thank You', 'cartflows' ),
1265
+ 'type' => 'landing',
1266
+ ),
1267
+ );
1268
+ }
1269
+
1270
+ foreach ( $steps_data as $slug => $data ) {
1271
+
1272
+ $post_content = '';
1273
+ $step_type = trim( $data['type'] );
1274
+
1275
+ $step_id = wp_insert_post(
1276
+ array(
1277
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1278
+ 'post_title' => $data['title'],
1279
+ 'post_content' => $post_content,
1280
+ 'post_status' => 'publish',
1281
+ )
1282
+ );
1283
+
1284
+ if ( is_wp_error( $step_id ) ) {
1285
+ wp_send_json_error( $step_id->get_error_message() );
1286
+ }
1287
+
1288
+ if ( $step_id ) {
1289
+
1290
+ $flow_steps[] = array(
1291
+ 'id' => $step_id,
1292
+ 'title' => $data['title'],
1293
+ 'type' => $step_type,
1294
+ );
1295
+
1296
+ // insert post meta.
1297
+ update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
1298
+ update_post_meta( $step_id, 'wcf-step-type', $step_type );
1299
+
1300
+ wp_set_object_terms( $step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE );
1301
+ wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1302
+
1303
+ update_post_meta( $step_id, '_wp_page_template', 'cartflows-default' );
1304
+ }
1305
+ }
1306
+
1307
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1308
+
1309
+ wp_send_json_success( $flow_id );
1310
+ }
1311
+
1312
+ /**
1313
+ * Create Flow
1314
+ *
1315
+ * @return void
1316
+ */
1317
+ public function create_flow() {
1318
+
1319
+ check_ajax_referer( 'cf-create-flow', 'security' );
1320
+
1321
+ // Create post object.
1322
+ $new_flow_post = array(
1323
+ 'post_content' => '',
1324
+ 'post_status' => 'publish',
1325
+ 'post_type' => CARTFLOWS_FLOW_POST_TYPE,
1326
+ );
1327
+
1328
+ // Insert the post into the database.
1329
+ $flow_id = wp_insert_post( $new_flow_post );
1330
+
1331
+ if ( is_wp_error( $flow_id ) ) {
1332
+ wp_send_json_error( $flow_id->get_error_message() );
1333
+ }
1334
+
1335
+ /* Imported Flow */
1336
+ update_post_meta( $flow_id, 'cartflows_imported_flow', 'yes' );
1337
+
1338
+ wp_send_json_success( $flow_id );
1339
+ }
1340
+
1341
+ /**
1342
+ * Create Step
1343
+ *
1344
+ * @return void
1345
+ */
1346
+ public function import_step() {
1347
+
1348
+ check_ajax_referer( 'cf-step-import', 'security' );
1349
+
1350
+ $template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
1351
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1352
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( wp_unslash( $_POST['step_title'] ) ) : '';
1353
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_title( wp_unslash( $_POST['step_type'] ) ) : '';
1354
+ $step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( wp_unslash( $_POST['step_custom_title'] ) ) : $step_title;
1355
+
1356
+ $cartflow_meta = Cartflows_Flow_Meta::get_instance();
1357
+
1358
+ $post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
1359
+
1360
+ wcf()->logger->import_log( '------------------------------------' );
1361
+ wcf()->logger->import_log( 'STARTED! Importing STEP' );
1362
+ wcf()->logger->import_log( '------------------------------------' );
1363
+
1364
+ if ( empty( $template_id ) || empty( $post_id ) ) {
1365
+ /* translators: %s: template ID */
1366
+ $data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
1367
+ wcf()->logger->import_log( $data );
1368
+ wp_send_json_error( $data );
1369
+ }
1370
+
1371
+ wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
1372
+
1373
+ $response = CartFlows_API::get_instance()->get_template( $template_id );
1374
+
1375
+ if ( 'divi' === Cartflows_Helper::get_common_setting( 'default_page_builder' ) ) {
1376
+ if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
1377
+ update_post_meta( $post_id, 'divi_content', $response['data']['divi_content'] );
1378
+
1379
+ wp_update_post(
1380
+ array(
1381
+ 'ID' => $post_id,
1382
+ 'post_content' => $response['data']['divi_content'],
1383
+ )
1384
+ );
1385
+ }
1386
+ }
1387
+
1388
+ /* Imported Step */
1389
+ update_post_meta( $post_id, 'cartflows_imported_step', 'yes' );
1390
+
1391
+ // Import Post Meta.
1392
+ self::import_post_meta( $post_id, $response );
1393
+
1394
+ do_action( 'cartflows_import_complete' );
1395
+
1396
+ // Batch Process.
1397
+ do_action( 'cartflows_after_template_import', $post_id, $response );
1398
+
1399
+ wcf()->logger->import_log( '------------------------------------' );
1400
+ wcf()->logger->import_log( 'COMPLETE! Importing Step' );
1401
+ wcf()->logger->import_log( '------------------------------------' );
1402
+
1403
+ wp_send_json_success( $post_id );
1404
+ }
1405
+
1406
+ /**
1407
+ * Import Step.
1408
+ *
1409
+ * @since 1.0.0
1410
+ * @hook wp_ajax_cartflows_step_create_blank
1411
+ *
1412
+ * @return void
1413
+ */
1414
+ public function step_create_blank() {
1415
+
1416
+ check_ajax_referer( 'cf-step-create-blank', 'security' );
1417
+
1418
+ $flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
1419
+ $step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( wp_unslash( $_POST['step_type'] ) ) : '';
1420
+ $step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( wp_unslash( $_POST['step_title'] ) ) : '';
1421
+
1422
+ if ( empty( $flow_id ) || empty( $step_type ) ) {
1423
+ /* translators: %s: flow ID */
1424
+ $data = sprintf( __( 'Invalid flow id %1$s OR step type %2$s.', 'cartflows' ), $flow_id, $step_type );
1425
+ wcf()->logger->import_log( $data );
1426
+ wp_send_json_error( $data );
1427
+ }
1428
+
1429
+ wcf()->logger->import_log( '------------------------------------' );
1430
+ wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
1431
+
1432
+ $step_type_title = str_replace( '-', ' ', $step_type );
1433
+ $step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
1434
+
1435
+ $new_step_id = wp_insert_post(
1436
+ array(
1437
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
1438
+ 'post_title' => $step_title,
1439
+ 'post_content' => '',
1440
+ 'post_status' => 'publish',
1441
+ )
1442
+ );
1443
+
1444
+ // insert post meta.
1445
+ update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
1446
+
1447
+ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
1448
+ $term_exist = term_exists( $step_type_slug, $taxonomy );
1449
+
1450
+ if ( empty( $term_exist ) ) {
1451
+ $terms = array(
1452
+ array(
1453
+ 'name' => $step_type_title,
1454
+ 'slug' => $step_type_slug,
1455
+ ),
1456
+ );
1457
+
1458
+ Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
1459
+ wcf()->logger->import_log( '(✓) Created new term name ' . $step_type_title . ' | term slug ' . $step_type_slug );
1460
+ }
1461
+
1462
+ $current_term = term_exists( $step_type_slug, $taxonomy );
1463
+
1464
+ // Set type object.
1465
+ $data = get_term( $current_term['term_id'], $taxonomy );
1466
+ $step_slug = $data->slug;
1467
+ wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
1468
+ wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
1469
+
1470
+ // Set Default page Layout.
1471
+ update_post_meta( $new_step_id, '_wp_page_template', 'cartflows-default' );
1472
+
1473
+ // Set type.
1474
+ update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
1475
+ wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
1476
+
1477
+ // Set flow.
1478
+ wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
1479
+ wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
1480
+
1481
+ self::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
1482
+
1483
+ wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
1484
+ wcf()->logger->import_log( '------------------------------------' );
1485
+
1486
+ wp_send_json_success( $new_step_id );
1487
+ }
1488
+
1489
+ /**
1490
+ * Import Post Meta
1491
+ *
1492
+ * @since 1.0.0
1493
+ *
1494
+ * @param integer $post_id Post ID.
1495
+ * @param array $response Post meta.
1496
+ * @return void
1497
+ */
1498
+ public static function import_post_meta( $post_id, $response ) {
1499
+
1500
+ $metadata = (array) $response['post_meta'];
1501
+
1502
+ foreach ( $metadata as $meta_key => $meta_value ) {
1503
+ $meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
1504
+
1505
+ if ( $meta_value ) {
1506
+
1507
+ if ( is_serialized( $meta_value, true ) ) {
1508
+ $raw_data = maybe_unserialize( stripslashes( $meta_value ) );
1509
+ } elseif ( is_array( $meta_value ) ) {
1510
+ $raw_data = json_decode( stripslashes( $meta_value ), true );
1511
+ } else {
1512
+ $raw_data = $meta_value;
1513
+ }
1514
+
1515
+ if ( '_elementor_data' === $meta_key ) {
1516
+ if ( is_array( $raw_data ) ) {
1517
+ $raw_data = wp_slash( wp_json_encode( $raw_data ) );
1518
+ } else {
1519
+ $raw_data = wp_slash( $raw_data );
1520
+ }
1521
+ }
1522
+ if ( '_elementor_data' !== $meta_key && '_elementor_draft' !== $meta_key && '_fl_builder_data' !== $meta_key && '_fl_builder_draft' !== $meta_key ) {
1523
+ if ( is_array( $raw_data ) ) {
1524
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . wp_json_encode( $raw_data ) );
1525
+ } else {
1526
+ if ( ! is_object( $raw_data ) ) {
1527
+ wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
1528
+ }
1529
+ }
1530
+ }
1531
+
1532
+ update_post_meta( $post_id, $meta_key, $raw_data );
1533
+ }
1534
+ }
1535
+ }
1536
+
1537
+ /**
1538
+ * Import Template for Elementor
1539
+ *
1540
+ * @since 1.0.0
1541
+ *
1542
+ * @param integer $post_id Post ID.
1543
+ * @param array $response Post meta.
1544
+ * @param array $page_build_data Page build data.
1545
+ * @return void
1546
+ */
1547
+ public static function import_template_elementor( $post_id, $response, $page_build_data ) {
1548
+ if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
1549
+ $data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
1550
+ wcf()->logger->import_log( $data );
1551
+ wp_send_json_error( $data );
1552
+ }
1553
+
1554
+ require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
1555
+
1556
+ wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
1557
+
1558
+ $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
1559
+ $obj->import_single_template( $post_id );
1560
+
1561
+ wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
1562
+ }
1563
+
1564
+ /**
1565
+ * Supported post types
1566
+ *
1567
+ * @since 1.0.0
1568
+ *
1569
+ * @return array Supported post types.
1570
+ */
1571
+ public static function supported_post_types() {
1572
+ return apply_filters(
1573
+ 'cartflows_supported_post_types',
1574
+ array(
1575
+ CARTFLOWS_FLOW_POST_TYPE,
1576
+ )
1577
+ );
1578
+ }
1579
+
1580
+ /**
1581
+ * Check supported post type
1582
+ *
1583
+ * @since 1.0.0
1584
+ *
1585
+ * @param string $post_type Post type.
1586
+ * @return boolean Supported post type status.
1587
+ */
1588
+ public static function is_supported_post( $post_type = '' ) {
1589
+
1590
+ if ( in_array( $post_type, self::supported_post_types(), true ) ) {
1591
+ return true;
1592
+ }
1593
+
1594
+ return false;
1595
+ }
1596
+
1597
+ /**
1598
+ * Set steps to the flow
1599
+ *
1600
+ * @param integer $flow_id Flow ID.
1601
+ * @param integer $new_step_id New step ID.
1602
+ * @param string $step_title Flow Type.
1603
+ * @param string $step_slug Flow Type.
1604
+ */
1605
+ public function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
1606
+ // Update steps for the current flow.
1607
+ $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
1608
+
1609
+ if ( ! is_array( $flow_steps ) ) {
1610
+ $flow_steps = array();
1611
+ }
1612
+
1613
+ $flow_steps[] = array(
1614
+ 'id' => $new_step_id,
1615
+ 'title' => $step_title,
1616
+ 'type' => $step_slug,
1617
+ );
1618
+ update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
1619
+ wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . wp_json_encode( $flow_steps ) );
1620
+ }
1621
+
1622
+ /**
1623
+ * Localize variables in admin
1624
+ *
1625
+ * @param array $vars variables.
1626
+ */
1627
+ public function localize_vars( $vars ) {
1628
+
1629
+ $ajax_actions = array(
1630
+ 'cf_step_import',
1631
+ 'cf_load_steps',
1632
+ 'cf_create_flow',
1633
+ 'cf_default_flow',
1634
+ 'cf_step_create_blank',
1635
+ 'cf_import_flow_step',
1636
+ );
1637
+
1638
+ foreach ( $ajax_actions as $action ) {
1639
+
1640
+ $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1641
+ }
1642
+
1643
+ return $vars;
1644
+ }
1645
+
1646
+ /**
1647
+ * Ajax action to activate plugin
1648
+ */
1649
+ public function activate_plugin() {
1650
+
1651
+ if ( ! check_ajax_referer( 'cartflows_activate_plugin', 'security', false ) ) {
1652
+ wp_send_json_error( esc_html__( 'Action failed. Invalid Security Nonce.', 'cartflows' ) );
1653
+ }
1654
+
1655
+ if ( ! current_user_can( 'activate_plugins' ) ) {
1656
+ wp_send_json_error(
1657
+ array(
1658
+ 'success' => false,
1659
+ 'message' => __( 'User have not plugin install permissions.', 'cartflows' ),
1660
+ )
1661
+ );
1662
+ }
1663
+
1664
+ $plugin_init = isset( $_POST['plugin_init'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_init'] ) ) : '';
1665
+
1666
+ $activate = activate_plugin( $plugin_init, '', false, true );
1667
+
1668
+ if ( is_wp_error( $activate ) ) {
1669
+ wp_send_json_error(
1670
+ array(
1671
+ 'success' => false,
1672
+ 'message' => $activate->get_error_message(),
1673
+ 'init' => $plugin_init,
1674
+ )
1675
+ );
1676
+ }
1677
+
1678
+ wp_send_json_success(
1679
+ array(
1680
+ 'success' => true,
1681
+ 'message' => __( 'Plugin Successfully Activated', 'cartflows' ),
1682
+ 'init' => $plugin_init,
1683
+ )
1684
+ );
1685
+ }
1686
+
1687
+ }
1688
+
1689
+ /**
1690
+ * Initialize class object with 'get_instance()' method
1691
+ */
1692
+ CartFlows_Importer::get_instance();
1693
+
1694
+ endif;
classes/class-cartflows-learndash-compatibility.php CHANGED
@@ -1,140 +1,140 @@
1
- <?php
2
- /**
3
- * LearnDash compatibility
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Class for LearnDash compatibility
10
- */
11
- class Cartflows_Learndash_Compatibility {
12
-
13
- /**
14
- * Member Variable
15
- *
16
- * @var instance
17
- */
18
- private static $instance;
19
-
20
- /**
21
- * Initiator
22
- */
23
- public static function get_instance() {
24
- if ( ! isset( self::$instance ) ) {
25
- self::$instance = new self();
26
- }
27
- return self::$instance;
28
- }
29
-
30
- /**
31
- * Constructor
32
- */
33
- public function __construct() {
34
- add_filter( 'learndash_post_args', array( $this, 'cartflows_course_setting_fields' ) );
35
- add_action( 'template_redirect', array( $this, 'cartflows_override_course_template' ) );
36
-
37
- }
38
-
39
- /**
40
- * Override course cartflows template.
41
- *
42
- * @return bool
43
- */
44
- public function cartflows_override_course_template() {
45
-
46
- // Don't run any code in admin area.
47
- if ( is_admin() ) {
48
- return false;
49
- }
50
-
51
- // Don't override the template if the post type is not `course`.
52
- if ( ! is_singular( 'sfwd-courses' ) ) {
53
- return false;
54
- }
55
-
56
- $course_id = learndash_get_course_id();
57
- $user_id = get_current_user_id();
58
- if ( is_user_logged_in() && sfwd_lms_has_access( $course_id, $user_id ) ) {
59
- return false;
60
- }
61
-
62
- if ( defined( LEARNDASH_VERSION ) && version_compare( LEARNDASH_VERSION, '2.6.4', '>' ) ) {
63
-
64
- $template = learndash_get_course_meta_setting( get_the_id(), 'wcf_course_template' );
65
- } else {
66
-
67
- $template = get_course_meta_setting( get_the_id(), 'wcf_course_template' );
68
- }
69
-
70
- if ( 'none' !== $template && $template ) {
71
- $link = get_permalink( $template );
72
- wp_safe_redirect( $link );
73
- }
74
- }
75
-
76
- /**
77
- * Add settings inside learndash settings.
78
- *
79
- * @param array $fields fields.
80
- * @return mixed
81
- */
82
- public function cartflows_course_setting_fields( $fields ) {
83
- global $post;
84
-
85
- $all_posts = array(
86
- 'none' => __( 'None', 'cartflows' ),
87
- );
88
-
89
- $landing_steps = get_posts(
90
- array(
91
- 'posts_per_page' => -1,
92
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
93
- 'post_status' => 'publish',
94
- 'orderby' => 'ID',
95
- 'order' => 'DESC',
96
- 'meta_query' => array( //phpcs:ignore
97
- array(
98
- 'key' => 'wcf-step-type',
99
- 'value' => array( 'landing', 'checkout', 'optin' ),
100
- 'compare' => 'IN',
101
- ),
102
- ),
103
- )
104
- );
105
-
106
- foreach ( $landing_steps as $landing_step ) {
107
- $all_posts[ $landing_step->ID ] = get_the_title( $landing_step->ID ) . ' ( #' . $landing_step->ID . ')';
108
- }
109
-
110
- $selected = get_post_meta( get_the_ID(), 'wcf_course_template', true );
111
- $description = sprintf(
112
- /* translators: 1: anchor start, 2: anchor close */
113
- __( 'Non-enrolled students will redirect to the selected CartFlows template. If you have not created any Flow already, add new Flow from %1$shere%2$s.', 'cartflows' ),
114
- '<a href="' . esc_url( admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&add-new-flow' ) ) . '">',
115
- '</a>'
116
- );
117
-
118
- $fields['sfwd-courses']['fields']['wcf_course_template'] = array(
119
- 'name' => __( 'Select CartFlows Template for this Course', 'cartflows' ),
120
- 'type' => 'select',
121
- 'initial_options' => $all_posts,
122
- 'default' => 'none',
123
- 'help_text' => $description,
124
- 'show_in_rest' => true,
125
- 'rest_args' => array(
126
- 'schema' => array(
127
- 'type' => 'string',
128
- ),
129
- ),
130
- );
131
-
132
- return $fields;
133
- }
134
-
135
- }
136
-
137
- /**
138
- * Kicking this off by calling 'get_instance()' method
139
- */
140
- Cartflows_Learndash_Compatibility::get_instance();
1
+ <?php
2
+ /**
3
+ * LearnDash compatibility
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Class for LearnDash compatibility
10
+ */
11
+ class Cartflows_Learndash_Compatibility {
12
+
13
+ /**
14
+ * Member Variable
15
+ *
16
+ * @var instance
17
+ */
18
+ private static $instance;
19
+
20
+ /**
21
+ * Initiator
22
+ */
23
+ public static function get_instance() {
24
+ if ( ! isset( self::$instance ) ) {
25
+ self::$instance = new self();
26
+ }
27
+ return self::$instance;
28
+ }
29
+
30
+ /**
31
+ * Constructor
32
+ */
33
+ public function __construct() {
34
+ add_filter( 'learndash_post_args', array( $this, 'cartflows_course_setting_fields' ) );
35
+ add_action( 'template_redirect', array( $this, 'cartflows_override_course_template' ) );
36
+
37
+ }
38
+
39
+ /**
40
+ * Override course cartflows template.
41
+ *
42
+ * @return bool
43
+ */
44
+ public function cartflows_override_course_template() {
45
+
46
+ // Don't run any code in admin area.
47
+ if ( is_admin() ) {
48
+ return false;
49
+ }
50
+
51
+ // Don't override the template if the post type is not `course`.
52
+ if ( ! is_singular( 'sfwd-courses' ) ) {
53
+ return false;
54
+ }
55
+
56
+ $course_id = learndash_get_course_id();
57
+ $user_id = get_current_user_id();
58
+ if ( is_user_logged_in() && sfwd_lms_has_access( $course_id, $user_id ) ) {
59
+ return false;
60
+ }
61
+
62
+ if ( defined( LEARNDASH_VERSION ) && version_compare( LEARNDASH_VERSION, '2.6.4', '>' ) ) {
63
+
64
+ $template = learndash_get_course_meta_setting( get_the_id(), 'wcf_course_template' );
65
+ } else {
66
+
67
+ $template = get_course_meta_setting( get_the_id(), 'wcf_course_template' );
68
+ }
69
+
70
+ if ( 'none' !== $template && $template ) {
71
+ $link = get_permalink( $template );
72
+ wp_safe_redirect( $link );
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Add settings inside learndash settings.
78
+ *
79
+ * @param array $fields fields.
80
+ * @return mixed
81
+ */
82
+ public function cartflows_course_setting_fields( $fields ) {
83
+ global $post;
84
+
85
+ $all_posts = array(
86
+ 'none' => __( 'None', 'cartflows' ),
87
+ );
88
+
89
+ $landing_steps = get_posts(
90
+ array(
91
+ 'posts_per_page' => -1,
92
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
93
+ 'post_status' => 'publish',
94
+ 'orderby' => 'ID',
95
+ 'order' => 'DESC',
96
+ 'meta_query' => array( //phpcs:ignore
97
+ array(
98
+ 'key' => 'wcf-step-type',
99
+ 'value' => array( 'landing', 'checkout', 'optin' ),
100
+ 'compare' => 'IN',
101
+ ),
102
+ ),
103
+ )
104
+ );
105
+
106
+ foreach ( $landing_steps as $landing_step ) {
107
+ $all_posts[ $landing_step->ID ] = get_the_title( $landing_step->ID ) . ' ( #' . $landing_step->ID . ')';
108
+ }
109
+
110
+ $selected = get_post_meta( get_the_ID(), 'wcf_course_template', true );
111
+ $description = sprintf(
112
+ /* translators: 1: anchor start, 2: anchor close */
113
+ __( 'Non-enrolled students will redirect to the selected CartFlows template. If you have not created any Flow already, add new Flow from %1$shere%2$s.', 'cartflows' ),
114
+ '<a href="' . esc_url( admin_url( 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE . '&add-new-flow' ) ) . '">',
115
+ '</a>'
116
+ );
117
+
118
+ $fields['sfwd-courses']['fields']['wcf_course_template'] = array(
119
+ 'name' => __( 'Select CartFlows Template for this Course', 'cartflows' ),
120
+ 'type' => 'select',
121
+ 'initial_options' => $all_posts,
122
+ 'default' => 'none',
123
+ 'help_text' => $description,
124
+ 'show_in_rest' => true,
125
+ 'rest_args' => array(
126
+ 'schema' => array(
127
+ 'type' => 'string',
128
+ ),
129
+ ),
130
+ );
131
+
132
+ return $fields;
133
+ }
134
+
135
+ }
136
+
137
+ /**
138
+ * Kicking this off by calling 'get_instance()' method
139
+ */
140
+ Cartflows_Learndash_Compatibility::get_instance();
classes/class-cartflows-loader.php CHANGED
@@ -125,7 +125,7 @@ if ( ! class_exists( 'Cartflows_Loader' ) ) {
125
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
126
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
127
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
128
- define( 'CARTFLOWS_VER', '1.5.1' );
129
  define( 'CARTFLOWS_SLUG', 'cartflows' );
130
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
131
 
125
  define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
126
  define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
127
  define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
128
+ define( 'CARTFLOWS_VER', '1.5.2' );
129
  define( 'CARTFLOWS_SLUG', 'cartflows' );
130
  define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
131
 
classes/class-cartflows-meta-fields.php CHANGED
@@ -376,9 +376,6 @@ class Cartflows_Meta_Fields {
376
  }
377
 
378
  function get_only_checkbox_field( $field_data ) {
379
- // echo "<pre>";
380
- // var_dump($field_data);
381
- // echo "</pre>";
382
 
383
  $value = $field_data['value'];
384
 
@@ -767,6 +764,7 @@ class Cartflows_Meta_Fields {
767
 
768
  function get_image_field( $field_data ) {
769
 
 
770
  $value = $field_data['value'];
771
 
772
  $attr = '';
@@ -781,13 +779,21 @@ class Cartflows_Meta_Fields {
781
  $display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
782
 
783
  $field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
784
- if( isset( $value ) ){
785
- $field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
786
- }
 
 
 
787
  $field_content .= '</div>';
788
- // $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
 
 
789
  $field_content .= '<input type="hidden" id="'. $field_data['name'] .'" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
790
 
 
 
 
791
  $field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
792
 
793
  $display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
376
  }
377
 
378
  function get_only_checkbox_field( $field_data ) {
 
 
 
379
 
380
  $value = $field_data['value'];
381
 
764
 
765
  function get_image_field( $field_data ) {
766
 
767
+ global $post;
768
  $value = $field_data['value'];
769
 
770
  $attr = '';
779
  $display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
780
 
781
  $field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
782
+
783
+ if( isset( $value ) ){
784
+
785
+ $field_content .= '<img src="'. $field_data['value'] .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
786
+ }
787
+
788
  $field_content .= '</div>';
789
+
790
+ $image_data = htmlentities( serialize( get_post_meta( $post->ID, $field_data['name'].'-obj') ) );
791
+
792
  $field_content .= '<input type="hidden" id="'. $field_data['name'] .'" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
793
 
794
+ $field_content .= '<input type="hidden" id="'. $field_data['name'].'-obj'.'" class="wcf-image-obj" name="' . $field_data['name'].'-obj'. '" value="'.$image_data.'">';
795
+
796
+
797
  $field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
798
 
799
  $display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
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
- public function right_column_footer( $options, $post_id ) {
32
- ?>
33
- <div class="wcf-column-right-footer">
34
- <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'wcf-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 esc_html_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
- public 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'], ENT_COMPAT, 'utf-8' ),
66
- 'help' => esc_html__( '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
+ public function right_column_footer( $options, $post_id ) {
32
+ ?>
33
+ <div class="wcf-column-right-footer">
34
+ <?php submit_button( __( 'Update', 'cartflows' ), 'primary', 'wcf-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 esc_html_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
+ public 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'], ENT_COMPAT, 'utf-8' ),
66
+ 'help' => esc_html__( '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;
classes/class-cartflows-tracking.php CHANGED
@@ -1,277 +1,277 @@
1
- <?php
2
- /**
3
- * Cartflows_Tracking
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Flow Markup
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Tracking {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var object instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Member Variable
25
- *
26
- * @var object instance
27
- */
28
- public static $google_analytics_settings = 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( 'wp_head', array( $this, 'wcf_render_gtag' ) );
46
-
47
- // Set Google analytics values.
48
- $this->get_google_analytics_settings( self::$google_analytics_settings );
49
- }
50
-
51
- /**
52
- * Get ga settings.
53
- *
54
- * @param array $google_analytics_settings ga settings.
55
- */
56
- public function get_google_analytics_settings( $google_analytics_settings ) {
57
- self::$google_analytics_settings = Cartflows_Helper::get_google_analytics_settings();
58
- }
59
-
60
-
61
- /**
62
- * Render google tag framework.
63
- */
64
- public function wcf_render_gtag() {
65
- $get_tracking_code = $this->wcf_ga_id();
66
-
67
- if ( self::is_wcf_ga_tracking_on() ) {
68
- ?>
69
- <!-- Google Analytics Script By CartFlows -->
70
- <script type="text/javascript">
71
- var tracking_id = '<?php echo $get_tracking_code; ?>';
72
- </script>
73
- <!-- Global site tag (gtag.js) - Google Analytics -->
74
- <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
75
- <script async src=https://www.googletagmanager.com/gtag/js?id=<?php echo $get_tracking_code; ?>></script>
76
- <script>
77
- window.dataLayer = window.dataLayer || [];
78
- function gtag(){dataLayer.push(arguments);}
79
- gtag('js', new Date());
80
- </script>
81
-
82
- <!-- Google Analytics Script By CartFlows -->
83
- <?php
84
- if ( 'enable' === self::$google_analytics_settings['enable_google_analytics_for_site'] ) {
85
- ?>
86
- <script>
87
- gtag('config', tracking_id);
88
- </script>
89
- <?php
90
- }
91
- }
92
- }
93
-
94
- /**
95
- * Set cookies to send ga data.
96
- *
97
- * @param int $order_id order id.
98
- * @param array $offer_data offer product data.
99
- */
100
- public static function send_ga_data_if_enabled( $order_id, $offer_data = array() ) {
101
-
102
- if ( self::is_wcf_ga_tracking_on() && self::wcf_track_ga_purchase() ) {
103
-
104
- setcookie( 'wcf_ga_trans_data', wp_json_encode( self::get_ga_purchase_transactions_data( $order_id, $offer_data ) ), strtotime( '+1 year' ), '/' );
105
- }
106
- }
107
-
108
-
109
- /**
110
- * Prepare cart data for GA response.
111
- *
112
- * @param int $order_id order id.
113
- * @param array $offer_data offer product data.
114
- * @return array
115
- */
116
- public static function get_ga_purchase_transactions_data( $order_id, $offer_data ) {
117
-
118
- $response = array();
119
-
120
- $order = wc_get_order( $order_id );
121
- $cart_total = WC()->cart->get_cart_contents_total();
122
- $cart_items_count = WC()->cart->get_cart_contents_count();
123
- $items = $order->get_items();
124
- $cart_tax = $order->get_cart_tax();
125
- $response['items'] = array();
126
- $cart_contents = array();
127
-
128
- $response = array(
129
- 'transaction_id' => $order_id,
130
- 'affiliation' => get_bloginfo( 'name' ),
131
- 'value' => $order->get_total(),
132
- 'currency' => $order->get_currency(),
133
- 'tax' => $order->get_cart_tax(),
134
- 'shipping' => $order->get_shipping_total(),
135
- 'coupon' => WC()->cart->get_coupons(),
136
- );
137
- if ( empty( $offer_data ) ) {
138
- // Iterating through each WC_Order_Item_Product objects.
139
- foreach ( $items as $item => $value ) {
140
-
141
- $_product = wc_get_product( $value['product_id'] );
142
-
143
- if ( ! $_product->is_type( 'variable' ) ) {
144
- $product_data = self::get_required_data( $_product );
145
- } else {
146
- $variable_product = wc_get_product( $value['variation_id'] );
147
- $product_data = self::get_required_data( $variable_product );
148
- }
149
- array_push(
150
- $cart_contents,
151
- array(
152
- 'id' => $product_data['id'],
153
- 'name' => $product_data['name'],
154
- 'category' => wp_strip_all_tags( wc_get_product_category_list( $_product->get_id() ) ),
155
- 'price' => $product_data['price'],
156
- 'quantity' => $value['quantity'],
157
- )
158
- );
159
- }
160
- } else {
161
- array_push(
162
- $cart_contents,
163
- array(
164
- 'id' => $offer_data['id'],
165
- 'name' => $offer_data['name'],
166
- 'quantity' => $offer_data['qty'],
167
- 'price' => $offer_data['price'],
168
- )
169
- );
170
- }
171
-
172
- $response['items'] = $cart_contents;
173
-
174
- // Prepare the json data to send it to google.
175
- return $response;
176
- }
177
-
178
- /**
179
- * Prepare Ecommerce data for GA response.
180
- *
181
- * @return array
182
- */
183
- public static function get_ga_items_list() {
184
-
185
- $items = WC()->cart->get_cart();
186
- $items_data = array();
187
-
188
- foreach ( $items as $item => $value ) {
189
-
190
- $_product = wc_get_product( $value['product_id'] );
191
-
192
- if ( ! $_product->is_type( 'variable' ) ) {
193
- $product_data = self::get_required_data( $_product );
194
- } else {
195
- $variable_product = wc_get_product( $value['variation_id'] );
196
- $product_data = self::get_required_data( $variable_product );
197
- }
198
-
199
- array_push(
200
- $items_data,
201
- array(
202
- 'id' => $product_data['id'],
203
- 'name' => $product_data['name'],
204
- 'category' => wp_strip_all_tags( wc_get_product_category_list( $_product->get_id() ) ),
205
- 'price' => $product_data['price'],
206
- 'quantity' => $value['quantity'],
207
- )
208
- );
209
- }
210
- return $items_data;
211
- }
212
-
213
-
214
-
215
- /**
216
- * Check tracking on.
217
- */
218
- public static function is_wcf_ga_tracking_on() {
219
-
220
- $is_enabled = false;
221
-
222
- if ( 'disable' === self::$google_analytics_settings['enable_google_analytics'] ) {
223
- $is_enabled = false;
224
- } else {
225
- $is_enabled = true;
226
- }
227
-
228
- return apply_filters( 'cartflows_google_analytics_tracking_enabled', $is_enabled );
229
- }
230
-
231
-
232
-
233
- /**
234
- * Check purchase event enable.
235
- */
236
- public static function wcf_track_ga_purchase() {
237
-
238
- $google_analytics_settings = Cartflows_Helper::get_google_analytics_settings();
239
- $wcf_track_ga_purchase = $google_analytics_settings['enable_purchase_event'];
240
-
241
- if ( is_array( $google_analytics_settings ) && ! empty( $google_analytics_settings ) && 'enable' === $wcf_track_ga_purchase ) {
242
- return true;
243
- }
244
-
245
- return false;
246
- }
247
-
248
- /**
249
- * Get product data.
250
- *
251
- * @param object $_product product data.
252
- */
253
- public static function get_required_data( $_product ) {
254
-
255
- $data = array(
256
- 'id' => $_product->get_id(),
257
- 'name' => $_product->get_name(),
258
- 'price' => $_product->get_price(),
259
- );
260
- return $data;
261
- }
262
-
263
- /**
264
- * Retreive google anlytics ID.
265
- */
266
- public function wcf_ga_id() {
267
-
268
- $get_ga_id = self::$google_analytics_settings['google_analytics_id'];
269
-
270
- return empty( $get_ga_id ) ? false : $get_ga_id;
271
- }
272
- }
273
-
274
- /**
275
- * Kicking this off by calling 'get_instance()' method
276
- */
277
- Cartflows_Tracking::get_instance();
1
+ <?php
2
+ /**
3
+ * Cartflows_Tracking
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Flow Markup
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Tracking {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var object instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var object instance
27
+ */
28
+ public static $google_analytics_settings = 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( 'wp_head', array( $this, 'wcf_render_gtag' ) );
46
+
47
+ // Set Google analytics values.
48
+ $this->get_google_analytics_settings( self::$google_analytics_settings );
49
+ }
50
+
51
+ /**
52
+ * Get ga settings.
53
+ *
54
+ * @param array $google_analytics_settings ga settings.
55
+ */
56
+ public function get_google_analytics_settings( $google_analytics_settings ) {
57
+ self::$google_analytics_settings = Cartflows_Helper::get_google_analytics_settings();
58
+ }
59
+
60
+
61
+ /**
62
+ * Render google tag framework.
63
+ */
64
+ public function wcf_render_gtag() {
65
+ $get_tracking_code = $this->wcf_ga_id();
66
+
67
+ if ( self::is_wcf_ga_tracking_on() ) {
68
+ ?>
69
+ <!-- Google Analytics Script By CartFlows -->
70
+ <script type="text/javascript">
71
+ var tracking_id = '<?php echo $get_tracking_code; ?>';
72
+ </script>
73
+ <!-- Global site tag (gtag.js) - Google Analytics -->
74
+ <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
75
+ <script async src=https://www.googletagmanager.com/gtag/js?id=<?php echo $get_tracking_code; ?>></script>
76
+ <script>
77
+ window.dataLayer = window.dataLayer || [];
78
+ function gtag(){dataLayer.push(arguments);}
79
+ gtag('js', new Date());
80
+ </script>
81
+
82
+ <!-- Google Analytics Script By CartFlows -->
83
+ <?php
84
+ if ( 'enable' === self::$google_analytics_settings['enable_google_analytics_for_site'] ) {
85
+ ?>
86
+ <script>
87
+ gtag('config', tracking_id);
88
+ </script>
89
+ <?php
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Set cookies to send ga data.
96
+ *
97
+ * @param int $order_id order id.
98
+ * @param array $offer_data offer product data.
99
+ */
100
+ public static function send_ga_data_if_enabled( $order_id, $offer_data = array() ) {
101
+
102
+ if ( self::is_wcf_ga_tracking_on() && self::wcf_track_ga_purchase() ) {
103
+
104
+ setcookie( 'wcf_ga_trans_data', wp_json_encode( self::get_ga_purchase_transactions_data( $order_id, $offer_data ) ), strtotime( '+1 year' ), '/' );
105
+ }
106
+ }
107
+
108
+
109
+ /**
110
+ * Prepare cart data for GA response.
111
+ *
112
+ * @param int $order_id order id.
113
+ * @param array $offer_data offer product data.
114
+ * @return array
115
+ */
116
+ public static function get_ga_purchase_transactions_data( $order_id, $offer_data ) {
117
+
118
+ $response = array();
119
+
120
+ $order = wc_get_order( $order_id );
121
+ $cart_total = WC()->cart->get_cart_contents_total();
122
+ $cart_items_count = WC()->cart->get_cart_contents_count();
123
+ $items = $order->get_items();
124
+ $cart_tax = $order->get_cart_tax();
125
+ $response['items'] = array();
126
+ $cart_contents = array();
127
+
128
+ $response = array(
129
+ 'transaction_id' => $order_id,
130
+ 'affiliation' => get_bloginfo( 'name' ),
131
+ 'value' => $order->get_total(),
132
+ 'currency' => $order->get_currency(),
133
+ 'tax' => $order->get_cart_tax(),
134
+ 'shipping' => $order->get_shipping_total(),
135
+ 'coupon' => WC()->cart->get_coupons(),
136
+ );
137
+ if ( empty( $offer_data ) ) {
138
+ // Iterating through each WC_Order_Item_Product objects.
139
+ foreach ( $items as $item => $value ) {
140
+
141
+ $_product = wc_get_product( $value['product_id'] );
142
+
143
+ if ( ! $_product->is_type( 'variable' ) ) {
144
+ $product_data = self::get_required_data( $_product );
145
+ } else {
146
+ $variable_product = wc_get_product( $value['variation_id'] );
147
+ $product_data = self::get_required_data( $variable_product );
148
+ }
149
+ array_push(
150
+ $cart_contents,
151
+ array(
152
+ 'id' => $product_data['id'],
153
+ 'name' => $product_data['name'],
154
+ 'category' => wp_strip_all_tags( wc_get_product_category_list( $_product->get_id() ) ),
155
+ 'price' => $product_data['price'],
156
+ 'quantity' => $value['quantity'],
157
+ )
158
+ );
159
+ }
160
+ } else {
161
+ array_push(
162
+ $cart_contents,
163
+ array(
164
+ 'id' => $offer_data['id'],
165
+ 'name' => $offer_data['name'],
166
+ 'quantity' => $offer_data['qty'],
167
+ 'price' => $offer_data['price'],
168
+ )
169
+ );
170
+ }
171
+
172
+ $response['items'] = $cart_contents;
173
+
174
+ // Prepare the json data to send it to google.
175
+ return $response;
176
+ }
177
+
178
+ /**
179
+ * Prepare Ecommerce data for GA response.
180
+ *
181
+ * @return array
182
+ */
183
+ public static function get_ga_items_list() {
184
+
185
+ $items = WC()->cart->get_cart();
186
+ $items_data = array();
187
+
188
+ foreach ( $items as $item => $value ) {
189
+
190
+ $_product = wc_get_product( $value['product_id'] );
191
+
192
+ if ( ! $_product->is_type( 'variable' ) ) {
193
+ $product_data = self::get_required_data( $_product );
194
+ } else {
195
+ $variable_product = wc_get_product( $value['variation_id'] );
196
+ $product_data = self::get_required_data( $variable_product );
197
+ }
198
+
199
+ array_push(
200
+ $items_data,
201
+ array(
202
+ 'id' => $product_data['id'],
203
+ 'name' => $product_data['name'],
204
+ 'category' => wp_strip_all_tags( wc_get_product_category_list( $_product->get_id() ) ),
205
+ 'price' => $product_data['price'],
206
+ 'quantity' => $value['quantity'],
207
+ )
208
+ );
209
+ }
210
+ return $items_data;
211
+ }
212
+
213
+
214
+
215
+ /**
216
+ * Check tracking on.
217
+ */
218
+ public static function is_wcf_ga_tracking_on() {
219
+
220
+ $is_enabled = false;
221
+
222
+ if ( 'disable' === self::$google_analytics_settings['enable_google_analytics'] ) {
223
+ $is_enabled = false;
224
+ } else {
225
+ $is_enabled = true;
226
+ }
227
+
228
+ return apply_filters( 'cartflows_google_analytics_tracking_enabled', $is_enabled );
229
+ }
230
+
231
+
232
+
233
+ /**
234
+ * Check purchase event enable.
235
+ */
236
+ public static function wcf_track_ga_purchase() {
237
+
238
+ $google_analytics_settings = Cartflows_Helper::get_google_analytics_settings();
239
+ $wcf_track_ga_purchase = $google_analytics_settings['enable_purchase_event'];
240
+
241
+ if ( is_array( $google_analytics_settings ) && ! empty( $google_analytics_settings ) && 'enable' === $wcf_track_ga_purchase ) {
242
+ return true;
243
+ }
244
+
245
+ return false;
246
+ }
247
+
248
+ /**
249
+ * Get product data.
250
+ *
251
+ * @param object $_product product data.
252
+ */
253
+ public static function get_required_data( $_product ) {
254
+
255
+ $data = array(
256
+ 'id' => $_product->get_id(),
257
+ 'name' => $_product->get_name(),
258
+ 'price' => $_product->get_price(),
259
+ );
260
+ return $data;
261
+ }
262
+
263
+ /**
264
+ * Retreive google anlytics ID.
265
+ */
266
+ public function wcf_ga_id() {
267
+
268
+ $get_ga_id = self::$google_analytics_settings['google_analytics_id'];
269
+
270
+ return empty( $get_ga_id ) ? false : $get_ga_id;
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Kicking this off by calling 'get_instance()' method
276
+ */
277
+ Cartflows_Tracking::get_instance();
includes/admin/cartflows-general.php CHANGED
@@ -223,7 +223,27 @@ $error_log = filter_input( INPUT_GET, 'cartflows-error-log', FILTER_VALIDATE_BOO
223
  );
224
 
225
  echo "<div class='wcf-fb-pixel-wrapper'>";
 
 
 
 
 
 
 
 
 
 
 
226
 
 
 
 
 
 
 
 
 
 
227
  echo Cartflows_Admin_Fields::text_field(
228
  array(
229
  'id' => 'wcf_facebook_pixel_id',
@@ -285,7 +305,7 @@ $error_log = filter_input( INPUT_GET, 'cartflows-error-log', FILTER_VALIDATE_BOO
285
  <!-- Google Analytics Tracking -->
286
  <div class="general-settingss-form postbox">
287
  <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
288
- <span><?php esc_html_e( 'Google Analytics Tracking', 'cartflows' ); ?></span>
289
  </h2>
290
  <div class="inside">
291
  <form method="post" class="wrap wcf-clear" action="" >
@@ -400,6 +420,8 @@ $error_log = filter_input( INPUT_GET, 'cartflows-error-log', FILTER_VALIDATE_BOO
400
  </div>
401
  <!-- Google Analytics Tracking -->
402
 
 
 
403
  </div>
404
 
405
  <!-- Right Sidebar -->
223
  );
224
 
225
  echo "<div class='wcf-fb-pixel-wrapper'>";
226
+ ?>
227
+ <hr/>
228
+ <?php
229
+ echo Cartflows_Admin_Fields::checkobox_field(
230
+ array(
231
+ 'id' => 'wcf_facebook_pixel_tracking_for_site',
232
+ 'name' => '_cartflows_facebook[facebook_pixel_tracking_for_site]',
233
+ 'title' => __( 'Enable for the whole site', 'cartflows' ),
234
+ 'value' => $facebook_settings['facebook_pixel_tracking_for_site'],
235
+ )
236
+ );
237
 
238
+ echo Cartflows_Admin_Fields::title_field(
239
+ array(
240
+ 'title' => '',
241
+ 'description' => __( 'If this option is unchecked, it will only apply to CartFlows steps.', 'cartflows' ),
242
+ )
243
+ );
244
+ ?>
245
+ <hr/>
246
+ <?php
247
  echo Cartflows_Admin_Fields::text_field(
248
  array(
249
  'id' => 'wcf_facebook_pixel_id',
305
  <!-- Google Analytics Tracking -->
306
  <div class="general-settingss-form postbox">
307
  <h2 class="hndle wcf-normal-cusror ui-sortable-handle">
308
+ <span><?php esc_html_e( 'Google Analytics Settings', 'cartflows' ); ?></span>
309
  </h2>
310
  <div class="inside">
311
  <form method="post" class="wrap wcf-clear" action="" >
420
  </div>
421
  <!-- Google Analytics Tracking -->
422
 
423
+ <?php do_action( 'cartflows_register_general_settings' ); ?>
424
+
425
  </div>
426
 
427
  <!-- Right Sidebar -->
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.5.1\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
- "POT-Creation-Date: 2020-03-12 07:53:57+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -114,7 +114,7 @@ msgstr ""
114
  msgid "Clone"
115
  msgstr ""
116
 
117
- #: classes/class-cartflows-default-meta.php:714
118
  #: modules/optin/classes/class-cartflows-optin-meta.php:487
119
  msgid "Submit"
120
  msgstr ""
@@ -387,24 +387,24 @@ msgstr ""
387
  msgid "Ultra-Bold 900"
388
  msgstr ""
389
 
390
- #: classes/class-cartflows-meta-fields.php:551
391
- #: classes/class-cartflows-meta-fields.php:750
392
  msgid "Search for a product&hellip;"
393
  msgstr ""
394
 
395
- #: classes/class-cartflows-meta-fields.php:592
396
  msgid "Search for a coupon&hellip;"
397
  msgstr ""
398
 
399
- #: classes/class-cartflows-meta-fields.php:725
400
  msgid "Add New Product"
401
  msgstr ""
402
 
403
- #: classes/class-cartflows-meta-fields.php:726
404
  msgid "Create Product"
405
  msgstr ""
406
 
407
- #: classes/class-cartflows-meta-fields.php:758
408
  msgid "Remove"
409
  msgstr ""
410
 
@@ -708,8 +708,8 @@ msgstr ""
708
 
709
  #: includes/admin/cartflows-general.php:106
710
  #: includes/admin/cartflows-general.php:190
711
- #: includes/admin/cartflows-general.php:276
712
- #: includes/admin/cartflows-general.php:393
713
  msgid "Save Changes"
714
  msgstr ""
715
 
@@ -759,127 +759,132 @@ msgstr ""
759
  msgid "Enable Facebook Pixel Tracking"
760
  msgstr ""
761
 
762
- #: includes/admin/cartflows-general.php:231
 
 
 
 
 
 
 
 
 
763
  msgid "Enter Facebook pixel ID"
764
  msgstr ""
765
 
766
- #: includes/admin/cartflows-general.php:239
767
- #: includes/admin/cartflows-general.php:338
768
  msgid "Enable Events:"
769
  msgstr ""
770
 
771
- #: includes/admin/cartflows-general.php:248
772
  msgid "Initiate Checkout"
773
  msgstr ""
774
 
775
- #: includes/admin/cartflows-general.php:257
776
- #: includes/admin/cartflows-general.php:364
777
  msgid "Add Payment Info"
778
  msgstr ""
779
 
780
- #: includes/admin/cartflows-general.php:266
781
  msgid "Purchase Complete"
782
  msgstr ""
783
 
784
- #: includes/admin/cartflows-general.php:288
785
- msgid "Google Analytics Tracking"
786
  msgstr ""
787
 
788
- #: includes/admin/cartflows-general.php:299
789
  msgid "Enable Google Analytics Tracking"
790
  msgstr ""
791
 
792
- #: includes/admin/cartflows-general.php:312
793
  msgid "Enable for the whole website"
794
  msgstr ""
795
 
796
- #: includes/admin/cartflows-general.php:320
797
- msgid "If this option is unchecked, it will only apply to CartFlows steps."
798
- msgstr ""
799
-
800
- #: includes/admin/cartflows-general.php:330
801
  msgid "Google Analytics ID"
802
  msgstr ""
803
 
804
- #: includes/admin/cartflows-general.php:332
805
  msgid ""
806
  "Log into your <a href=\"https://analytics.google.com/\" "
807
  "target=\"_blank\">google analytics account</a> to find your ID. eg: "
808
  "UA-XXXXXX-X&period;"
809
  msgstr ""
810
 
811
- #: includes/admin/cartflows-general.php:346
812
  msgid "Begin Checkout"
813
  msgstr ""
814
 
815
- #: includes/admin/cartflows-general.php:355
816
  msgid "Add To Cart"
817
  msgstr ""
818
 
819
- #: includes/admin/cartflows-general.php:373
820
  msgid "Purchase"
821
  msgstr ""
822
 
823
- #: includes/admin/cartflows-general.php:381
824
  msgid ""
825
  "Google Analytics not working correctly? <a "
826
  "href=\"https://cartflows.com/docs/troubleshooting-google-analytics-tracking-"
827
  "issues/\" > Click here </a> to know more. "
828
  msgstr ""
829
 
830
- #: includes/admin/cartflows-general.php:412
831
  msgid "Knowledge Base"
832
  msgstr ""
833
 
834
- #: includes/admin/cartflows-general.php:416
835
  msgid "Not sure how something works? Take a peek at the knowledge base and learn."
836
  msgstr ""
837
 
838
- #: includes/admin/cartflows-general.php:419
839
  msgid "Visit Knowledge Base »"
840
  msgstr ""
841
 
842
- #: includes/admin/cartflows-general.php:427
843
  msgid "Community"
844
  msgstr ""
845
 
846
- #: includes/admin/cartflows-general.php:431
847
  msgid ""
848
  "Join the community of super helpful CartFlows users. Say hello, ask "
849
  "questions, give feedback and help each other!"
850
  msgstr ""
851
 
852
- #: includes/admin/cartflows-general.php:434
853
  msgid "Join Our Facebook Group »"
854
  msgstr ""
855
 
856
- #: includes/admin/cartflows-general.php:442
857
  msgid "Five Star Support"
858
  msgstr ""
859
 
860
- #: includes/admin/cartflows-general.php:446
861
  msgid "Got a question? Get in touch with CartFlows developers. We're happy to help!"
862
  msgstr ""
863
 
864
- #: includes/admin/cartflows-general.php:449
865
  msgid "Submit a Ticket »"
866
  msgstr ""
867
 
868
- #: includes/admin/cartflows-general.php:459
869
  msgid "Load Minified CSS"
870
  msgstr ""
871
 
872
- #: includes/admin/cartflows-general.php:464
873
  msgid ""
874
  "Load the Minified CSS from here. Just Enable it by checking the below given "
875
  "checkbox."
876
  msgstr ""
877
 
878
- #: includes/admin/cartflows-general.php:471
879
  msgid "Load minified CSS & JS Files"
880
  msgstr ""
881
 
882
- #: includes/admin/cartflows-general.php:476
883
  msgid "Save"
884
  msgstr ""
885
 
@@ -944,29 +949,29 @@ msgstr ""
944
  msgid "This product can't be purchased"
945
  msgstr ""
946
 
947
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1043
948
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1086
949
  msgid "Coupon Code"
950
  msgstr ""
951
 
952
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1044
953
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1095
954
  msgid "Apply"
955
  msgstr ""
956
 
957
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1251
958
  msgid "Sorry there was a problem removing this coupon."
959
  msgstr ""
960
 
961
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1254
962
  msgid "Coupon has been removed."
963
  msgstr ""
964
 
965
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1273
966
  msgid "Sorry there was a problem removing "
967
  msgstr ""
968
 
969
- #: modules/checkout/classes/class-cartflows-checkout-markup.php:1276
970
  msgid " has been removed."
971
  msgstr ""
972
 
2
  # This file is distributed under the same license as the CartFlows package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: CartFlows 1.5.2\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cartflows\n"
7
+ "POT-Creation-Date: 2020-03-18 05:58:59+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
114
  msgid "Clone"
115
  msgstr ""
116
 
117
+ #: classes/class-cartflows-default-meta.php:741
118
  #: modules/optin/classes/class-cartflows-optin-meta.php:487
119
  msgid "Submit"
120
  msgstr ""
387
  msgid "Ultra-Bold 900"
388
  msgstr ""
389
 
390
+ #: classes/class-cartflows-meta-fields.php:548
391
+ #: classes/class-cartflows-meta-fields.php:747
392
  msgid "Search for a product&hellip;"
393
  msgstr ""
394
 
395
+ #: classes/class-cartflows-meta-fields.php:589
396
  msgid "Search for a coupon&hellip;"
397
  msgstr ""
398
 
399
+ #: classes/class-cartflows-meta-fields.php:722
400
  msgid "Add New Product"
401
  msgstr ""
402
 
403
+ #: classes/class-cartflows-meta-fields.php:723
404
  msgid "Create Product"
405
  msgstr ""
406
 
407
+ #: classes/class-cartflows-meta-fields.php:755
408
  msgid "Remove"
409
  msgstr ""
410
 
708
 
709
  #: includes/admin/cartflows-general.php:106
710
  #: includes/admin/cartflows-general.php:190
711
+ #: includes/admin/cartflows-general.php:296
712
+ #: includes/admin/cartflows-general.php:413
713
  msgid "Save Changes"
714
  msgstr ""
715
 
759
  msgid "Enable Facebook Pixel Tracking"
760
  msgstr ""
761
 
762
+ #: includes/admin/cartflows-general.php:233
763
+ msgid "Enable for the whole site"
764
+ msgstr ""
765
+
766
+ #: includes/admin/cartflows-general.php:241
767
+ #: includes/admin/cartflows-general.php:340
768
+ msgid "If this option is unchecked, it will only apply to CartFlows steps."
769
+ msgstr ""
770
+
771
+ #: includes/admin/cartflows-general.php:251
772
  msgid "Enter Facebook pixel ID"
773
  msgstr ""
774
 
775
+ #: includes/admin/cartflows-general.php:259
776
+ #: includes/admin/cartflows-general.php:358
777
  msgid "Enable Events:"
778
  msgstr ""
779
 
780
+ #: includes/admin/cartflows-general.php:268
781
  msgid "Initiate Checkout"
782
  msgstr ""
783
 
784
+ #: includes/admin/cartflows-general.php:277
785
+ #: includes/admin/cartflows-general.php:384
786
  msgid "Add Payment Info"
787
  msgstr ""
788
 
789
+ #: includes/admin/cartflows-general.php:286
790
  msgid "Purchase Complete"
791
  msgstr ""
792
 
793
+ #: includes/admin/cartflows-general.php:308
794
+ msgid "Google Analytics Settings"
795
  msgstr ""
796
 
797
+ #: includes/admin/cartflows-general.php:319
798
  msgid "Enable Google Analytics Tracking"
799
  msgstr ""
800
 
801
+ #: includes/admin/cartflows-general.php:332
802
  msgid "Enable for the whole website"
803
  msgstr ""
804
 
805
+ #: includes/admin/cartflows-general.php:350
 
 
 
 
806
  msgid "Google Analytics ID"
807
  msgstr ""
808
 
809
+ #: includes/admin/cartflows-general.php:352
810
  msgid ""
811
  "Log into your <a href=\"https://analytics.google.com/\" "
812
  "target=\"_blank\">google analytics account</a> to find your ID. eg: "
813
  "UA-XXXXXX-X&period;"
814
  msgstr ""
815
 
816
+ #: includes/admin/cartflows-general.php:366
817
  msgid "Begin Checkout"
818
  msgstr ""
819
 
820
+ #: includes/admin/cartflows-general.php:375
821
  msgid "Add To Cart"
822
  msgstr ""
823
 
824
+ #: includes/admin/cartflows-general.php:393
825
  msgid "Purchase"
826
  msgstr ""
827
 
828
+ #: includes/admin/cartflows-general.php:401
829
  msgid ""
830
  "Google Analytics not working correctly? <a "
831
  "href=\"https://cartflows.com/docs/troubleshooting-google-analytics-tracking-"
832
  "issues/\" > Click here </a> to know more. "
833
  msgstr ""
834
 
835
+ #: includes/admin/cartflows-general.php:434
836
  msgid "Knowledge Base"
837
  msgstr ""
838
 
839
+ #: includes/admin/cartflows-general.php:438
840
  msgid "Not sure how something works? Take a peek at the knowledge base and learn."
841
  msgstr ""
842
 
843
+ #: includes/admin/cartflows-general.php:441
844
  msgid "Visit Knowledge Base »"
845
  msgstr ""
846
 
847
+ #: includes/admin/cartflows-general.php:449
848
  msgid "Community"
849
  msgstr ""
850
 
851
+ #: includes/admin/cartflows-general.php:453
852
  msgid ""
853
  "Join the community of super helpful CartFlows users. Say hello, ask "
854
  "questions, give feedback and help each other!"
855
  msgstr ""
856
 
857
+ #: includes/admin/cartflows-general.php:456
858
  msgid "Join Our Facebook Group »"
859
  msgstr ""
860
 
861
+ #: includes/admin/cartflows-general.php:464
862
  msgid "Five Star Support"
863
  msgstr ""
864
 
865
+ #: includes/admin/cartflows-general.php:468
866
  msgid "Got a question? Get in touch with CartFlows developers. We're happy to help!"
867
  msgstr ""
868
 
869
+ #: includes/admin/cartflows-general.php:471
870
  msgid "Submit a Ticket »"
871
  msgstr ""
872
 
873
+ #: includes/admin/cartflows-general.php:481
874
  msgid "Load Minified CSS"
875
  msgstr ""
876
 
877
+ #: includes/admin/cartflows-general.php:486
878
  msgid ""
879
  "Load the Minified CSS from here. Just Enable it by checking the below given "
880
  "checkbox."
881
  msgstr ""
882
 
883
+ #: includes/admin/cartflows-general.php:493
884
  msgid "Load minified CSS & JS Files"
885
  msgstr ""
886
 
887
+ #: includes/admin/cartflows-general.php:498
888
  msgid "Save"
889
  msgstr ""
890
 
949
  msgid "This product can't be purchased"
950
  msgstr ""
951
 
952
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:901
953
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:944
954
  msgid "Coupon Code"
955
  msgstr ""
956
 
957
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:902
958
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:953
959
  msgid "Apply"
960
  msgstr ""
961
 
962
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:1109
963
  msgid "Sorry there was a problem removing this coupon."
964
  msgstr ""
965
 
966
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:1112
967
  msgid "Coupon has been removed."
968
  msgstr ""
969
 
970
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:1131
971
  msgid "Sorry there was a problem removing "
972
  msgstr ""
973
 
974
+ #: modules/checkout/classes/class-cartflows-checkout-markup.php:1134
975
  msgid " has been removed."
976
  msgstr ""
977
 
modules/checkout/classes/class-cartflows-checkout-markup.php CHANGED
@@ -623,6 +623,9 @@ class Cartflows_Checkout_Markup {
623
  $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
624
  }
625
 
 
 
 
626
  CartFlows_Font_Families::render_fonts( $checkout_id );
627
 
628
  $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
@@ -740,160 +743,15 @@ class Cartflows_Checkout_Markup {
740
 
741
  list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' );
742
  }
743
- $output = "
744
- .wcf-embed-checkout-form .woocommerce .woocommerce-checkout .product-name .remove:hover{
745
- color:$primary_color !important;
746
- border:1px solid $primary_color !important;
747
- }
748
- .wcf-embed-checkout-form .wcf-checkout-header-image img{
749
- width: {$header_logo_width}px;
750
- }
751
- .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
752
- .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
753
- color: {$primary_color};
754
- }
755
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
756
- background-color: {$primary_color};
757
- }
758
- .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
759
- .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
760
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
761
- .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
762
- border-color: {$primary_color};
763
- box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
764
- }
765
- .wcf-embed-checkout-form .woocommerce-checkout label{
766
- color: {$field_label_color};
767
- }
768
- .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
769
- background-color: {$hl_bg_color};
770
- font-family: {$input_font_family};
771
- font-weight: {$input_font_weight};
772
- }
773
-
774
- .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
775
- .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
776
- .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
777
- {
778
- border-bottom-color: {$hl_bg_color};
779
- border-right-color: transparent;
780
- border-left-color: transparent;
781
- border-top-color: transparent;
782
- position: absolute;
783
- }
784
 
785
- .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
786
- .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
787
- font-family: {$input_font_family};
788
- font-weight: {$input_font_weight};
789
- }
790
-
791
- .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
792
- .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
793
- .wcf-embed-checkout-form .woocommerce form .form-row textarea,
794
- .wcf-embed-checkout-form .select2-container--default .select2-selection--single {
795
- color: {$field_color};
796
- background: {$field_bg_color};
797
- border-color: {$field_border_color};
798
- padding-top: {$field_tb_padding}px;
799
- padding-bottom: {$field_tb_padding}px;
800
- padding-left: {$field_lr_padding}px;
801
- padding-right: {$field_lr_padding}px;
802
- min-height: {$field_input_size};
803
- font-family: {$input_font_family};
804
- font-weight: {$input_font_weight};
805
- }
806
 
807
- .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
808
- .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
809
- .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
810
- .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
811
- .wcf-embed-checkout-form .woocommerce-checkout #payment,
812
- .wcf-embed-checkout-form .woocommerce form.checkout_coupon
813
- {
814
- background-color: {$section_bg_color};
815
- border-color: {$box_border_color};
816
- font-family: {$input_font_family};
817
- font-weight: {$input_font_weight};
818
- }
819
 
820
- .woocommerce table.shop_table th{
821
- color: {$field_label_color};
822
- }
823
- /*.wcf-embed-checkout-form .woocommerce .woocommerce-info,
824
- .wcf-embed-checkout-form .woocommerce-message{
825
- border-top-color: {$primary_color};
826
- background-color: {$hl_bg_color};
827
- }*/
828
- .wcf-embed-checkout-form .woocommerce a{
829
- color: {$primary_color};
830
- }
831
- .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
832
- color: {$field_color};
833
- }
834
- .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
835
- color: {$field_color};
836
- }
837
- .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
838
- color: {$field_color};
839
- }
840
- .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
841
- color: {$field_color};
842
- }
843
- .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
844
- color: {$field_color};
845
- }
846
- .wcf-embed-checkout-form .woocommerce form p.form-row label {
847
- color: {$field_label_color};
848
- font-family: {$input_font_family};
849
- font-weight: {$input_font_weight};
850
- }
851
- .wcf-embed-checkout-form .woocommerce #order_review button,
852
- .wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
853
- .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
854
- color: {$submit_color};
855
- background: {$submit_bg_color};
856
- padding-top: {$submit_tb_padding}px;
857
- padding-bottom: {$submit_tb_padding}px;
858
- padding-left: {$submit_lr_padding}px;
859
- padding-right: {$submit_lr_padding}px;
860
- border-color: {$submit_border_color};
861
- min-height: {$submit_button_height};
862
- font-family: {$button_font_family};
863
- font-weight: {$button_font_weight};
864
- }
865
- .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
866
- .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
867
- background: {$submit_bg_color};
868
- border: 1px {$submit_border_color} solid;
869
- color: {$submit_color};
870
- min-height: {$submit_button_height};
871
- font-family: {$button_font_family};
872
- font-weight: {$button_font_weight};
873
- }
874
- .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
875
- .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
876
- .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
877
- .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
878
- color: {$submit_hover_color};
879
- background-color: {$submit_bg_hover_color};
880
- border-color: {$submit_border_hover_color};
881
- }
882
- .wcf-embed-checkout-form .woocommerce h3,
883
- .wcf-embed-checkout-form .woocommerce h3 span,
884
- .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
885
- color: {$section_heading_color};
886
- font-family: {$heading_font_family};
887
- font-weight: {$heading_font_weight};
888
- }
889
- .wcf-embed-checkout-form .woocommerce-info::before,
890
- .wcf-embed-checkout-form .woocommerce-message::before{
891
- color: {$primary_color};
892
- }
893
- .wcf-embed-checkout-form{
894
- font-family: {$base_font_family};
895
- }
896
- img.emoji, img.wp-smiley {}";
897
 
898
  return $output;
899
  }
623
  $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
624
  }
625
 
626
+ /*Output css variable */
627
+ $output = '';
628
+
629
  CartFlows_Font_Families::render_fonts( $checkout_id );
630
 
631
  $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
743
 
744
  list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' );
745
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
 
747
+ if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
748
+ Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
 
750
+ include CARTFLOWS_CHECKOUT_DIR . 'includes/checkout-dynamic-divi-css.php';
 
 
 
 
 
 
 
 
 
 
 
751
 
752
+ } else {
753
+ include CARTFLOWS_CHECKOUT_DIR . 'includes/checkout-dynamic-css.php';
754
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
 
756
  return $output;
757
  }
modules/checkout/classes/class-cartflows-checkout-meta.php CHANGED
@@ -1,915 +1,915 @@
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
- /**
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
- * 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
- public function setup_meta_box() {
61
-
62
- if ( _is_wcf_checkout_type() ) {
63
- add_meta_box(
64
- 'wcf-checkout-settings', // Id.
65
- __( 'Checkout Layout', '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
- public function markup_meta_box( $post ) {
81
-
82
- wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
83
-
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
- $checkout_data = array();
100
-
101
- foreach ( $meta as $key => $value ) {
102
- $checkout_data[ $key ] = $meta[ $key ]['default'];
103
- }
104
-
105
- /**
106
- $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
107
-
108
- // For loop
109
- foreach ( $billing_fields as $key => $value ) {
110
-
111
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
112
- }
113
-
114
- $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
115
-
116
- foreach ( $shipping_fields as $key => $value ) {
117
-
118
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
119
- }
120
-
121
- $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
122
-
123
- foreach ( $additional_fields as $key => $value ) {
124
-
125
- $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
126
- }
127
- */
128
-
129
- do_action( 'wcf_checkout_settings_markup_before' );
130
- $this->tabs_markup( $checkout_data, $post->ID );
131
- do_action( 'wcf_checkout_settings_markup_after' );
132
- }
133
-
134
- /**
135
- * Page Header Tabs
136
- *
137
- * @param array $options options.
138
- * @param int $post_id post ID.
139
- */
140
- public function tabs_markup( $options, $post_id ) {
141
-
142
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
143
-
144
- if ( empty( $active_tab ) ) {
145
- $active_tab = 'wcf-checkout-shortcodes';
146
- }
147
-
148
- $tab_array = array(
149
- array(
150
- 'title' => __( 'Shortcodes', 'cartflows' ),
151
- 'id' => 'wcf-checkout-shortcodes',
152
- 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
153
- 'icon' => 'dashicons-editor-code',
154
- ),
155
- array(
156
- 'title' => __( 'Select Product', 'cartflows' ),
157
- 'id' => 'wcf-checkout-general',
158
- 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
159
- 'icon' => 'dashicons-info',
160
- ),
161
- array(
162
- 'title' => __( 'Order Bump', 'cartflows' ),
163
- 'id' => 'wcf-product-order-bump',
164
- 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
165
- 'icon' => 'dashicons-cart',
166
- ),
167
- array(
168
- 'title' => __( 'Checkout Offer', 'cartflows' ),
169
- 'id' => 'wcf-pre-checkout-offer',
170
- 'class' => 'wcf-pre-checkout-offer' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
171
- 'icon' => 'dashicons-arrow-up-alt',
172
- ),
173
- array(
174
- 'title' => __( 'Checkout Design', 'cartflows' ),
175
- 'id' => 'wcf-checkout-style',
176
- 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
177
- 'icon' => 'dashicons-admin-customizer',
178
- ),
179
- array(
180
- 'title' => __( 'Checkout Fields', 'cartflows' ),
181
- 'id' => 'wcf-checkout-custom-fields',
182
- 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
183
- 'icon' => 'dashicons-welcome-widgets-menus',
184
- ),
185
- array(
186
- 'title' => __( 'Checkout Settings', 'cartflows' ),
187
- 'id' => 'wcf-checkout-custom-settings',
188
- 'class' => 'wcf-checkout-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
189
- 'icon' => 'dashicons-admin-generic',
190
- ),
191
- array(
192
- 'title' => __( 'Custom Script', 'cartflows' ),
193
- 'id' => 'wcf-checkout-custom-script-header',
194
- 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
195
- 'icon' => 'dashicons-format-aside',
196
- ),
197
- );
198
-
199
- $show_logo = filter_input( INPUT_GET, 'logo-tab', FILTER_VALIDATE_BOOLEAN );
200
-
201
- if ( $show_logo ) {
202
- $logo_tab = array(
203
- 'title' => __( 'Logo (Optional)', 'cartflows' ),
204
- 'id' => 'wcf-checkout-header',
205
- 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
206
- 'icon' => 'dashicons-format-image',
207
- );
208
- array_push( $tab_array, $logo_tab );
209
- }
210
-
211
- $tabs = apply_filters( 'cartflows_checkout_tabs', $tab_array, $active_tab );
212
-
213
- ?>
214
- <div class="wcf-checkout-table wcf-metabox-wrap widefat">
215
- <div class="wcf-table-container">
216
- <div class="wcf-column-left">
217
- <div class="wcf-tab-wrapper">
218
-
219
- <?php foreach ( $tabs as $key => $tab ) { ?>
220
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
221
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
222
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
223
- </div>
224
- <?php } ?>
225
-
226
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
227
- </div>
228
- </div>
229
- <div class="wcf-column-right">
230
- <?php $this->tab_shortcodes( $options, $post_id ); ?>
231
- <?php $this->tab_general( $options, $post_id ); ?>
232
- <?php $this->tab_style( $options, $post_id ); ?>
233
- <?php $this->tab_pre_checkout_offer( $options, $post_id ); ?>
234
- <?php $this->tab_product_bump( $options, $post_id ); ?>
235
- <?php $this->tab_custom_fields( $options, $post_id ); ?>
236
- <?php $this->tab_custom_settings( $options, $post_id ); ?>
237
- <?php $this->tab_header_content( $options, $post_id ); ?>
238
- <?php $this->tab_custom_script( $options, $post_id ); ?>
239
- <?php do_action( 'cartflows_checkout_tabs_content', $options, $post_id ); ?>
240
- <?php $this->right_column_footer( $options, $post_id ); ?>
241
- </div>
242
- </div>
243
- </div>
244
-
245
- <?php
246
- }
247
-
248
- /**
249
- * Shortcodes tab
250
- *
251
- * @param array $options options.
252
- * @param int $post_id post ID.
253
- */
254
- public function tab_shortcodes( $options, $post_id ) {
255
- ?>
256
- <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
257
-
258
- <?php
259
-
260
- echo wcf()->meta->get_shortcode_field(
261
- array(
262
- 'label' => 'Checkout Page',
263
- 'name' => 'wcf-checkout-shortcode',
264
- 'content' => '[cartflows_checkout]',
265
- 'help' => esc_html__( 'Add this shortcode to your checkout page', 'cartflows' ),
266
- )
267
- );
268
- ?>
269
- </div>
270
- <?php
271
- }
272
-
273
-
274
- /**
275
- * General tab
276
- *
277
- * @param array $options options.
278
- * @param int $post_id post ID.
279
- */
280
- public function tab_general( $options, $post_id ) {
281
- ?>
282
- <div class="wcf-checkout-general wcf-tab-content widefat">
283
-
284
- <?php
285
-
286
- echo wcf()->meta->get_product_selection_repeater(
287
- array(
288
- 'name' => 'wcf-checkout-products',
289
- 'value' => $options['wcf-checkout-products'],
290
- 'allow_clear' => true,
291
- )
292
- );
293
-
294
- if ( ! _is_cartflows_pro() ) {
295
-
296
- echo wcf()->meta->get_hr_line_field( array() );
297
- echo wcf()->meta->get_description_field(
298
- array(
299
- 'name' => 'wcf-upgrade-to-pro',
300
- /* translators: %s: link */
301
- 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Pre-applied Coupon, Product Variations & Quantity Options.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
302
- )
303
- );
304
- }
305
-
306
- do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
307
-
308
- ?>
309
- </div>
310
- <?php
311
- }
312
-
313
- /**
314
- * Pre Checkout tab
315
- *
316
- * @param array $options options.
317
- * @param int $post_id post ID.
318
- */
319
- public function tab_pre_checkout_offer( $options, $post_id ) {
320
- ?>
321
- <div class="wcf-pre-checkout-offer wcf-tab-content widefat">
322
- <?php
323
- if ( ! _is_cartflows_pro() ) {
324
- echo wcf()->meta->get_description_field(
325
- array(
326
- 'name' => 'wcf-upgrade-to-pro',
327
- /* translators: %s: link */
328
- 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Checkout Offer feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
329
- )
330
- );
331
- } elseif ( _is_cartflows_pro_ver_less_than( '1.2.0' ) ) {
332
-
333
- $version = '1.2.0';
334
- echo wcf()->meta->get_description_field(
335
- array(
336
- 'name' => 'wcf-upgrade-to-pro',
337
- /* translators: %s: link */
338
- 'content' => '<i>' . sprintf( esc_html__( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for Checkout Offer feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>', $version ) . '</i>',
339
- )
340
- );
341
- }
342
- ?>
343
-
344
- <?php do_action( 'cartflows_pre_checkout_offer_tab_content', $options, $post_id ); ?>
345
- </div>
346
- <?php
347
- }
348
-
349
-
350
- /**
351
- * Pre Checkout tab
352
- *
353
- * @param array $options options.
354
- * @param int $post_id post ID.
355
- */
356
- public function animate_title_settings( $options, $post_id ) {
357
-
358
- echo wcf()->meta->get_hr_line_field( array() );
359
-
360
- if ( ! _is_cartflows_pro() ) {
361
- echo wcf()->meta->get_description_field(
362
- array(
363
- 'name' => 'wcf-upgrade-to-pro',
364
- /* translators: %s: link */
365
- 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for animate browser tab feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
366
- )
367
- );
368
- } elseif ( _is_cartflows_pro_ver_less_than( '1.4.0' ) ) {
369
-
370
- $version = '1.4.0';
371
- echo wcf()->meta->get_description_field(
372
- array(
373
- 'name' => 'wcf-upgrade-to-pro',
374
- /* translators: %s: link */
375
- 'content' => '<i>' . sprintf( __( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for animate browser tab feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>', $version ) . '</i>',
376
- )
377
- );
378
- }
379
-
380
- do_action( 'cartflows_animate_browser_tab_settings', $options, $post_id );
381
- }
382
-
383
- /**
384
- * Product bump tab
385
- *
386
- * @param array $options options.
387
- * @param int $post_id post ID.
388
- */
389
- public function tab_product_bump( $options, $post_id ) {
390
- ?>
391
- <div class="wcf-product-order-bump wcf-tab-content widefat">
392
- <?php
393
- if ( ! _is_cartflows_pro() ) {
394
- echo wcf()->meta->get_description_field(
395
- array(
396
- 'name' => 'wcf-upgrade-to-pro',
397
- /* translators: %s: link */
398
- 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
399
- )
400
- );
401
- }
402
- ?>
403
-
404
- <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
405
- </div>
406
- <?php
407
- }
408
- /**
409
- * Tab custom fields
410
- *
411
- * @param array $options options.
412
- * @param int $post_id post ID.
413
- */
414
- public function tab_custom_fields( $options, $post_id ) {
415
- ?>
416
- <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
417
- <?php
418
- /* Custom Checkout Fields Section */
419
-
420
- if ( ! _is_cartflows_pro() ) {
421
- echo wcf()->meta->get_description_field(
422
- array(
423
- 'name' => 'wcf-upgrade-to-pro',
424
- /* translators: %s: link */
425
- 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
426
- )
427
- );
428
- }
429
- ?>
430
- <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
431
- </div>
432
- <?php
433
- }
434
- /**
435
- * Tab custom settings
436
- *
437
- * @param array $options options.
438
- * @param int $post_id post ID.
439
- */
440
- public function tab_custom_settings( $options, $post_id ) {
441
- ?>
442
- <div class="wcf-checkout-custom-settings wcf-tab-content widefat">
443
- <div class="wcf-custom-settings-fields">
444
- <?php
445
-
446
- echo wcf()->meta->get_text_field(
447
- array(
448
- 'label' => __( 'Place Order Button Text', 'cartflows' ),
449
- 'name' => 'wcf-checkout-place-order-button-text',
450
- 'value' => $options['wcf-checkout-place-order-button-text'],
451
- 'attr' => array(
452
- 'placeholder' => __( 'Place order', 'cartflows' ),
453
- ),
454
- 'help' => __( 'It will change the Place Order Button text on checkout page.', 'cartflows' ),
455
- )
456
- );
457
-
458
- echo wcf()->meta->get_hr_line_field( array() );
459
-
460
- echo wcf()->meta->get_checkbox_field(
461
- array(
462
- 'name' => 'wcf-remove-product-field',
463
- 'value' => $options['wcf-remove-product-field'],
464
- 'after' => esc_html__( 'Enable cart editing on checkout', 'cartflows' ),
465
- )
466
- );
467
-
468
- echo wcf()->meta->get_description_field(
469
- array(
470
- 'name' => '',
471
- /* translators: %s: link */
472
- 'content' => '<i>' . sprintf( esc_html__( 'Users will able to remove products from the checkout page.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
473
- )
474
- );
475
-
476
- $this->animate_title_settings( $options, $post_id );
477
- ?>
478
- </div>
479
- <?php do_action( 'cartflows_custom_settings_tab_content', $options, $post_id ); ?>
480
- </div>
481
- <?php
482
- }
483
-
484
- /**
485
- * Tab style
486
- *
487
- * @param array $options options.
488
- * @param int $post_id post ID.
489
- */
490
- public function tab_style( $options, $post_id ) {
491
- ?>
492
-
493
- <div class="wcf-checkout-style wcf-tab-content widefat">
494
- <div class="wcf-cs-fields">
495
- <div class="wcf-cs-checkbox-field">
496
- <?php
497
-
498
- $layout_pro_option = array();
499
-
500
- if ( ! _is_cartflows_pro() ) {
501
- $layout_pro_option = array(
502
- 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
503
- 'two-step' => __( 'Two Step (Available in CartFlows Pro) ', 'cartflows' ),
504
- );
505
- }
506
-
507
- echo wcf()->meta->get_select_field(
508
- array(
509
- 'label' => __( 'Checkout Skin', 'cartflows' ),
510
- 'name' => 'wcf-checkout-layout',
511
- 'value' => $options['wcf-checkout-layout'],
512
- 'options' => array(
513
- 'one-column' => esc_html__( 'One Column', 'cartflows' ),
514
- 'two-column' => esc_html__( 'Two Column', 'cartflows' ),
515
- 'two-step' => esc_html__( 'Two Step', 'cartflows' ),
516
- ),
517
- 'pro-options' => $layout_pro_option,
518
-
519
- )
520
- );
521
-
522
- echo wcf()->meta->get_color_picker_field(
523
- array(
524
- 'label' => __( 'Primary Color', 'cartflows' ),
525
- 'name' => 'wcf-primary-color',
526
- 'value' => $options['wcf-primary-color'],
527
- )
528
- );
529
-
530
- echo wcf()->meta->get_font_family_field(
531
- array(
532
- 'for' => 'wcf-base',
533
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
534
- 'name' => 'wcf-base-font-family',
535
- 'value' => $options['wcf-base-font-family'],
536
- )
537
- );
538
-
539
- echo wcf()->meta->get_checkbox_field(
540
- array(
541
- 'label' => __( 'Advance Options', 'cartflows' ),
542
- 'name' => 'wcf-advance-options-fields',
543
- 'value' => $options['wcf-advance-options-fields'],
544
- 'after' => 'Enable',
545
- )
546
- );
547
- ?>
548
- </div>
549
- <div class="wcf-cs-fields-options">
550
- <?php
551
- echo wcf()->meta->get_section(
552
- array(
553
- 'label' => __( 'Heading', 'cartflows' ),
554
- )
555
- );
556
-
557
- echo wcf()->meta->get_color_picker_field(
558
- array(
559
- 'label' => __( 'Heading Color', 'cartflows' ),
560
- 'name' => 'wcf-heading-color',
561
- 'value' => $options['wcf-heading-color'],
562
- )
563
- );
564
-
565
- echo wcf()->meta->get_font_family_field(
566
- array(
567
- 'for' => 'wcf-heading',
568
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
569
- 'name' => 'wcf-heading-font-family',
570
- 'value' => $options['wcf-heading-font-family'],
571
- )
572
- );
573
-
574
- echo wcf()->meta->get_font_weight_field(
575
- array(
576
- 'for' => 'wcf-heading',
577
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
578
- 'name' => 'wcf-heading-font-weight',
579
- 'value' => $options['wcf-heading-font-weight'],
580
- )
581
- );
582
-
583
- echo wcf()->meta->get_section(
584
- array(
585
- 'label' => __( 'Input Fields', 'cartflows' ),
586
- )
587
- );
588
-
589
- $fields_skin_pro_option = array();
590
-
591
- if ( ! _is_cartflows_pro() ) {
592
- $fields_skin_pro_option = array(
593
- 'style-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
594
- );
595
- }
596
-
597
- echo wcf()->meta->get_select_field(
598
- array(
599
- 'label' => __( 'Style', 'cartflows' ),
600
- 'name' => 'wcf-fields-skins',
601
- 'value' => $options['wcf-fields-skins'],
602
- 'options' => array(
603
- 'default' => esc_html__( 'Default', 'cartflows' ),
604
- 'style-one' => esc_html__( 'Floating Labels', 'cartflows' ),
605
- ),
606
- 'pro-options' => $fields_skin_pro_option,
607
-
608
- )
609
- );
610
-
611
- echo wcf()->meta->get_font_family_field(
612
- array(
613
- 'for' => 'wcf-input',
614
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
615
- 'name' => 'wcf-input-font-family',
616
- 'value' => $options['wcf-input-font-family'],
617
- )
618
- );
619
-
620
- echo wcf()->meta->get_font_weight_field(
621
- array(
622
- 'for' => 'wcf-input',
623
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
624
- 'name' => 'wcf-input-font-weight',
625
- 'value' => $options['wcf-input-font-weight'],
626
- )
627
- );
628
-
629
- echo wcf()->meta->get_select_field(
630
- array(
631
- 'label' => __( 'Size', 'cartflows' ),
632
- 'name' => 'wcf-input-field-size',
633
- 'value' => $options['wcf-input-field-size'],
634
- 'options' => array(
635
- '33px' => esc_html__( 'Extra Small', 'cartflows' ),
636
- '38px' => esc_html__( 'Small', 'cartflows' ),
637
- '44px' => esc_html__( 'Medium', 'cartflows' ),
638
- '58px' => esc_html__( 'Large', 'cartflows' ),
639
- '68px' => esc_html__( 'Extra Large', 'cartflows' ),
640
- 'custom' => esc_html__( 'Custom', 'cartflows' ),
641
- ),
642
- )
643
- );
644
-
645
- echo wcf()->meta->get_number_field(
646
- array(
647
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
648
- 'name' => 'wcf-field-tb-padding',
649
- 'value' => $options['wcf-field-tb-padding'],
650
- )
651
- );
652
-
653
- echo wcf()->meta->get_number_field(
654
- array(
655
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
656
- 'name' => 'wcf-field-lr-padding',
657
- 'value' => $options['wcf-field-lr-padding'],
658
- )
659
- );
660
-
661
- echo wcf()->meta->get_color_picker_field(
662
- array(
663
- 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
664
- 'name' => 'wcf-field-color',
665
- 'value' => $options['wcf-field-color'],
666
- )
667
- );
668
-
669
- echo wcf()->meta->get_color_picker_field(
670
- array(
671
- 'label' => __( 'Background Color', 'cartflows' ),
672
- 'name' => 'wcf-field-bg-color',
673
- 'value' => $options['wcf-field-bg-color'],
674
- )
675
- );
676
-
677
- echo wcf()->meta->get_color_picker_field(
678
- array(
679
- 'label' => __( 'Border Color', 'cartflows' ),
680
- 'name' => 'wcf-field-border-color',
681
- 'value' => $options['wcf-field-border-color'],
682
- )
683
- );
684
- echo wcf()->meta->get_color_picker_field(
685
- array(
686
- 'label' => __( 'Label Color', 'cartflows' ),
687
- 'name' => 'wcf-field-label-color',
688
- 'value' => $options['wcf-field-label-color'],
689
- )
690
- );
691
-
692
- ?>
693
- </div>
694
- <div class="wcf-cs-button-options">
695
- <?php
696
-
697
- echo wcf()->meta->get_section(
698
- array(
699
- 'label' => __( 'Buttons', 'cartflows' ),
700
- )
701
- );
702
-
703
- echo wcf()->meta->get_font_family_field(
704
- array(
705
- 'for' => 'wcf-button',
706
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
707
- 'name' => 'wcf-button-font-family',
708
- 'value' => $options['wcf-button-font-family'],
709
- )
710
- );
711
-
712
- echo wcf()->meta->get_font_weight_field(
713
- array(
714
- 'for' => 'wcf-button',
715
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
716
- 'name' => 'wcf-button-font-weight',
717
- 'value' => $options['wcf-button-font-weight'],
718
- )
719
- );
720
-
721
- echo wcf()->meta->get_select_field(
722
- array(
723
- 'label' => __( 'Size', 'cartflows' ),
724
- 'name' => 'wcf-input-button-size',
725
- 'value' => $options['wcf-input-button-size'],
726
- 'options' => array(
727
- '33px' => esc_html__( 'Extra Small', 'cartflows' ),
728
- '38px' => esc_html__( 'Small', 'cartflows' ),
729
- '44px' => esc_html__( 'Medium', 'cartflows' ),
730
- '58px' => esc_html__( 'Large', 'cartflows' ),
731
- '68px' => esc_html__( 'Extra Large', 'cartflows' ),
732
- 'custom' => esc_html__( 'Custom', 'cartflows' ),
733
- ),
734
- )
735
- );
736
-
737
- echo wcf()->meta->get_number_field(
738
- array(
739
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
740
- 'name' => 'wcf-submit-tb-padding',
741
- 'value' => $options['wcf-submit-tb-padding'],
742
- )
743
- );
744
-
745
- echo wcf()->meta->get_number_field(
746
- array(
747
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
748
- 'name' => 'wcf-submit-lr-padding',
749
- 'value' => $options['wcf-submit-lr-padding'],
750
- )
751
- );
752
-
753
- echo wcf()->meta->get_color_picker_field(
754
- array(
755
- 'label' => __( 'Text Color', 'cartflows' ),
756
- 'name' => 'wcf-submit-color',
757
- 'value' => $options['wcf-submit-color'],
758
- )
759
- );
760
-
761
- echo wcf()->meta->get_color_picker_field(
762
- array(
763
- 'label' => __( 'Text Hover Color', 'cartflows' ),
764
- 'name' => 'wcf-submit-hover-color',
765
- 'value' => $options['wcf-submit-hover-color'],
766
- )
767
- );
768
-
769
- echo wcf()->meta->get_color_picker_field(
770
- array(
771
- 'label' => __( 'Background Color', 'cartflows' ),
772
- 'name' => 'wcf-submit-bg-color',
773
- 'value' => $options['wcf-submit-bg-color'],
774
- )
775
- );
776
-
777
- echo wcf()->meta->get_color_picker_field(
778
- array(
779
- 'label' => __( 'Background Hover Color', 'cartflows' ),
780
- 'name' => 'wcf-submit-bg-hover-color',
781
- 'value' => $options['wcf-submit-bg-hover-color'],
782
- )
783
- );
784
-
785
- echo wcf()->meta->get_color_picker_field(
786
- array(
787
- 'label' => __( 'Border Color', 'cartflows' ),
788
- 'name' => 'wcf-submit-border-color',
789
- 'value' => $options['wcf-submit-border-color'],
790
- )
791
- );
792
-
793
- echo wcf()->meta->get_color_picker_field(
794
- array(
795
- 'label' => __( 'Border Hover Color', 'cartflows' ),
796
- 'name' => 'wcf-submit-border-hover-color',
797
- 'value' => $options['wcf-submit-border-hover-color'],
798
- )
799
- );
800
-
801
- ?>
802
- </div>
803
- <div class="wcf-cs-section-options">
804
- <?php
805
-
806
- echo wcf()->meta->get_section(
807
- array(
808
- 'label' => __( 'Sections', 'cartflows' ),
809
- )
810
- );
811
-
812
- echo wcf()->meta->get_color_picker_field(
813
- array(
814
- 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
815
- 'name' => 'wcf-hl-bg-color',
816
- 'value' => $options['wcf-hl-bg-color'],
817
- )
818
- );
819
-
820
- echo wcf()->meta->get_hidden_field(
821
- array(
822
- 'name' => 'wcf-field-google-font-url',
823
- 'value' => $options['wcf-field-google-font-url'],
824
- )
825
- );
826
- ?>
827
- </div>
828
- <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
829
- </div>
830
- </div>
831
- <?php
832
- }
833
-
834
-
835
- /**
836
- * Tab Header (Used for add logo into header)
837
- *
838
- * @param array $options options.
839
- * @param int $post_id post ID.
840
- */
841
- public function tab_header_content( $options, $post_id ) {
842
- ?>
843
-
844
- <div class="wcf-checkout-header wcf-tab-content widefat">
845
- <?php
846
-
847
- $layout_pro_option = array();
848
-
849
- echo wcf()->meta->get_image_field(
850
- array(
851
- 'name' => 'wcf-header-logo-image',
852
- 'value' => $options['wcf-header-logo-image'],
853
- 'label' => esc_html__( 'Header Logo', 'cartflows' ),
854
- )
855
- );
856
-
857
- echo wcf()->meta->get_number_field(
858
- array(
859
- 'name' => 'wcf-header-logo-width',
860
- 'value' => $options['wcf-header-logo-width'],
861
- 'label' => esc_html__( 'Logo Width (In px)', 'cartflows' ),
862
- )
863
- );
864
- ?>
865
- <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
866
- </div>
867
- <?php
868
- }
869
- /**
870
- * Get metabox options
871
- *
872
- * @param int $post_id post ID.
873
- */
874
- public static function get_meta_option( $post_id ) {
875
-
876
- if ( null === self::$meta_option ) {
877
-
878
- /**
879
- * Set metabox options
880
- *
881
- * @see http://php.net/manual/en/filter.filters.sanitize.php
882
- */
883
- self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
884
- }
885
-
886
- return self::$meta_option;
887
- }
888
-
889
- /**
890
- * Metabox Save
891
- *
892
- * @param number $post_id Post ID.
893
- * @return void
894
- */
895
- public function save_meta_box( $post_id ) {
896
-
897
- // Checks save status.
898
- $is_autosave = wp_is_post_autosave( $post_id );
899
- $is_revision = wp_is_post_revision( $post_id );
900
-
901
- $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-checkout-step-meta'] ) ), 'save-nonce-checkout-step-meta' ) ) ? true : false;
902
-
903
- // Exits script depending on save status.
904
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
905
- return;
906
- }
907
-
908
- wcf()->options->save_checkout_fields( $post_id );
909
- }
910
- }
911
-
912
- /**
913
- * Kicking this off by calling 'get_instance()' method
914
- */
915
- 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
+ /**
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
+ * 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
+ public function setup_meta_box() {
61
+
62
+ if ( _is_wcf_checkout_type() ) {
63
+ add_meta_box(
64
+ 'wcf-checkout-settings', // Id.
65
+ __( 'Checkout Layout', '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
+ public function markup_meta_box( $post ) {
81
+
82
+ wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
83
+
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
+ $checkout_data = array();
100
+
101
+ foreach ( $meta as $key => $value ) {
102
+ $checkout_data[ $key ] = $meta[ $key ]['default'];
103
+ }
104
+
105
+ /**
106
+ $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
107
+
108
+ // For loop
109
+ foreach ( $billing_fields as $key => $value ) {
110
+
111
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
112
+ }
113
+
114
+ $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
115
+
116
+ foreach ( $shipping_fields as $key => $value ) {
117
+
118
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
119
+ }
120
+
121
+ $additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
122
+
123
+ foreach ( $additional_fields as $key => $value ) {
124
+
125
+ $checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
126
+ }
127
+ */
128
+
129
+ do_action( 'wcf_checkout_settings_markup_before' );
130
+ $this->tabs_markup( $checkout_data, $post->ID );
131
+ do_action( 'wcf_checkout_settings_markup_after' );
132
+ }
133
+
134
+ /**
135
+ * Page Header Tabs
136
+ *
137
+ * @param array $options options.
138
+ * @param int $post_id post ID.
139
+ */
140
+ public function tabs_markup( $options, $post_id ) {
141
+
142
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
143
+
144
+ if ( empty( $active_tab ) ) {
145
+ $active_tab = 'wcf-checkout-shortcodes';
146
+ }
147
+
148
+ $tab_array = array(
149
+ array(
150
+ 'title' => __( 'Shortcodes', 'cartflows' ),
151
+ 'id' => 'wcf-checkout-shortcodes',
152
+ 'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
153
+ 'icon' => 'dashicons-editor-code',
154
+ ),
155
+ array(
156
+ 'title' => __( 'Select Product', 'cartflows' ),
157
+ 'id' => 'wcf-checkout-general',
158
+ 'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
159
+ 'icon' => 'dashicons-info',
160
+ ),
161
+ array(
162
+ 'title' => __( 'Order Bump', 'cartflows' ),
163
+ 'id' => 'wcf-product-order-bump',
164
+ 'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
165
+ 'icon' => 'dashicons-cart',
166
+ ),
167
+ array(
168
+ 'title' => __( 'Checkout Offer', 'cartflows' ),
169
+ 'id' => 'wcf-pre-checkout-offer',
170
+ 'class' => 'wcf-pre-checkout-offer' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
171
+ 'icon' => 'dashicons-arrow-up-alt',
172
+ ),
173
+ array(
174
+ 'title' => __( 'Checkout Design', 'cartflows' ),
175
+ 'id' => 'wcf-checkout-style',
176
+ 'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
177
+ 'icon' => 'dashicons-admin-customizer',
178
+ ),
179
+ array(
180
+ 'title' => __( 'Checkout Fields', 'cartflows' ),
181
+ 'id' => 'wcf-checkout-custom-fields',
182
+ 'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
183
+ 'icon' => 'dashicons-welcome-widgets-menus',
184
+ ),
185
+ array(
186
+ 'title' => __( 'Checkout Settings', 'cartflows' ),
187
+ 'id' => 'wcf-checkout-custom-settings',
188
+ 'class' => 'wcf-checkout-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
189
+ 'icon' => 'dashicons-admin-generic',
190
+ ),
191
+ array(
192
+ 'title' => __( 'Custom Script', 'cartflows' ),
193
+ 'id' => 'wcf-checkout-custom-script-header',
194
+ 'class' => 'wcf-checkout-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
195
+ 'icon' => 'dashicons-format-aside',
196
+ ),
197
+ );
198
+
199
+ $show_logo = filter_input( INPUT_GET, 'logo-tab', FILTER_VALIDATE_BOOLEAN );
200
+
201
+ if ( $show_logo ) {
202
+ $logo_tab = array(
203
+ 'title' => __( 'Logo (Optional)', 'cartflows' ),
204
+ 'id' => 'wcf-checkout-header',
205
+ 'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
206
+ 'icon' => 'dashicons-format-image',
207
+ );
208
+ array_push( $tab_array, $logo_tab );
209
+ }
210
+
211
+ $tabs = apply_filters( 'cartflows_checkout_tabs', $tab_array, $active_tab );
212
+
213
+ ?>
214
+ <div class="wcf-checkout-table wcf-metabox-wrap widefat">
215
+ <div class="wcf-table-container">
216
+ <div class="wcf-column-left">
217
+ <div class="wcf-tab-wrapper">
218
+
219
+ <?php foreach ( $tabs as $key => $tab ) { ?>
220
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
221
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
222
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
223
+ </div>
224
+ <?php } ?>
225
+
226
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
227
+ </div>
228
+ </div>
229
+ <div class="wcf-column-right">
230
+ <?php $this->tab_shortcodes( $options, $post_id ); ?>
231
+ <?php $this->tab_general( $options, $post_id ); ?>
232
+ <?php $this->tab_style( $options, $post_id ); ?>
233
+ <?php $this->tab_pre_checkout_offer( $options, $post_id ); ?>
234
+ <?php $this->tab_product_bump( $options, $post_id ); ?>
235
+ <?php $this->tab_custom_fields( $options, $post_id ); ?>
236
+ <?php $this->tab_custom_settings( $options, $post_id ); ?>
237
+ <?php $this->tab_header_content( $options, $post_id ); ?>
238
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
239
+ <?php do_action( 'cartflows_checkout_tabs_content', $options, $post_id ); ?>
240
+ <?php $this->right_column_footer( $options, $post_id ); ?>
241
+ </div>
242
+ </div>
243
+ </div>
244
+
245
+ <?php
246
+ }
247
+
248
+ /**
249
+ * Shortcodes tab
250
+ *
251
+ * @param array $options options.
252
+ * @param int $post_id post ID.
253
+ */
254
+ public function tab_shortcodes( $options, $post_id ) {
255
+ ?>
256
+ <div class="wcf-checkout-shortcodes wcf-tab-content widefat">
257
+
258
+ <?php
259
+
260
+ echo wcf()->meta->get_shortcode_field(
261
+ array(
262
+ 'label' => 'Checkout Page',
263
+ 'name' => 'wcf-checkout-shortcode',
264
+ 'content' => '[cartflows_checkout]',
265
+ 'help' => esc_html__( 'Add this shortcode to your checkout page', 'cartflows' ),
266
+ )
267
+ );
268
+ ?>
269
+ </div>
270
+ <?php
271
+ }
272
+
273
+
274
+ /**
275
+ * General tab
276
+ *
277
+ * @param array $options options.
278
+ * @param int $post_id post ID.
279
+ */
280
+ public function tab_general( $options, $post_id ) {
281
+ ?>
282
+ <div class="wcf-checkout-general wcf-tab-content widefat">
283
+
284
+ <?php
285
+
286
+ echo wcf()->meta->get_product_selection_repeater(
287
+ array(
288
+ 'name' => 'wcf-checkout-products',
289
+ 'value' => $options['wcf-checkout-products'],
290
+ 'allow_clear' => true,
291
+ )
292
+ );
293
+
294
+ if ( ! _is_cartflows_pro() ) {
295
+
296
+ echo wcf()->meta->get_hr_line_field( array() );
297
+ echo wcf()->meta->get_description_field(
298
+ array(
299
+ 'name' => 'wcf-upgrade-to-pro',
300
+ /* translators: %s: link */
301
+ 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Pre-applied Coupon, Product Variations & Quantity Options.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
302
+ )
303
+ );
304
+ }
305
+
306
+ do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
307
+
308
+ ?>
309
+ </div>
310
+ <?php
311
+ }
312
+
313
+ /**
314
+ * Pre Checkout tab
315
+ *
316
+ * @param array $options options.
317
+ * @param int $post_id post ID.
318
+ */
319
+ public function tab_pre_checkout_offer( $options, $post_id ) {
320
+ ?>
321
+ <div class="wcf-pre-checkout-offer wcf-tab-content widefat">
322
+ <?php
323
+ if ( ! _is_cartflows_pro() ) {
324
+ echo wcf()->meta->get_description_field(
325
+ array(
326
+ 'name' => 'wcf-upgrade-to-pro',
327
+ /* translators: %s: link */
328
+ 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Checkout Offer feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
329
+ )
330
+ );
331
+ } elseif ( _is_cartflows_pro_ver_less_than( '1.2.0' ) ) {
332
+
333
+ $version = '1.2.0';
334
+ echo wcf()->meta->get_description_field(
335
+ array(
336
+ 'name' => 'wcf-upgrade-to-pro',
337
+ /* translators: %s: link */
338
+ 'content' => '<i>' . sprintf( esc_html__( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for Checkout Offer feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>', $version ) . '</i>',
339
+ )
340
+ );
341
+ }
342
+ ?>
343
+
344
+ <?php do_action( 'cartflows_pre_checkout_offer_tab_content', $options, $post_id ); ?>
345
+ </div>
346
+ <?php
347
+ }
348
+
349
+
350
+ /**
351
+ * Pre Checkout tab
352
+ *
353
+ * @param array $options options.
354
+ * @param int $post_id post ID.
355
+ */
356
+ public function animate_title_settings( $options, $post_id ) {
357
+
358
+ echo wcf()->meta->get_hr_line_field( array() );
359
+
360
+ if ( ! _is_cartflows_pro() ) {
361
+ echo wcf()->meta->get_description_field(
362
+ array(
363
+ 'name' => 'wcf-upgrade-to-pro',
364
+ /* translators: %s: link */
365
+ 'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for animate browser tab feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
366
+ )
367
+ );
368
+ } elseif ( _is_cartflows_pro_ver_less_than( '1.4.0' ) ) {
369
+
370
+ $version = '1.4.0';
371
+ echo wcf()->meta->get_description_field(
372
+ array(
373
+ 'name' => 'wcf-upgrade-to-pro',
374
+ /* translators: %s: link */
375
+ 'content' => '<i>' . sprintf( __( 'Update to %1$sCartFlows Pro%2$s to %3$s or above for animate browser tab feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>', $version ) . '</i>',
376
+ )
377
+ );
378
+ }
379
+
380
+ do_action( 'cartflows_animate_browser_tab_settings', $options, $post_id );
381
+ }
382
+
383
+ /**
384
+ * Product bump tab
385
+ *
386
+ * @param array $options options.
387
+ * @param int $post_id post ID.
388
+ */
389
+ public function tab_product_bump( $options, $post_id ) {
390
+ ?>
391
+ <div class="wcf-product-order-bump wcf-tab-content widefat">
392
+ <?php
393
+ if ( ! _is_cartflows_pro() ) {
394
+ echo wcf()->meta->get_description_field(
395
+ array(
396
+ 'name' => 'wcf-upgrade-to-pro',
397
+ /* translators: %s: link */
398
+ 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
399
+ )
400
+ );
401
+ }
402
+ ?>
403
+
404
+ <?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
405
+ </div>
406
+ <?php
407
+ }
408
+ /**
409
+ * Tab custom fields
410
+ *
411
+ * @param array $options options.
412
+ * @param int $post_id post ID.
413
+ */
414
+ public function tab_custom_fields( $options, $post_id ) {
415
+ ?>
416
+ <div class="wcf-checkout-custom-fields wcf-tab-content widefat">
417
+ <?php
418
+ /* Custom Checkout Fields Section */
419
+
420
+ if ( ! _is_cartflows_pro() ) {
421
+ echo wcf()->meta->get_description_field(
422
+ array(
423
+ 'name' => 'wcf-upgrade-to-pro',
424
+ /* translators: %s: link */
425
+ 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
426
+ )
427
+ );
428
+ }
429
+ ?>
430
+ <?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
431
+ </div>
432
+ <?php
433
+ }
434
+ /**
435
+ * Tab custom settings
436
+ *
437
+ * @param array $options options.
438
+ * @param int $post_id post ID.
439
+ */
440
+ public function tab_custom_settings( $options, $post_id ) {
441
+ ?>
442
+ <div class="wcf-checkout-custom-settings wcf-tab-content widefat">
443
+ <div class="wcf-custom-settings-fields">
444
+ <?php
445
+
446
+ echo wcf()->meta->get_text_field(
447
+ array(
448
+ 'label' => __( 'Place Order Button Text', 'cartflows' ),
449
+ 'name' => 'wcf-checkout-place-order-button-text',
450
+ 'value' => $options['wcf-checkout-place-order-button-text'],
451
+ 'attr' => array(
452
+ 'placeholder' => __( 'Place order', 'cartflows' ),
453
+ ),
454
+ 'help' => __( 'It will change the Place Order Button text on checkout page.', 'cartflows' ),
455
+ )
456
+ );
457
+
458
+ echo wcf()->meta->get_hr_line_field( array() );
459
+
460
+ echo wcf()->meta->get_checkbox_field(
461
+ array(
462
+ 'name' => 'wcf-remove-product-field',
463
+ 'value' => $options['wcf-remove-product-field'],
464
+ 'after' => esc_html__( 'Enable cart editing on checkout', 'cartflows' ),
465
+ )
466
+ );
467
+
468
+ echo wcf()->meta->get_description_field(
469
+ array(
470
+ 'name' => '',
471
+ /* translators: %s: link */
472
+ 'content' => '<i>' . sprintf( esc_html__( 'Users will able to remove products from the checkout page.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
473
+ )
474
+ );
475
+
476
+ $this->animate_title_settings( $options, $post_id );
477
+ ?>
478
+ </div>
479
+ <?php do_action( 'cartflows_custom_settings_tab_content', $options, $post_id ); ?>
480
+ </div>
481
+ <?php
482
+ }
483
+
484
+ /**
485
+ * Tab style
486
+ *
487
+ * @param array $options options.
488
+ * @param int $post_id post ID.
489
+ */
490
+ public function tab_style( $options, $post_id ) {
491
+ ?>
492
+
493
+ <div class="wcf-checkout-style wcf-tab-content widefat">
494
+ <div class="wcf-cs-fields">
495
+ <div class="wcf-cs-checkbox-field">
496
+ <?php
497
+
498
+ $layout_pro_option = array();
499
+
500
+ if ( ! _is_cartflows_pro() ) {
501
+ $layout_pro_option = array(
502
+ 'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
503
+ 'two-step' => __( 'Two Step (Available in CartFlows Pro) ', 'cartflows' ),
504
+ );
505
+ }
506
+
507
+ echo wcf()->meta->get_select_field(
508
+ array(
509
+ 'label' => __( 'Checkout Skin', 'cartflows' ),
510
+ 'name' => 'wcf-checkout-layout',
511
+ 'value' => $options['wcf-checkout-layout'],
512
+ 'options' => array(
513
+ 'one-column' => esc_html__( 'One Column', 'cartflows' ),
514
+ 'two-column' => esc_html__( 'Two Column', 'cartflows' ),
515
+ 'two-step' => esc_html__( 'Two Step', 'cartflows' ),
516
+ ),
517
+ 'pro-options' => $layout_pro_option,
518
+
519
+ )
520
+ );
521
+
522
+ echo wcf()->meta->get_color_picker_field(
523
+ array(
524
+ 'label' => __( 'Primary Color', 'cartflows' ),
525
+ 'name' => 'wcf-primary-color',
526
+ 'value' => $options['wcf-primary-color'],
527
+ )
528
+ );
529
+
530
+ echo wcf()->meta->get_font_family_field(
531
+ array(
532
+ 'for' => 'wcf-base',
533
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
534
+ 'name' => 'wcf-base-font-family',
535
+ 'value' => $options['wcf-base-font-family'],
536
+ )
537
+ );
538
+
539
+ echo wcf()->meta->get_checkbox_field(
540
+ array(
541
+ 'label' => __( 'Advance Options', 'cartflows' ),
542
+ 'name' => 'wcf-advance-options-fields',
543
+ 'value' => $options['wcf-advance-options-fields'],
544
+ 'after' => 'Enable',
545
+ )
546
+ );
547
+ ?>
548
+ </div>
549
+ <div class="wcf-cs-fields-options">
550
+ <?php
551
+ echo wcf()->meta->get_section(
552
+ array(
553
+ 'label' => __( 'Heading', 'cartflows' ),
554
+ )
555
+ );
556
+
557
+ echo wcf()->meta->get_color_picker_field(
558
+ array(
559
+ 'label' => __( 'Heading Color', 'cartflows' ),
560
+ 'name' => 'wcf-heading-color',
561
+ 'value' => $options['wcf-heading-color'],
562
+ )
563
+ );
564
+
565
+ echo wcf()->meta->get_font_family_field(
566
+ array(
567
+ 'for' => 'wcf-heading',
568
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
569
+ 'name' => 'wcf-heading-font-family',
570
+ 'value' => $options['wcf-heading-font-family'],
571
+ )
572
+ );
573
+
574
+ echo wcf()->meta->get_font_weight_field(
575
+ array(
576
+ 'for' => 'wcf-heading',
577
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
578
+ 'name' => 'wcf-heading-font-weight',
579
+ 'value' => $options['wcf-heading-font-weight'],
580
+ )
581
+ );
582
+
583
+ echo wcf()->meta->get_section(
584
+ array(
585
+ 'label' => __( 'Input Fields', 'cartflows' ),
586
+ )
587
+ );
588
+
589
+ $fields_skin_pro_option = array();
590
+
591
+ if ( ! _is_cartflows_pro() ) {
592
+ $fields_skin_pro_option = array(
593
+ 'style-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
594
+ );
595
+ }
596
+
597
+ echo wcf()->meta->get_select_field(
598
+ array(
599
+ 'label' => __( 'Style', 'cartflows' ),
600
+ 'name' => 'wcf-fields-skins',
601
+ 'value' => $options['wcf-fields-skins'],
602
+ 'options' => array(
603
+ 'default' => esc_html__( 'Default', 'cartflows' ),
604
+ 'style-one' => esc_html__( 'Floating Labels', 'cartflows' ),
605
+ ),
606
+ 'pro-options' => $fields_skin_pro_option,
607
+
608
+ )
609
+ );
610
+
611
+ echo wcf()->meta->get_font_family_field(
612
+ array(
613
+ 'for' => 'wcf-input',
614
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
615
+ 'name' => 'wcf-input-font-family',
616
+ 'value' => $options['wcf-input-font-family'],
617
+ )
618
+ );
619
+
620
+ echo wcf()->meta->get_font_weight_field(
621
+ array(
622
+ 'for' => 'wcf-input',
623
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
624
+ 'name' => 'wcf-input-font-weight',
625
+ 'value' => $options['wcf-input-font-weight'],
626
+ )
627
+ );
628
+
629
+ echo wcf()->meta->get_select_field(
630
+ array(
631
+ 'label' => __( 'Size', 'cartflows' ),
632
+ 'name' => 'wcf-input-field-size',
633
+ 'value' => $options['wcf-input-field-size'],
634
+ 'options' => array(
635
+ '33px' => esc_html__( 'Extra Small', 'cartflows' ),
636
+ '38px' => esc_html__( 'Small', 'cartflows' ),
637
+ '44px' => esc_html__( 'Medium', 'cartflows' ),
638
+ '58px' => esc_html__( 'Large', 'cartflows' ),
639
+ '68px' => esc_html__( 'Extra Large', 'cartflows' ),
640
+ 'custom' => esc_html__( 'Custom', 'cartflows' ),
641
+ ),
642
+ )
643
+ );
644
+
645
+ echo wcf()->meta->get_number_field(
646
+ array(
647
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
648
+ 'name' => 'wcf-field-tb-padding',
649
+ 'value' => $options['wcf-field-tb-padding'],
650
+ )
651
+ );
652
+
653
+ echo wcf()->meta->get_number_field(
654
+ array(
655
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
656
+ 'name' => 'wcf-field-lr-padding',
657
+ 'value' => $options['wcf-field-lr-padding'],
658
+ )
659
+ );
660
+
661
+ echo wcf()->meta->get_color_picker_field(
662
+ array(
663
+ 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
664
+ 'name' => 'wcf-field-color',
665
+ 'value' => $options['wcf-field-color'],
666
+ )
667
+ );
668
+
669
+ echo wcf()->meta->get_color_picker_field(
670
+ array(
671
+ 'label' => __( 'Background Color', 'cartflows' ),
672
+ 'name' => 'wcf-field-bg-color',
673
+ 'value' => $options['wcf-field-bg-color'],
674
+ )
675
+ );
676
+
677
+ echo wcf()->meta->get_color_picker_field(
678
+ array(
679
+ 'label' => __( 'Border Color', 'cartflows' ),
680
+ 'name' => 'wcf-field-border-color',
681
+ 'value' => $options['wcf-field-border-color'],
682
+ )
683
+ );
684
+ echo wcf()->meta->get_color_picker_field(
685
+ array(
686
+ 'label' => __( 'Label Color', 'cartflows' ),
687
+ 'name' => 'wcf-field-label-color',
688
+ 'value' => $options['wcf-field-label-color'],
689
+ )
690
+ );
691
+
692
+ ?>
693
+ </div>
694
+ <div class="wcf-cs-button-options">
695
+ <?php
696
+
697
+ echo wcf()->meta->get_section(
698
+ array(
699
+ 'label' => __( 'Buttons', 'cartflows' ),
700
+ )
701
+ );
702
+
703
+ echo wcf()->meta->get_font_family_field(
704
+ array(
705
+ 'for' => 'wcf-button',
706
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
707
+ 'name' => 'wcf-button-font-family',
708
+ 'value' => $options['wcf-button-font-family'],
709
+ )
710
+ );
711
+
712
+ echo wcf()->meta->get_font_weight_field(
713
+ array(
714
+ 'for' => 'wcf-button',
715
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
716
+ 'name' => 'wcf-button-font-weight',
717
+ 'value' => $options['wcf-button-font-weight'],
718
+ )
719
+ );
720
+
721
+ echo wcf()->meta->get_select_field(
722
+ array(
723
+ 'label' => __( 'Size', 'cartflows' ),
724
+ 'name' => 'wcf-input-button-size',
725
+ 'value' => $options['wcf-input-button-size'],
726
+ 'options' => array(
727
+ '33px' => esc_html__( 'Extra Small', 'cartflows' ),
728
+ '38px' => esc_html__( 'Small', 'cartflows' ),
729
+ '44px' => esc_html__( 'Medium', 'cartflows' ),
730
+ '58px' => esc_html__( 'Large', 'cartflows' ),
731
+ '68px' => esc_html__( 'Extra Large', 'cartflows' ),
732
+ 'custom' => esc_html__( 'Custom', 'cartflows' ),
733
+ ),
734
+ )
735
+ );
736
+
737
+ echo wcf()->meta->get_number_field(
738
+ array(
739
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
740
+ 'name' => 'wcf-submit-tb-padding',
741
+ 'value' => $options['wcf-submit-tb-padding'],
742
+ )
743
+ );
744
+
745
+ echo wcf()->meta->get_number_field(
746
+ array(
747
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
748
+ 'name' => 'wcf-submit-lr-padding',
749
+ 'value' => $options['wcf-submit-lr-padding'],
750
+ )
751
+ );
752
+
753
+ echo wcf()->meta->get_color_picker_field(
754
+ array(
755
+ 'label' => __( 'Text Color', 'cartflows' ),
756
+ 'name' => 'wcf-submit-color',
757
+ 'value' => $options['wcf-submit-color'],
758
+ )
759
+ );
760
+
761
+ echo wcf()->meta->get_color_picker_field(
762
+ array(
763
+ 'label' => __( 'Text Hover Color', 'cartflows' ),
764
+ 'name' => 'wcf-submit-hover-color',
765
+ 'value' => $options['wcf-submit-hover-color'],
766
+ )
767
+ );
768
+
769
+ echo wcf()->meta->get_color_picker_field(
770
+ array(
771
+ 'label' => __( 'Background Color', 'cartflows' ),
772
+ 'name' => 'wcf-submit-bg-color',
773
+ 'value' => $options['wcf-submit-bg-color'],
774
+ )
775
+ );
776
+
777
+ echo wcf()->meta->get_color_picker_field(
778
+ array(
779
+ 'label' => __( 'Background Hover Color', 'cartflows' ),
780
+ 'name' => 'wcf-submit-bg-hover-color',
781
+ 'value' => $options['wcf-submit-bg-hover-color'],
782
+ )
783
+ );
784
+
785
+ echo wcf()->meta->get_color_picker_field(
786
+ array(
787
+ 'label' => __( 'Border Color', 'cartflows' ),
788
+ 'name' => 'wcf-submit-border-color',
789
+ 'value' => $options['wcf-submit-border-color'],
790
+ )
791
+ );
792
+
793
+ echo wcf()->meta->get_color_picker_field(
794
+ array(
795
+ 'label' => __( 'Border Hover Color', 'cartflows' ),
796
+ 'name' => 'wcf-submit-border-hover-color',
797
+ 'value' => $options['wcf-submit-border-hover-color'],
798
+ )
799
+ );
800
+
801
+ ?>
802
+ </div>
803
+ <div class="wcf-cs-section-options">
804
+ <?php
805
+
806
+ echo wcf()->meta->get_section(
807
+ array(
808
+ 'label' => __( 'Sections', 'cartflows' ),
809
+ )
810
+ );
811
+
812
+ echo wcf()->meta->get_color_picker_field(
813
+ array(
814
+ 'label' => __( 'Highlight Area Background Color', 'cartflows' ),
815
+ 'name' => 'wcf-hl-bg-color',
816
+ 'value' => $options['wcf-hl-bg-color'],
817
+ )
818
+ );
819
+
820
+ echo wcf()->meta->get_hidden_field(
821
+ array(
822
+ 'name' => 'wcf-field-google-font-url',
823
+ 'value' => $options['wcf-field-google-font-url'],
824
+ )
825
+ );
826
+ ?>
827
+ </div>
828
+ <?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
829
+ </div>
830
+ </div>
831
+ <?php
832
+ }
833
+
834
+
835
+ /**
836
+ * Tab Header (Used for add logo into header)
837
+ *
838
+ * @param array $options options.
839
+ * @param int $post_id post ID.
840
+ */
841
+ public function tab_header_content( $options, $post_id ) {
842
+ ?>
843
+
844
+ <div class="wcf-checkout-header wcf-tab-content widefat">
845
+ <?php
846
+
847
+ $layout_pro_option = array();
848
+
849
+ echo wcf()->meta->get_image_field(
850
+ array(
851
+ 'name' => 'wcf-header-logo-image',
852
+ 'value' => $options['wcf-header-logo-image'],
853
+ 'label' => esc_html__( 'Header Logo', 'cartflows' ),
854
+ )
855
+ );
856
+
857
+ echo wcf()->meta->get_number_field(
858
+ array(
859
+ 'name' => 'wcf-header-logo-width',
860
+ 'value' => $options['wcf-header-logo-width'],
861
+ 'label' => esc_html__( 'Logo Width (In px)', 'cartflows' ),
862
+ )
863
+ );
864
+ ?>
865
+ <?php do_action( 'cartflows_checkout_header_tab_content', $options, $post_id ); ?>
866
+ </div>
867
+ <?php
868
+ }
869
+ /**
870
+ * Get metabox options
871
+ *
872
+ * @param int $post_id post ID.
873
+ */
874
+ public static function get_meta_option( $post_id ) {
875
+
876
+ if ( null === self::$meta_option ) {
877
+
878
+ /**
879
+ * Set metabox options
880
+ *
881
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
882
+ */
883
+ self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
884
+ }
885
+
886
+ return self::$meta_option;
887
+ }
888
+
889
+ /**
890
+ * Metabox Save
891
+ *
892
+ * @param number $post_id Post ID.
893
+ * @return void
894
+ */
895
+ public function save_meta_box( $post_id ) {
896
+
897
+ // Checks save status.
898
+ $is_autosave = wp_is_post_autosave( $post_id );
899
+ $is_revision = wp_is_post_revision( $post_id );
900
+
901
+ $is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-checkout-step-meta'] ) ), 'save-nonce-checkout-step-meta' ) ) ? true : false;
902
+
903
+ // Exits script depending on save status.
904
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
905
+ return;
906
+ }
907
+
908
+ wcf()->options->save_checkout_fields( $post_id );
909
+ }
910
+ }
911
+
912
+ /**
913
+ * Kicking this off by calling 'get_instance()' method
914
+ */
915
+ Cartflows_Checkout_Meta::get_instance();
modules/checkout/includes/checkout-dynamic-css.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dynamic checkout css
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $output = "
9
+ .wcf-embed-checkout-form .woocommerce .woocommerce-checkout .product-name .remove:hover{
10
+ color:$primary_color !important;
11
+ border:1px solid $primary_color !important;
12
+ }
13
+ .wcf-embed-checkout-form .wcf-checkout-header-image img{
14
+ width: {$header_logo_width}px;
15
+ }
16
+ .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
17
+ .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
18
+ color: {$primary_color};
19
+ }
20
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
21
+ background-color: {$primary_color};
22
+ }
23
+ .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
24
+ .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
25
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
26
+ .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
27
+ border-color: {$primary_color};
28
+ box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
29
+ }
30
+ .wcf-embed-checkout-form .woocommerce-checkout label{
31
+ color: {$field_label_color};
32
+ }
33
+ .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
34
+ background-color: {$hl_bg_color};
35
+ font-family: {$input_font_family};
36
+ font-weight: {$input_font_weight};
37
+ }
38
+
39
+ .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
40
+ .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
41
+ .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
42
+ {
43
+ border-bottom-color: {$hl_bg_color};
44
+ border-right-color: transparent;
45
+ border-left-color: transparent;
46
+ border-top-color: transparent;
47
+ position: absolute;
48
+ }
49
+
50
+ .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
51
+ .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
52
+ font-family: {$input_font_family};
53
+ font-weight: {$input_font_weight};
54
+ }
55
+
56
+ .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
57
+ .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
58
+ .wcf-embed-checkout-form .woocommerce form .form-row textarea,
59
+ .wcf-embed-checkout-form .select2-container--default .select2-selection--single,
60
+ .wcf-embed-checkout-form .woocommerce form .form-row select.select {
61
+ color: {$field_color};
62
+ background: {$field_bg_color};
63
+ border-color: {$field_border_color};
64
+ padding-top: {$field_tb_padding}px;
65
+ padding-bottom: {$field_tb_padding}px;
66
+ padding-left: {$field_lr_padding}px;
67
+ padding-right: {$field_lr_padding}px;
68
+ min-height: {$field_input_size};
69
+ font-family: {$input_font_family};
70
+ font-weight: {$input_font_weight};
71
+ }
72
+
73
+ .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
74
+ .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
75
+ .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
76
+ .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
77
+ .wcf-embed-checkout-form .woocommerce-checkout #payment,
78
+ .wcf-embed-checkout-form .woocommerce form.checkout_coupon
79
+ {
80
+ background-color: {$section_bg_color};
81
+ border-color: {$box_border_color};
82
+ font-family: {$input_font_family};
83
+ font-weight: {$input_font_weight};
84
+ }
85
+
86
+ .woocommerce table.shop_table th{
87
+ color: {$field_label_color};
88
+ }
89
+ /*.wcf-embed-checkout-form .woocommerce .woocommerce-info,
90
+ .wcf-embed-checkout-form .woocommerce-message{
91
+ border-top-color: {$primary_color};
92
+ background-color: {$hl_bg_color};
93
+ }*/
94
+ .wcf-embed-checkout-form .woocommerce a{
95
+ color: {$primary_color};
96
+ }
97
+ .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
98
+ color: {$field_color};
99
+ }
100
+ .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
101
+ color: {$field_color};
102
+ }
103
+ .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
104
+ color: {$field_color};
105
+ }
106
+ .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
107
+ color: {$field_color};
108
+ }
109
+ .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
110
+ color: {$field_color};
111
+ }
112
+ .wcf-embed-checkout-form .woocommerce form p.form-row label {
113
+ color: {$field_label_color};
114
+ font-family: {$input_font_family};
115
+ font-weight: {$input_font_weight};
116
+ }
117
+ .wcf-embed-checkout-form .woocommerce #order_review button,
118
+ .wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
119
+ .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
120
+ color: {$submit_color};
121
+ background: {$submit_bg_color};
122
+ padding-top: {$submit_tb_padding}px;
123
+ padding-bottom: {$submit_tb_padding}px;
124
+ padding-left: {$submit_lr_padding}px;
125
+ padding-right: {$submit_lr_padding}px;
126
+ border-color: {$submit_border_color};
127
+ min-height: {$submit_button_height};
128
+ font-family: {$button_font_family};
129
+ font-weight: {$button_font_weight};
130
+ }
131
+ .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
132
+ .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
133
+ background: {$submit_bg_color};
134
+ border: 1px {$submit_border_color} solid;
135
+ color: {$submit_color};
136
+ min-height: {$submit_button_height};
137
+ font-family: {$button_font_family};
138
+ font-weight: {$button_font_weight};
139
+ }
140
+ .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
141
+ .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
142
+ .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
143
+ .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
144
+ color: {$submit_hover_color};
145
+ background-color: {$submit_bg_hover_color};
146
+ border-color: {$submit_border_hover_color};
147
+ }
148
+ .wcf-embed-checkout-form .woocommerce h3,
149
+ .wcf-embed-checkout-form .woocommerce h3 span,
150
+ .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
151
+ color: {$section_heading_color};
152
+ font-family: {$heading_font_family};
153
+ font-weight: {$heading_font_weight};
154
+ }
155
+ .wcf-embed-checkout-form .woocommerce-info::before,
156
+ .wcf-embed-checkout-form .woocommerce-message::before{
157
+ color: {$primary_color};
158
+ }
159
+ .wcf-embed-checkout-form{
160
+ font-family: {$base_font_family};
161
+ }
162
+ img.emoji, img.wp-smiley {}";
modules/checkout/includes/checkout-dynamic-divi-css.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dynamic checkout divi css
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $output = "
9
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .woocommerce-checkout .product-name .remove:hover{
10
+ color:$primary_color !important;
11
+ border:1px solid $primary_color !important;
12
+ }
13
+ .et_pb_module #wcf-embed-checkout-form .wcf-checkout-header-image img{
14
+ width: {$header_logo_width}px;
15
+ }
16
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
17
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
18
+ color: {$primary_color} !important;
19
+ }
20
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
21
+ background-color: {$primary_color};
22
+ }
23
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
24
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
25
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
26
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
27
+ border-color: {$primary_color} !important;
28
+ box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8) !important;
29
+ }
30
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout label{
31
+ color: {$field_label_color};
32
+ }
33
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
34
+ background-color: {$hl_bg_color};
35
+ font-family: {$input_font_family};
36
+ font-weight: {$input_font_weight};
37
+ }
38
+
39
+ .et_pb_module #wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
40
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
41
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
42
+ {
43
+ border-bottom-color: {$hl_bg_color};
44
+ border-right-color: transparent;
45
+ border-left-color: transparent;
46
+ border-top-color: transparent;
47
+ position: absolute;
48
+ }
49
+
50
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
51
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
52
+ font-family: {$input_font_family};
53
+ font-weight: {$input_font_weight};
54
+ }
55
+
56
+ .et_pb_module #wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
57
+ .et_pb_module #wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
58
+ .et_pb_module #wcf-embed-checkout-form .woocommerce form .form-row textarea,
59
+ .et_pb_module #wcf-embed-checkout-form .select2-container--default .select2-selection--single {
60
+ color: {$field_color} !important;
61
+ background-color: {$field_bg_color} !important;
62
+ border-color: {$field_border_color} !important;
63
+ padding-top: {$field_tb_padding}px;
64
+ padding-bottom: {$field_tb_padding}px;
65
+ padding-left: {$field_lr_padding}px;
66
+ padding-right: {$field_lr_padding}px;
67
+ min-height: {$field_input_size} !important;
68
+ font-family: {$input_font_family};
69
+ font-weight: {$input_font_weight};
70
+ }
71
+ .et_pb_module #wcf-embed-checkout-form.wcf-field-style-one .woocommerce .form-row input[type='text'],
72
+ .et_pb_module #wcf-embed-checkout-form.wcf-field-style-one .woocommerce .form-row input[type='email'],
73
+ .et_pb_module #wcf-embed-checkout-form.wcf-field-style-one .woocommerce .form-row input[type='password'],
74
+ .et_pb_module #wcf-embed-checkout-form.wcf-field-style-one .woocommerce .form-row input[type='tel'],
75
+ .et_pb_module #wcf-embed-checkout-form.wcf-field-style-one .select2-container--default .select2-selection--single{
76
+ padding:{$field_tb_padding}px {$field_lr_padding}px !important;
77
+
78
+ }
79
+
80
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .col2-set .col-1,
81
+ .et_pb_module #wcf-embed-checkout-form .woocommerce .col2-set .col-2,
82
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout .shop_table,
83
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
84
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout #payment,
85
+ .et_pb_module #wcf-embed-checkout-form .woocommerce form.checkout_coupon
86
+ {
87
+ background-color: {$section_bg_color};
88
+ border-color: {$box_border_color};
89
+ font-family: {$input_font_family};
90
+ font-weight: {$input_font_weight};
91
+ }
92
+
93
+ .et_pb_module #wcf-embed-checkout-form .woocommerce table.shop_table th{
94
+ color: {$field_label_color};
95
+ }
96
+ /*.et_pb_module #wcf-embed-checkout-form .woocommerce .woocommerce-info,
97
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-message{
98
+ border-top-color: {$primary_color};
99
+ background-color: {$hl_bg_color};
100
+ }*/
101
+ .et_pb_module #wcf-embed-checkout-form .woocommerce a:not(.wcf-next-button){
102
+ color: {$primary_color} !important;
103
+ }
104
+ .et_pb_module #wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
105
+ color: {$field_color};
106
+ }
107
+ .et_pb_module #wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
108
+ color: {$field_color};
109
+ }
110
+ .et_pb_module #wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
111
+ color: {$field_color};
112
+ }
113
+ .et_pb_module #wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
114
+ color: {$field_color};
115
+ }
116
+ .et_pb_module #wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
117
+ color: {$field_color};
118
+ }
119
+ .et_pb_module #wcf-embed-checkout-form .woocommerce form p.form-row label {
120
+ color: {$field_label_color};
121
+ font-family: {$input_font_family};
122
+ font-weight: {$input_font_weight};
123
+ }
124
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #order_review button,
125
+ .et_pb_module #wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
126
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
127
+ color: {$submit_color};
128
+ background: {$submit_bg_color};
129
+ padding-top: {$submit_tb_padding}px;
130
+ padding-bottom: {$submit_tb_padding}px;
131
+ padding-left: {$submit_lr_padding}px;
132
+ padding-right: {$submit_lr_padding}px;
133
+ border-color: {$submit_border_color};
134
+ min-height: {$submit_button_height};
135
+ font-family: {$button_font_family};
136
+ font-weight: {$button_font_weight};
137
+ }
138
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
139
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
140
+ background: {$submit_bg_color};
141
+ border: 1px {$submit_border_color} solid;
142
+ color: {$submit_color};
143
+ min-height: {$submit_button_height};
144
+ font-family: {$button_font_family};
145
+ font-weight: {$button_font_weight};
146
+ }
147
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
148
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
149
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
150
+ .et_pb_module #wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
151
+ color: {$submit_hover_color};
152
+ background-color: {$submit_bg_hover_color};
153
+ border-color: {$submit_border_hover_color};
154
+ }
155
+ .et_pb_module #wcf-embed-checkout-form .woocommerce h3,
156
+ .et_pb_module #wcf-embed-checkout-form .woocommerce h3 span,
157
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
158
+ color: {$section_heading_color};
159
+ font-family: {$heading_font_family};
160
+ font-weight: {$heading_font_weight};
161
+ }
162
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-info::before,
163
+ .et_pb_module #wcf-embed-checkout-form .woocommerce-message::before{
164
+ color: {$primary_color};
165
+ }
166
+ .et_pb_module #wcf-embed-checkout-form {
167
+ font-family: {$base_font_family};
168
+ }
169
+ img.emoji, img.wp-smiley {}";
modules/flow/view/meta-flow-steps.php CHANGED
@@ -1,210 +1,210 @@
1
- <?php
2
- /**
3
- * View Flow steps
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
9
-
10
- $steps = array(
11
- 'landing' => __( 'Landing', 'cartflows' ),
12
- 'checkout' => __( 'Checkout (Woo)', 'cartflows' ),
13
- 'thankyou' => __( 'Thank You (Woo)', 'cartflows' ),
14
- 'upsell' => __( 'Upsell (Woo)', 'cartflows' ),
15
- 'downsell' => __( 'Downsell (Woo)', 'cartflows' ),
16
- 'optin' => __( 'Optin (Woo)', 'cartflows' ),
17
- );
18
-
19
- ?>
20
- <div class="wcf-flow-steps-meta-box">
21
- <div class="wcf-flow-settings">
22
- <?php do_action( 'cartflows_above_flow_steps' ); ?>
23
- <div class="wcf-flow-steps-wrap">
24
- <div class="wcf-flow-steps-container">
25
- <?php if ( is_array( $options['steps'] ) ) { ?>
26
- <?php foreach ( $options['steps'] as $index => $data ) { ?>
27
- <?php
28
- $term_slug = '';
29
- $term_name = '';
30
- $step_wrap_class = '';
31
- $has_product_assigned = true;
32
- $is_global_checkout = '';
33
- $common = '';
34
- $data_step_id = intval( $data['id'] );
35
-
36
- if ( isset( $data['type'] ) ) {
37
- $term_slug = $data['type'];
38
- $term_name = $steps[ $data['type'] ];
39
- }
40
-
41
- if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
42
- $step_wrap_class .= ' invalid-step';
43
- }
44
-
45
- if ( isset( $_GET['highlight-step-id'] ) ) { //phpcs:ignore
46
-
47
- $highlight_step_id = intval( $_GET['highlight-step-id'] ); //phpcs:ignore
48
-
49
- if ( $highlight_step_id === $data_step_id ) {
50
- $step_wrap_class .= ' wcf-new-step-highlight';
51
- }
52
- }
53
-
54
- if ( 'checkout' === $term_slug ) {
55
-
56
- $common = Cartflows_Helper::get_common_settings();
57
-
58
- $is_global_checkout = (int) $common['global_checkout'];
59
-
60
- if ( $data['id'] === $is_global_checkout ) {
61
- $step_wrap_class .= ' wcf-global-checkout';
62
- }
63
- }
64
-
65
- if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
66
-
67
- $has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
68
-
69
- if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
70
- $step_wrap_class .= ' wcf-no-product-step';
71
- }
72
- }
73
-
74
- ?>
75
- <div class="wcf-step-wrap <?php echo $step_wrap_class; ?>" data-id="<?php echo $data['id']; ?>" data-term-slug="<?php echo esc_attr( $term_slug ); ?>">
76
- <div class="wcf-step">
77
- <div class="wcf-step-left-content">
78
- <span class="dashicons dashicons-menu"></span>
79
- <span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
80
- <span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
81
-
82
- <?php
83
- if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
84
- ?>
85
- <span class="wcf-no-product-badge"><?php esc_html_e( 'No Product Assigned', 'cartflows' ); ?></span>
86
- <?php
87
- } elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
88
- ?>
89
- <span class="wcf-global-checkout-badge wcf-error-badge"><?php esc_html_e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
90
- <?php
91
- } elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
92
- ?>
93
- <span class="wcf-global-checkout-badge"><?php esc_html_e( 'Global Checkout', 'cartflows' ); ?></span>
94
- <?php
95
- }
96
- ?>
97
-
98
- <input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
99
- <?php do_action( 'cartflows_step_left_content', $data['id'], $term_slug ); ?>
100
- </div>
101
- <div class="wcf-steps-action-buttons">
102
- <a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'View Step', 'cartflows' ); ?>" >
103
- <span class="dashicons dashicons-visibility"></span>
104
- <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'View', 'cartflows' ); ?></span>
105
- </a>
106
- <a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Edit Step', 'cartflows' ); ?>" >
107
- <span class="dashicons dashicons-edit"></span>
108
- <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Edit', 'cartflows' ); ?></span>
109
- </a>
110
- <?php
111
- if ( _is_cartflows_pro() ) {
112
- ?>
113
- <a href="<?php echo wp_nonce_url( 'admin.php?action=cartflows_clone_step&post=' . $data['id'], 'step_clone', 'step_clone_nonce' ); ?>" class="wcf-step-clone wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
114
- <span class="dashicons dashicons-admin-page"></span>
115
- <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Clone', 'cartflows' ); ?></span>
116
- </a>
117
- <?php } ?>
118
- <a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
119
- <span class="dashicons dashicons-trash"></span>
120
- <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Delete', 'cartflows' ); ?></span>
121
- </a>
122
- </div>
123
- </div>
124
- </div><!-- .wcf-step-wrap -->
125
- <?php } ?>
126
- <?php } ?>
127
- </div><!-- .wcf-flow-steps-container -->
128
- </div> <!-- .wcf-flow-steps-wrap -->
129
- <div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
130
- <?php do_action( 'cartflows_bellow_flow_steps' ); ?>
131
- <div class='wcf-add-new-step-btn-wrap'>
132
- <button class='wcf-trigger-popup button button-primary'>
133
- <?php echo esc_html__( 'Add New Step', 'cartflows' ); ?>
134
- </button>
135
- </div>
136
- </div><!-- .wcf-flow-buttons-wrap -->
137
- </div><!-- .wcf-flow-settings -->
138
-
139
- <div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
140
- <div class="wcf-templates-popup-content">
141
- <div class="spinner"></div>
142
- <div class="wcf-templates-wrap wcf-templates-wrap-flows">
143
-
144
- <div id="wcf-remote-step-actions" class="wcf-template-header">
145
- <div class="wcf-template-logo-wrap">
146
- <span class="wcf-cartflows-logo-img">
147
- <span class="cartflows-logo-icon"></span>
148
- </span>
149
- <span class="wcf-cartflows-title"><?php esc_html_e( 'Steps Library', 'cartflows' ); ?></span>
150
- </div>
151
- <div class="wcf-tab-wrapper">
152
- <?php if ( 'other' !== $default_page_builder ) { ?>
153
- <div id="wcf-get-started-steps">
154
- <ul class="filter-links ">
155
- <li>
156
- <a href="#" class="current" data-slug="ready-templates" data-title="<?php esc_html_e( 'Ready Templates', 'cartflows' ); ?>"><?php esc_html_e( 'Ready Templates', 'cartflows' ); ?></a>
157
- </li>
158
- <li>
159
- <a href="#" data-slug="canvas" data-title="<?php esc_html_e( 'Create Your Own', 'cartflows' ); ?>"><?php esc_html_e( 'Create Your Own', 'cartflows' ); ?></a>
160
- </li>
161
- </ul>
162
- </div>
163
- <?php } ?>
164
- </div>
165
- <div class="wcf-popup-close-wrap">
166
- <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
167
- </div>
168
- </div>
169
-
170
- <!--<div class="wcf-search-form">
171
- <label class="screen-reader-text" for="wp-filter-search-input"><?php esc_html_e( 'Search Sites', 'cartflows' ); ?> </label>
172
- <input placeholder="<?php esc_html_e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
173
- </div>-->
174
-
175
- <div id="wcf-remote-content">
176
- <?php if ( 'other' !== $default_page_builder ) { ?>
177
- <div id="wcf-ready-templates">
178
- <div id="wcf-remote-filters">
179
- <div id="wcf-page-builders"></div>
180
- <div id="wcf-categories"></div>
181
- </div>
182
- <div class="wcf-page-builder-notice"></div>
183
- <div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
184
- <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
185
- </div>
186
- <?php } ?>
187
- <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
188
- <div class="inner">
189
- <div id="wcf-scratch-steps-categories">
190
- <select class="step-type-filter-links filter-links">
191
- <option value="" class="current"> Select Step Type </option>
192
-
193
- <?php foreach ( $steps as $key => $value ) { ?>
194
- <option class="<?php echo $key; ?>" data-slug="<?php echo $key; ?>" data-title="<?php echo $key; ?>"><?php echo $value; ?></option>
195
- <?php } ?>
196
- </select>
197
- </div>
198
- <a href="#" class="button button-primary cartflows-step-import-blank"><?php esc_html_e( 'Create Step', 'cartflows' ); ?></a>
199
- <?php if ( ! _is_cartflows_pro() ) { ?>
200
- <div class="wcf-template-notice"><p><?php echo esc_html__( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
201
- <?php } ?>
202
- <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php esc_html_e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
203
- </div>
204
- </div>
205
- </div>
206
- </div>
207
- </div>
208
- </div><!-- .wcf-templates-popup-overlay -->
209
- </div>
210
- <?php
1
+ <?php
2
+ /**
3
+ * View Flow steps
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
9
+
10
+ $steps = array(
11
+ 'landing' => __( 'Landing', 'cartflows' ),
12
+ 'checkout' => __( 'Checkout (Woo)', 'cartflows' ),
13
+ 'thankyou' => __( 'Thank You (Woo)', 'cartflows' ),
14
+ 'upsell' => __( 'Upsell (Woo)', 'cartflows' ),
15
+ 'downsell' => __( 'Downsell (Woo)', 'cartflows' ),
16
+ 'optin' => __( 'Optin (Woo)', 'cartflows' ),
17
+ );
18
+
19
+ ?>
20
+ <div class="wcf-flow-steps-meta-box">
21
+ <div class="wcf-flow-settings">
22
+ <?php do_action( 'cartflows_above_flow_steps' ); ?>
23
+ <div class="wcf-flow-steps-wrap">
24
+ <div class="wcf-flow-steps-container">
25
+ <?php if ( is_array( $options['steps'] ) ) { ?>
26
+ <?php foreach ( $options['steps'] as $index => $data ) { ?>
27
+ <?php
28
+ $term_slug = '';
29
+ $term_name = '';
30
+ $step_wrap_class = '';
31
+ $has_product_assigned = true;
32
+ $is_global_checkout = '';
33
+ $common = '';
34
+ $data_step_id = intval( $data['id'] );
35
+
36
+ if ( isset( $data['type'] ) ) {
37
+ $term_slug = $data['type'];
38
+ $term_name = $steps[ $data['type'] ];
39
+ }
40
+
41
+ if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
42
+ $step_wrap_class .= ' invalid-step';
43
+ }
44
+
45
+ if ( isset( $_GET['highlight-step-id'] ) ) { //phpcs:ignore
46
+
47
+ $highlight_step_id = intval( $_GET['highlight-step-id'] ); //phpcs:ignore
48
+
49
+ if ( $highlight_step_id === $data_step_id ) {
50
+ $step_wrap_class .= ' wcf-new-step-highlight';
51
+ }
52
+ }
53
+
54
+ if ( 'checkout' === $term_slug ) {
55
+
56
+ $common = Cartflows_Helper::get_common_settings();
57
+
58
+ $is_global_checkout = (int) $common['global_checkout'];
59
+
60
+ if ( $data['id'] === $is_global_checkout ) {
61
+ $step_wrap_class .= ' wcf-global-checkout';
62
+ }
63
+ }
64
+
65
+ if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
66
+
67
+ $has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
68
+
69
+ if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
70
+ $step_wrap_class .= ' wcf-no-product-step';
71
+ }
72
+ }
73
+
74
+ ?>
75
+ <div class="wcf-step-wrap <?php echo $step_wrap_class; ?>" data-id="<?php echo $data['id']; ?>" data-term-slug="<?php echo esc_attr( $term_slug ); ?>">
76
+ <div class="wcf-step">
77
+ <div class="wcf-step-left-content">
78
+ <span class="dashicons dashicons-menu"></span>
79
+ <span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
80
+ <span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
81
+
82
+ <?php
83
+ if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
84
+ ?>
85
+ <span class="wcf-no-product-badge"><?php esc_html_e( 'No Product Assigned', 'cartflows' ); ?></span>
86
+ <?php
87
+ } elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
88
+ ?>
89
+ <span class="wcf-global-checkout-badge wcf-error-badge"><?php esc_html_e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
90
+ <?php
91
+ } elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
92
+ ?>
93
+ <span class="wcf-global-checkout-badge"><?php esc_html_e( 'Global Checkout', 'cartflows' ); ?></span>
94
+ <?php
95
+ }
96
+ ?>
97
+
98
+ <input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
99
+ <?php do_action( 'cartflows_step_left_content', $data['id'], $term_slug ); ?>
100
+ </div>
101
+ <div class="wcf-steps-action-buttons">
102
+ <a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'View Step', 'cartflows' ); ?>" >
103
+ <span class="dashicons dashicons-visibility"></span>
104
+ <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'View', 'cartflows' ); ?></span>
105
+ </a>
106
+ <a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Edit Step', 'cartflows' ); ?>" >
107
+ <span class="dashicons dashicons-edit"></span>
108
+ <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Edit', 'cartflows' ); ?></span>
109
+ </a>
110
+ <?php
111
+ if ( _is_cartflows_pro() ) {
112
+ ?>
113
+ <a href="<?php echo wp_nonce_url( 'admin.php?action=cartflows_clone_step&post=' . $data['id'], 'step_clone', 'step_clone_nonce' ); ?>" class="wcf-step-clone wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
114
+ <span class="dashicons dashicons-admin-page"></span>
115
+ <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Clone', 'cartflows' ); ?></span>
116
+ </a>
117
+ <?php } ?>
118
+ <a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo esc_html__( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
119
+ <span class="dashicons dashicons-trash"></span>
120
+ <span class="wcf-step-act-btn-text"><?php echo esc_html__( 'Delete', 'cartflows' ); ?></span>
121
+ </a>
122
+ </div>
123
+ </div>
124
+ </div><!-- .wcf-step-wrap -->
125
+ <?php } ?>
126
+ <?php } ?>
127
+ </div><!-- .wcf-flow-steps-container -->
128
+ </div> <!-- .wcf-flow-steps-wrap -->
129
+ <div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
130
+ <?php do_action( 'cartflows_bellow_flow_steps' ); ?>
131
+ <div class='wcf-add-new-step-btn-wrap'>
132
+ <button class='wcf-trigger-popup button button-primary'>
133
+ <?php echo esc_html__( 'Add New Step', 'cartflows' ); ?>
134
+ </button>
135
+ </div>
136
+ </div><!-- .wcf-flow-buttons-wrap -->
137
+ </div><!-- .wcf-flow-settings -->
138
+
139
+ <div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
140
+ <div class="wcf-templates-popup-content">
141
+ <div class="spinner"></div>
142
+ <div class="wcf-templates-wrap wcf-templates-wrap-flows">
143
+
144
+ <div id="wcf-remote-step-actions" class="wcf-template-header">
145
+ <div class="wcf-template-logo-wrap">
146
+ <span class="wcf-cartflows-logo-img">
147
+ <span class="cartflows-logo-icon"></span>
148
+ </span>
149
+ <span class="wcf-cartflows-title"><?php esc_html_e( 'Steps Library', 'cartflows' ); ?></span>
150
+ </div>
151
+ <div class="wcf-tab-wrapper">
152
+ <?php if ( 'other' !== $default_page_builder ) { ?>
153
+ <div id="wcf-get-started-steps">
154
+ <ul class="filter-links ">
155
+ <li>
156
+ <a href="#" class="current" data-slug="ready-templates" data-title="<?php esc_html_e( 'Ready Templates', 'cartflows' ); ?>"><?php esc_html_e( 'Ready Templates', 'cartflows' ); ?></a>
157
+ </li>
158
+ <li>
159
+ <a href="#" data-slug="canvas" data-title="<?php esc_html_e( 'Create Your Own', 'cartflows' ); ?>"><?php esc_html_e( 'Create Your Own', 'cartflows' ); ?></a>
160
+ </li>
161
+ </ul>
162
+ </div>
163
+ <?php } ?>
164
+ </div>
165
+ <div class="wcf-popup-close-wrap">
166
+ <span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
167
+ </div>
168
+ </div>
169
+
170
+ <!--<div class="wcf-search-form">
171
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php esc_html_e( 'Search Sites', 'cartflows' ); ?> </label>
172
+ <input placeholder="<?php esc_html_e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
173
+ </div>-->
174
+
175
+ <div id="wcf-remote-content">
176
+ <?php if ( 'other' !== $default_page_builder ) { ?>
177
+ <div id="wcf-ready-templates">
178
+ <div id="wcf-remote-filters">
179
+ <div id="wcf-page-builders"></div>
180
+ <div id="wcf-categories"></div>
181
+ </div>
182
+ <div class="wcf-page-builder-notice"></div>
183
+ <div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"><span class="spinner is-active"></span></div>
184
+ <div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
185
+ </div>
186
+ <?php } ?>
187
+ <div id="wcf-start-from-scratch" style="<?php echo ( 'other' !== $default_page_builder ) ? 'display: none;' : ''; ?>">
188
+ <div class="inner">
189
+ <div id="wcf-scratch-steps-categories">
190
+ <select class="step-type-filter-links filter-links">
191
+ <option value="" class="current"> Select Step Type </option>
192
+
193
+ <?php foreach ( $steps as $key => $value ) { ?>
194
+ <option class="<?php echo $key; ?>" data-slug="<?php echo $key; ?>" data-title="<?php echo $key; ?>"><?php echo $value; ?></option>
195
+ <?php } ?>
196
+ </select>
197
+ </div>
198
+ <a href="#" class="button button-primary cartflows-step-import-blank"><?php esc_html_e( 'Create Step', 'cartflows' ); ?></a>
199
+ <?php if ( ! _is_cartflows_pro() ) { ?>
200
+ <div class="wcf-template-notice"><p><?php echo esc_html__( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
201
+ <?php } ?>
202
+ <p class="wcf-learn-how"><a href="https://cartflows.com/docs/cartflows-step-types/" target="_blank"><?php esc_html_e( 'Learn How', 'cartflows' ); ?> <i class="dashicons dashicons-external"></i></a></p>
203
+ </div>
204
+ </div>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ </div><!-- .wcf-templates-popup-overlay -->
209
+ </div>
210
+ <?php
modules/landing/classes/class-cartflows-landing-markup.php CHANGED
@@ -1,143 +1,143 @@
1
- <?php
2
- /**
3
- * Markup
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Checkout Markup
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Landing_Markup {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var object instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self();
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- add_action( 'pre_get_posts', array( $this, 'wcf_pre_get_posts' ) );
39
- add_action( 'template_redirect', array( $this, 'template_redirect' ) );
40
-
41
- if ( is_admin() ) {
42
- add_filter( 'wp_dropdown_pages', array( $this, 'wp_dropdown_pages' ) );
43
- }
44
- }
45
-
46
- /**
47
- * Add landing pages in WordPress reading section.
48
- *
49
- * @param array $output output.
50
- */
51
- public function wp_dropdown_pages( $output ) {
52
-
53
- global $pagenow;
54
-
55
- if ( ( 'options-reading.php' === $pagenow || 'customize.php' === $pagenow ) && preg_match( '#page_on_front#', $output ) ) {
56
-
57
- $args = array(
58
- 'post_type' => CARTFLOWS_STEP_POST_TYPE,
59
- 'numberposts' => 100,
60
- 'meta_query' => array( //phpcs:ignore
61
- 'relation' => 'OR',
62
- array(
63
- 'key' => 'wcf-step-type',
64
- 'value' => 'landing',
65
- ),
66
- array(
67
- 'key' => 'wcf-step-type',
68
- 'value' => 'checkout',
69
- ),
70
- array(
71
- 'key' => 'wcf-step-type',
72
- 'value' => 'optin',
73
- ),
74
- ),
75
- );
76
-
77
- $landing_pages = get_posts( $args );
78
-
79
- if ( is_array( $landing_pages ) && ! empty( $landing_pages ) ) {
80
-
81
- $cartflows_custom_option = '';
82
-
83
- $front_page_id = get_option( 'page_on_front' );
84
-
85
- foreach ( $landing_pages as $key => $landing_page ) {
86
-
87
- $selected = selected( $front_page_id, $landing_page->ID, false );
88
-
89
- $cartflows_custom_option .= "<option value=\"{$landing_page->ID}\"{$selected}>{$landing_page->post_title} ( #{$landing_page->ID} - CartFlows )</option>";
90
- }
91
-
92
- $cartflows_custom_option .= '</select>';
93
-
94
- $output = str_replace( '</select>', $cartflows_custom_option, $output );
95
- }
96
- }
97
-
98
- return $output;
99
- }
100
-
101
- /**
102
- * Set post query.
103
- *
104
- * @param string $query post query.
105
- */
106
- public function wcf_pre_get_posts( $query ) {
107
-
108
- if ( $query->is_main_query() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
109
-
110
- $post_type = $query->get( 'post_type' );
111
-
112
- $page_id = $query->get( 'page_id' );
113
-
114
- if ( empty( $post_type ) && ! empty( $page_id ) ) {
115
- $query->set( 'post_type', get_post_type( $page_id ) );
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * Redirect to homepage if landing page set as home page.
122
- */
123
- public function template_redirect() {
124
-
125
- $compatibiliy = Cartflows_Compatibility::get_instance();
126
-
127
- // Do not redirect for page builder preview.
128
- if ( $compatibiliy->is_page_builder_preview() ) {
129
- return;
130
- }
131
-
132
- global $post;
133
-
134
- if ( is_singular() && ! is_front_page() && get_option( 'page_on_front' ) == $post->ID ) {
135
- wp_safe_redirect( site_url(), 301 );
136
- }
137
- }
138
- }
139
-
140
- /**
141
- * Kicking this off by calling 'get_instance()' method
142
- */
143
- Cartflows_Landing_Markup::get_instance();
1
+ <?php
2
+ /**
3
+ * Markup
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Checkout Markup
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Landing_Markup {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var object instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self();
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ add_action( 'pre_get_posts', array( $this, 'wcf_pre_get_posts' ) );
39
+ add_action( 'template_redirect', array( $this, 'template_redirect' ) );
40
+
41
+ if ( is_admin() ) {
42
+ add_filter( 'wp_dropdown_pages', array( $this, 'wp_dropdown_pages' ) );
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Add landing pages in WordPress reading section.
48
+ *
49
+ * @param array $output output.
50
+ */
51
+ public function wp_dropdown_pages( $output ) {
52
+
53
+ global $pagenow;
54
+
55
+ if ( ( 'options-reading.php' === $pagenow || 'customize.php' === $pagenow ) && preg_match( '#page_on_front#', $output ) ) {
56
+
57
+ $args = array(
58
+ 'post_type' => CARTFLOWS_STEP_POST_TYPE,
59
+ 'numberposts' => 100,
60
+ 'meta_query' => array( //phpcs:ignore
61
+ 'relation' => 'OR',
62
+ array(
63
+ 'key' => 'wcf-step-type',
64
+ 'value' => 'landing',
65
+ ),
66
+ array(
67
+ 'key' => 'wcf-step-type',
68
+ 'value' => 'checkout',
69
+ ),
70
+ array(
71
+ 'key' => 'wcf-step-type',
72
+ 'value' => 'optin',
73
+ ),
74
+ ),
75
+ );
76
+
77
+ $landing_pages = get_posts( $args );
78
+
79
+ if ( is_array( $landing_pages ) && ! empty( $landing_pages ) ) {
80
+
81
+ $cartflows_custom_option = '';
82
+
83
+ $front_page_id = get_option( 'page_on_front' );
84
+
85
+ foreach ( $landing_pages as $key => $landing_page ) {
86
+
87
+ $selected = selected( $front_page_id, $landing_page->ID, false );
88
+
89
+ $cartflows_custom_option .= "<option value=\"{$landing_page->ID}\"{$selected}>{$landing_page->post_title} ( #{$landing_page->ID} - CartFlows )</option>";
90
+ }
91
+
92
+ $cartflows_custom_option .= '</select>';
93
+
94
+ $output = str_replace( '</select>', $cartflows_custom_option, $output );
95
+ }
96
+ }
97
+
98
+ return $output;
99
+ }
100
+
101
+ /**
102
+ * Set post query.
103
+ *
104
+ * @param string $query post query.
105
+ */
106
+ public function wcf_pre_get_posts( $query ) {
107
+
108
+ if ( $query->is_main_query() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
109
+
110
+ $post_type = $query->get( 'post_type' );
111
+
112
+ $page_id = $query->get( 'page_id' );
113
+
114
+ if ( empty( $post_type ) && ! empty( $page_id ) ) {
115
+ $query->set( 'post_type', get_post_type( $page_id ) );
116
+ }
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Redirect to homepage if landing page set as home page.
122
+ */
123
+ public function template_redirect() {
124
+
125
+ $compatibiliy = Cartflows_Compatibility::get_instance();
126
+
127
+ // Do not redirect for page builder preview.
128
+ if ( $compatibiliy->is_page_builder_preview() ) {
129
+ return;
130
+ }
131
+
132
+ global $post;
133
+
134
+ if ( is_singular() && ! is_front_page() && get_option( 'page_on_front' ) == $post->ID ) {
135
+ wp_safe_redirect( site_url(), 301 );
136
+ }
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Kicking this off by calling 'get_instance()' method
142
+ */
143
+ Cartflows_Landing_Markup::get_instance();
modules/optin/classes/class-cartflows-optin-markup.php CHANGED
@@ -1,802 +1,802 @@
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_Optin_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_optin_fields' ), 10, 2 );
41
-
42
- /* Optin Shortcode */
43
- add_shortcode( 'cartflows_optin', array( $this, 'optin_shortcode_markup' ) );
44
-
45
- /* Preconfigured cart data */
46
- add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
47
-
48
- /* Optin shortcode data */
49
- add_action( 'wp', array( $this, 'shortcode_load_data' ), 1000 );
50
-
51
- /* Ajax Endpoint */
52
- add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ), 10, 2 );
53
- add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
54
-
55
- /* Optin Fields */
56
- add_filter( 'woocommerce_default_address_fields', array( $this, 'set_optin_default_fields' ), 1000 );
57
- /**
58
- * It may required later
59
- * add_filter( 'woocommerce_checkout_fields', array( $this, 'set_optin_fields' ) );
60
- */
61
- add_filter( 'woocommerce_billing_fields', array( $this, 'billing_optin_fields' ), 1000, 2 );
62
-
63
- add_filter( 'woocommerce_checkout_required_field_notice', array( $this, 'change_field_label_in_required_notice' ), 100, 2 );
64
-
65
- $this->elementor_editor_compatibility();
66
- }
67
-
68
- /**
69
- * Elementor editor compatibility.
70
- */
71
- public function elementor_editor_compatibility() {
72
-
73
- if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] && is_admin() ) { //phpcs:ignore
74
-
75
- if ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { //phpcs:ignore
76
-
77
- if ( _wcf_check_is_optin_by_id( intval( $_GET['post'] ) ) ) { //phpcs:ignore
78
-
79
- /* Submit Button */
80
- add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 );
81
- }
82
- }
83
- }
84
- }
85
-
86
- /**
87
- * Change order button text .
88
- *
89
- * @param string $woo_button_text place order.
90
- * @return string
91
- */
92
- public function place_order_button_text( $woo_button_text ) {
93
-
94
- $optin_id = get_the_ID();
95
-
96
- $wcf_order_button_text = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-text' );
97
-
98
- if ( ! empty( $wcf_order_button_text ) ) {
99
- $woo_button_text = $wcf_order_button_text;
100
- }
101
-
102
- return $woo_button_text;
103
- }
104
-
105
- /**
106
- * Display all WooCommerce notices.
107
- *
108
- * @since 1.1.5
109
- */
110
- public function display_woo_notices() {
111
-
112
- if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
113
- woocommerce_output_all_notices();
114
- }
115
- }
116
-
117
- /**
118
- * Check for checkout flag
119
- *
120
- * @param bool $is_checkout is checkout.
121
- *
122
- * @return bool
123
- */
124
- public function woo_checkout_flag( $is_checkout ) {
125
-
126
- if ( ! is_admin() ) {
127
-
128
- if ( _is_wcf_optin_type() ) {
129
-
130
- $is_checkout = true;
131
- }
132
- }
133
-
134
- return $is_checkout;
135
- }
136
-
137
- /**
138
- * Render checkout shortcode markup.
139
- *
140
- * @param array $atts attributes.
141
- * @return string
142
- */
143
- public function optin_shortcode_markup( $atts ) {
144
-
145
- if ( ! function_exists( 'wc_print_notices' ) ) {
146
- $notice_out = '<p class="woocommerce-notice">' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '</p>';
147
- $notice_out .= '<button onClick="location.reload()">' . __( 'Click Here to Reload', 'cartflows' ) . '</button>';
148
-
149
- return $notice_out;
150
- }
151
-
152
- $atts = shortcode_atts(
153
- array(
154
- 'id' => 0,
155
- ),
156
- $atts
157
- );
158
-
159
- $optin_id = intval( $atts['id'] );
160
-
161
- if ( empty( $optin_id ) ) {
162
-
163
- if ( ! _is_wcf_optin_type() ) {
164
-
165
- return '<h4>' . __( 'Please place shortcode on Optin step-type only.', 'cartflows' ) . '</h4>';
166
- }
167
-
168
- global $post;
169
-
170
- $optin_id = intval( $post->ID );
171
- }
172
-
173
- $output = '';
174
-
175
- ob_start();
176
-
177
- do_action( 'cartflows_optin_form_before', $optin_id );
178
-
179
- $optin_layout = 'default';
180
-
181
- $template_default = CARTFLOWS_OPTIN_DIR . 'templates/optin-template-simple.php';
182
-
183
- include $template_default;
184
-
185
- $output .= ob_get_clean();
186
-
187
- return $output;
188
- }
189
-
190
- /**
191
- * Configure Cart Data.
192
- *
193
- * @since 1.0.0
194
- *
195
- * @return void
196
- */
197
- public function preconfigured_cart_data() {
198
-
199
- if ( is_admin() ) {
200
- return;
201
- }
202
-
203
- global $post;
204
-
205
- if ( _is_wcf_optin_type() ) {
206
-
207
- if ( wp_doing_ajax() ) {
208
- return;
209
- } else {
210
-
211
- $optin_id = $post->ID;
212
-
213
- do_action( 'cartflows_optin_before_configure_cart', $optin_id );
214
-
215
- $products = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-optin-product' );
216
-
217
- if ( ! is_array( $products ) ) {
218
- return;
219
- }
220
-
221
- /* Empty the current cart */
222
- WC()->cart->empty_cart();
223
-
224
- if ( is_array( $products ) && count( $products ) < 1 ) {
225
- wc_add_notice( __( 'No product is selected. Please select a Simple, Virtual and Free product from the meta settings.', 'cartflows' ), 'error' );
226
- return;
227
- }
228
-
229
- /* Set customer session if not set */
230
- if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
231
- WC()->session->set_customer_session_cookie( true );
232
- }
233
-
234
- $product_id = reset( $products );
235
- $_product = wc_get_product( $product_id );
236
-
237
- if ( ! empty( $_product ) ) {
238
-
239
- if ( $_product->is_type( 'simple' ) && $_product->is_virtual() ) {
240
-
241
- if ( $_product->get_price() > 0 ) {
242
- wc_add_notice( __( 'Please update the selected product\'s price to zero (0).', 'cartflows' ), 'error' );
243
- } else {
244
-
245
- $quantity = 1;
246
-
247
- WC()->cart->add_to_cart( $product_id, $quantity );
248
- }
249
- } else {
250
-
251
- wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' );
252
- }
253
- } else {
254
-
255
- wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' );
256
- }
257
-
258
- do_action( 'cartflows_optin_after_configure_cart', $optin_id );
259
- }
260
- }
261
- }
262
-
263
- /**
264
- * Load shortcode data.
265
- *
266
- * @return void
267
- */
268
- public function shortcode_load_data() {
269
-
270
- if ( _is_wcf_optin_type() ) {
271
-
272
- add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
273
-
274
- /* Show notices if cart has errors */
275
- add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
276
-
277
- // Outputting the hidden field in checkout page.
278
- add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
279
- add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
280
-
281
- /* Remove unnecessary option */
282
- add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
283
- add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' );
284
-
285
- remove_all_actions( 'woocommerce_before_checkout_form' );
286
- remove_all_actions( 'woocommerce_checkout_billing' );
287
- remove_all_actions( 'woocommerce_checkout_shipping' );
288
- remove_all_actions( 'woocommerce_checkout_before_order_review' );
289
- remove_all_actions( 'woocommerce_checkout_order_review' );
290
- remove_all_actions( 'woocommerce_checkout_after_order_review' );
291
- add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
292
- add_filter( 'woocommerce_available_payment_gateways', array( $this, 'disable_payment_gateways' ) );
293
-
294
- /* Paypal Expresss remove */
295
-
296
- if ( function_exists( 'wc_gateway_ppec' ) ) {
297
- remove_action( 'wp_enqueue_scripts', array( wc_gateway_ppec()->cart, 'enqueue_scripts' ) );
298
- }
299
-
300
- // Hook in actions once.
301
- add_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 );
302
- add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
303
- add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
304
- add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
305
-
306
- /* Submit Button */
307
- add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 );
308
-
309
- add_filter( 'woocommerce_get_terms_and_conditions_checkbox_text', '__return_false' );
310
-
311
- global $post;
312
-
313
- $optin_id = $post->ID;
314
-
315
- do_action( 'cartflows_optin_before_shortcode', $optin_id );
316
- }
317
- }
318
-
319
- /**
320
- * Disable payment gateways.
321
- *
322
- * @param array $available_gateways gateways.
323
- * @return array
324
- */
325
- public function disable_payment_gateways( $available_gateways ) {
326
-
327
- if ( ! is_admin() ) {
328
-
329
- $available_gateways = array();
330
- }
331
-
332
- return $available_gateways;
333
- }
334
-
335
- /**
336
- * Render checkout ID hidden field.
337
- *
338
- * @param array $checkout checkout session data.
339
- * @return void
340
- */
341
- public function checkout_shortcode_post_id( $checkout ) {
342
-
343
- if ( ! _is_wcf_optin_type() ) {
344
- return;
345
- }
346
-
347
- global $post;
348
-
349
- $optin_id = $post->ID;
350
-
351
- $flow_id = get_post_meta( $optin_id, 'wcf-flow-id', true );
352
-
353
- echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
354
- echo '<input type="hidden" class="input-hidden _wcf_optin_id" name="_wcf_optin_id" value="' . intval( $optin_id ) . '">';
355
- }
356
-
357
- /**
358
- * Load shortcode scripts.
359
- *
360
- * @return void
361
- */
362
- public function shortcode_scripts() {
363
-
364
- wp_enqueue_style( 'wcf-optin-template', wcf()->utils->get_css_url( 'optin-template' ), '', CARTFLOWS_VER );
365
-
366
- wp_enqueue_script(
367
- 'wcf-optin-template',
368
- wcf()->utils->get_js_url( 'optin-template' ),
369
- array( 'jquery' ),
370
- CARTFLOWS_VER,
371
- true
372
- );
373
-
374
- do_action( 'cartflows_optin_scripts' );
375
-
376
- $style = $this->generate_style();
377
-
378
- wp_add_inline_style( 'wcf-optin-template', $style );
379
- }
380
-
381
- /**
382
- * Generate styles.
383
- *
384
- * @return string
385
- */
386
- public function generate_style() {
387
-
388
- global $post;
389
-
390
- $optin_id = $post->ID;
391
-
392
- /* Load all fonts */
393
- CartFlows_Font_Families::render_fonts( $optin_id );
394
-
395
- $r = '';
396
- $g = '';
397
- $b = '';
398
- $output = '';
399
-
400
- /* Global */
401
- $primary_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-primary-color' );
402
- $base_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-base-font-family' );
403
-
404
- /* Input Fields */
405
- $input_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-family' );
406
- $input_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-weight' );
407
- $field_input_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-field-size' );
408
- $field_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-tb-padding' );
409
- $field_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-lr-padding' );
410
- $field_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-color' );
411
- $field_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-bg-color' );
412
- $field_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-border-color' );
413
- $field_label_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-label-color' );
414
-
415
- if ( 'custom' == $field_input_size ) {
416
- $field_input_size = '38px';
417
- }
418
-
419
- /* Submit Button */
420
- $submit_button_width = '100%';
421
- $optin_button_position = '';
422
- $button_font_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-font-size' );
423
- $button_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-family' );
424
- $button_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-weight' );
425
- $submit_button_height = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-size' );
426
- $submit_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-tb-padding' );
427
- $submit_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-lr-padding' );
428
- $submit_button_position = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-position' );
429
- $submit_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-color' );
430
- $submit_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-hover-color' );
431
- $submit_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-color', $primary_color );
432
- $submit_bg_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-hover-color', $primary_color );
433
- $submit_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-color', $primary_color );
434
- $submit_border_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-hover-color', $primary_color );
435
-
436
- if ( 'custom' == $submit_button_height ) {
437
- $submit_button_height = '38px';
438
- $submit_button_width = 'auto';
439
-
440
- switch ( $submit_button_position ) {
441
- case 'left':
442
- $optin_button_position = '0 auto 0 0';
443
- break;
444
- case 'center':
445
- $optin_button_position = '0 auto';
446
- break;
447
- case 'right':
448
- $optin_button_position = '0 0 0 auto';
449
- break;
450
-
451
- default:
452
- $optin_button_position = '0 auto';
453
- break;
454
- }
455
-
456
- $output .= ".wcf-optin-form .woocommerce #order_review #payment button{
457
- margin: {$optin_button_position};
458
- }";
459
- }
460
-
461
- $output .= "
462
- .wcf-optin-form .woocommerce #payment input[type=checkbox]:checked:before,
463
- .wcf-optin-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
464
- color: {$primary_color};
465
- }
466
- .wcf-optin-form .woocommerce #payment input[type=radio]:checked:before{
467
- background-color: {$primary_color};
468
- }
469
- .wcf-optin-form .woocommerce #payment input[type=checkbox]:focus,
470
- .wcf-optin-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
471
- .wcf-optin-form .woocommerce #payment input[type=radio]:checked:focus,
472
- .wcf-optin-form .woocommerce #payment input[type=radio]:not(:checked):focus{
473
- border-color: {$primary_color};
474
- box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
475
- }
476
- .wcf-optin-form .woocommerce-checkout label{
477
- color: {$field_label_color};
478
- }
479
-
480
- .wcf-optin-form #order_review .wcf-custom-coupon-field input[type='text'],
481
- .wcf-optin-form .woocommerce form .form-row input.input-text,
482
- .wcf-optin-form .woocommerce form .form-row textarea,
483
- .wcf-optin-form .select2-container--default .select2-selection--single {
484
- color: {$field_color};
485
- background: {$field_bg_color};
486
- border-color: {$field_border_color};
487
- padding-top: {$field_tb_padding}px;
488
- padding-bottom: {$field_tb_padding}px;
489
- padding-left: {$field_lr_padding}px;
490
- padding-right: {$field_lr_padding}px;
491
- min-height: {$field_input_size};
492
- font-family: {$input_font_family};
493
- font-weight: {$input_font_weight};
494
- }
495
-
496
- .wcf-optin-form .woocommerce .col2-set .col-1,
497
- .wcf-optin-form .woocommerce .col2-set .col-2,
498
- .wcf-optin-form .woocommerce-checkout .shop_table,
499
- .wcf-optin-form .woocommerce-checkout #order_review_heading,
500
- .wcf-optin-form .woocommerce-checkout #payment,
501
- .wcf-optin-form .woocommerce form.checkout_coupon {
502
- font-family: {$input_font_family};
503
- font-weight: {$input_font_weight};
504
- }
505
-
506
- .woocommerce table.shop_table th{
507
- color: {$field_label_color};
508
- }
509
-
510
- .wcf-optin-form .woocommerce a{
511
- color: {$primary_color};
512
- }
513
- .wcf-optin-form .select2-container--default .select2-selection--single .select2-selection__rendered {
514
- color: {$field_color};
515
- }
516
- .wcf-optin-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
517
- color: {$field_color};
518
- }
519
- .wcf-optin-form ::-moz-placeholder { /* Firefox 19+ */
520
- color: {$field_color};
521
- }
522
- .wcf-optin-form :-ms-input-placeholder { /* IE 10+ */
523
- color: {$field_color};
524
- }
525
- .wcf-optin-form :-moz-placeholder { /* Firefox 18- */
526
- color: {$field_color};
527
- }
528
- .wcf-optin-form .woocommerce form p.form-row label {
529
- color: {$field_label_color};
530
- font-family: {$input_font_family};
531
- font-weight: {$input_font_weight};
532
- }
533
- .wcf-optin-form .woocommerce #order_review button,
534
- .wcf-optin-form .woocommerce form.woocommerce-form-login .form-row button,
535
- .wcf-optin-form .woocommerce #order_review button.wcf-btn-small {
536
- color: {$submit_color};
537
- background: {$submit_bg_color};
538
- padding-top: {$submit_tb_padding}px;
539
- padding-bottom: {$submit_tb_padding}px;
540
- padding-left: {$submit_lr_padding}px;
541
- padding-right: {$submit_lr_padding}px;
542
- border-color: {$submit_border_color};
543
- min-height: {$submit_button_height};
544
- font-size: {$button_font_size}px;
545
- font-family: {$button_font_family};
546
- font-weight: {$button_font_weight};
547
- width: {$submit_button_width};
548
-
549
- }
550
-
551
- .wcf-optin-form .woocommerce-checkout form.woocommerce-form-login .button,
552
- .wcf-optin-form .woocommerce-checkout form.checkout_coupon .button{
553
- background: {$submit_bg_color};
554
- border: 1px {$submit_border_color} solid;
555
- color: {$submit_color};
556
- min-height: {$submit_button_height};
557
- font-family: {$button_font_family};
558
- font-weight: {$button_font_weight};
559
- }
560
- .wcf-optin-form .woocommerce-checkout form.login .button:hover,
561
- .wcf-optin-form .woocommerce-checkout form.checkout_coupon .button:hover,
562
- .wcf-optin-form .woocommerce #payment #place_order:hover,
563
- .wcf-optin-form .woocommerce #order_review button.wcf-btn-small:hover{
564
- color: {$submit_hover_color};
565
- background-color: {$submit_bg_hover_color};
566
- border-color: {$submit_border_hover_color};
567
- }
568
- .wcf-optin-form .woocommerce-info::before,
569
- .wcf-optin-form .woocommerce-message::before{
570
- color: {$primary_color};
571
- }
572
- .wcf-optin-form{
573
- font-family: {$base_font_family};
574
- }
575
- img.emoji, img.wp-smiley {}";
576
-
577
- return $output;
578
- }
579
-
580
- /**
581
- * Get ajax end points.
582
- *
583
- * @param string $endpoint_url end point URL.
584
- * @param string $request end point request.
585
- * @return string
586
- */
587
- public function get_ajax_endpoint( $endpoint_url, $request ) {
588
-
589
- global $post;
590
-
591
- if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
592
-
593
- if ( _is_wcf_optin_type() ) {
594
-
595
- if ( mb_strpos( $endpoint_url, 'checkout', 0, 'utf-8' ) === false ) {
596
-
597
- if ( '' === $request ) {
598
- $query_args = array(
599
- 'wc-ajax' => '%%endpoint%%',
600
- );
601
- } else {
602
- $query_args = array(
603
- 'wc-ajax' => $request,
604
- );
605
- }
606
-
607
- $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 ); //phpcs:ignore
608
- $uri = $uri[0];
609
-
610
- $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
611
- }
612
- }
613
- }
614
-
615
- return $endpoint_url;
616
- }
617
-
618
-
619
- /**
620
- * Save checkout fields.
621
- *
622
- * @param int $order_id order id.
623
- * @param array $posted posted data.
624
- * @return void
625
- */
626
- public function save_optin_fields( $order_id, $posted ) {
627
-
628
- if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore
629
-
630
- $optin_id = wc_clean( wp_unslash( $_POST['_wcf_optin_id'] ) ); //phpcs:ignore
631
-
632
- update_post_meta( $order_id, '_wcf_optin_id', $optin_id );
633
-
634
- if ( isset( $_POST['_wcf_flow_id'] ) ) { //phpcs:ignore
635
-
636
- $flow_id = wc_clean( wp_unslash( $_POST['_wcf_flow_id'] ) ); //phpcs:ignore
637
-
638
- update_post_meta( $order_id, '_wcf_flow_id', $flow_id );
639
- }
640
- }
641
-
642
- }
643
-
644
- /**
645
- * Redirect users to our checkout if hidden param
646
- *
647
- * @param string $redirect redirect url.
648
- * @param object $user user.
649
- * @return string
650
- */
651
- public function after_login_redirect( $redirect, $user ) {
652
-
653
- if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore
654
-
655
- $optin_id = intval( $_POST['_wcf_optin_id'] ); //phpcs:ignore
656
-
657
- $redirect = get_permalink( $optin_id );
658
- }
659
-
660
- return $redirect;
661
- }
662
-
663
-
664
- /**
665
- * Add custom class to the fields to change the UI to three column.
666
- *
667
- * @param array $fields fields.
668
- */
669
- public function set_optin_default_fields( $fields ) {
670
-
671
- if ( _is_wcf_optin_type() ) {
672
-
673
- global $post;
674
-
675
- $optin_id = $post->ID;
676
- } else {
677
-
678
- if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
679
-
680
- $optin_id = wcf()->utils->get_optin_id_from_post_data();
681
- } else {
682
- return $fields;
683
- }
684
- }
685
-
686
- $first_name = $fields['first_name'];
687
- $last_name = $fields['last_name'];
688
-
689
- /* Make fields required */
690
- $first_name['required'] = true;
691
- $last_name['required'] = true;
692
-
693
- $fields = array(
694
- 'first_name' => $first_name,
695
- 'last_name' => $last_name,
696
- );
697
-
698
- return apply_filters( 'cartflows_optin_default_fields', $fields, $optin_id );
699
- }
700
-
701
- /**
702
- * Add custom class to the fields to change the UI to three column.
703
- *
704
- * @param array $fields fields.
705
- */
706
- public function set_optin_fields( $fields ) {
707
-
708
- if ( _is_wcf_optin_type() ) {
709
-
710
- global $post;
711
-
712
- $optin_id = $post->ID;
713
- } else {
714
-
715
- if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
716
-
717
- $optin_id = wcf()->utils->get_optin_id_from_post_data();
718
- } else {
719
- return $fields;
720
- }
721
- }
722
-
723
- $billing_first_name = $fields['billing']['billing_first_name'];
724
- $billing_last_name = $fields['billing']['billing_last_name'];
725
- $billing_email = $fields['billing']['billing_email'];
726
-
727
- $fields['billing'] = array(
728
- 'billing_first_name' => $billing_first_name,
729
- 'billing_last_name' => $billing_last_name,
730
- 'billing_email' => $billing_email,
731
- );
732
-
733
- return apply_filters( 'cartflows_optin_fields', $fields, $optin_id );
734
- }
735
-
736
- /**
737
- * Billing field customization.
738
- *
739
- * @param array $fields fields data.
740
- * @param string $country country name.
741
- * @return array
742
- */
743
- public function billing_optin_fields( $fields, $country ) {
744
-
745
- if ( _is_wcf_optin_type() ) {
746
-
747
- global $post;
748
-
749
- $optin_id = $post->ID;
750
- } else {
751
-
752
- if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
753
- $optin_id = wcf()->utils->get_optin_id_from_post_data();
754
- } else {
755
- return $fields;
756
- }
757
- }
758
-
759
- if ( is_wc_endpoint_url( 'edit-address' ) ) {
760
- return $fields;
761
- }
762
-
763
- $billing_first_name = $fields['billing_first_name'];
764
- $billing_last_name = $fields['billing_last_name'];
765
- $billing_email = $fields['billing_email'];
766
-
767
- /* Make fields required */
768
- $billing_first_name['required'] = true;
769
- $billing_last_name['required'] = true;
770
-
771
- $fields = array(
772
- 'billing_first_name' => $billing_first_name,
773
- 'billing_last_name' => $billing_last_name,
774
- 'billing_email' => $billing_email,
775
- );
776
-
777
- return apply_filters( 'cartflows_billing_optin_fields', $fields, $country, $optin_id );
778
- }
779
-
780
-
781
- /**
782
- * Replace billing label.
783
- *
784
- * @param string $notice Notice.
785
- * @param string $field_label Field name.
786
- * @return string
787
- */
788
- public function change_field_label_in_required_notice( $notice, $field_label ) {
789
-
790
- if ( _is_wcf_doing_optin_ajax() ) {
791
-
792
- $notice = str_replace( 'Billing ', '', $notice );
793
- }
794
-
795
- return $notice;
796
- }
797
- }
798
-
799
- /**
800
- * Kicking this off by calling 'get_instance()' method
801
- */
802
- Cartflows_Optin_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_Optin_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_optin_fields' ), 10, 2 );
41
+
42
+ /* Optin Shortcode */
43
+ add_shortcode( 'cartflows_optin', array( $this, 'optin_shortcode_markup' ) );
44
+
45
+ /* Preconfigured cart data */
46
+ add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
47
+
48
+ /* Optin shortcode data */
49
+ add_action( 'wp', array( $this, 'shortcode_load_data' ), 1000 );
50
+
51
+ /* Ajax Endpoint */
52
+ add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ), 10, 2 );
53
+ add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
54
+
55
+ /* Optin Fields */
56
+ add_filter( 'woocommerce_default_address_fields', array( $this, 'set_optin_default_fields' ), 1000 );
57
+ /**
58
+ * It may required later
59
+ * add_filter( 'woocommerce_checkout_fields', array( $this, 'set_optin_fields' ) );
60
+ */
61
+ add_filter( 'woocommerce_billing_fields', array( $this, 'billing_optin_fields' ), 1000, 2 );
62
+
63
+ add_filter( 'woocommerce_checkout_required_field_notice', array( $this, 'change_field_label_in_required_notice' ), 100, 2 );
64
+
65
+ $this->elementor_editor_compatibility();
66
+ }
67
+
68
+ /**
69
+ * Elementor editor compatibility.
70
+ */
71
+ public function elementor_editor_compatibility() {
72
+
73
+ if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] && is_admin() ) { //phpcs:ignore
74
+
75
+ if ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { //phpcs:ignore
76
+
77
+ if ( _wcf_check_is_optin_by_id( intval( $_GET['post'] ) ) ) { //phpcs:ignore
78
+
79
+ /* Submit Button */
80
+ add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 );
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Change order button text .
88
+ *
89
+ * @param string $woo_button_text place order.
90
+ * @return string
91
+ */
92
+ public function place_order_button_text( $woo_button_text ) {
93
+
94
+ $optin_id = get_the_ID();
95
+
96
+ $wcf_order_button_text = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-text' );
97
+
98
+ if ( ! empty( $wcf_order_button_text ) ) {
99
+ $woo_button_text = $wcf_order_button_text;
100
+ }
101
+
102
+ return $woo_button_text;
103
+ }
104
+
105
+ /**
106
+ * Display all WooCommerce notices.
107
+ *
108
+ * @since 1.1.5
109
+ */
110
+ public function display_woo_notices() {
111
+
112
+ if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
113
+ woocommerce_output_all_notices();
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Check for checkout flag
119
+ *
120
+ * @param bool $is_checkout is checkout.
121
+ *
122
+ * @return bool
123
+ */
124
+ public function woo_checkout_flag( $is_checkout ) {
125
+
126
+ if ( ! is_admin() ) {
127
+
128
+ if ( _is_wcf_optin_type() ) {
129
+
130
+ $is_checkout = true;
131
+ }
132
+ }
133
+
134
+ return $is_checkout;
135
+ }
136
+
137
+ /**
138
+ * Render checkout shortcode markup.
139
+ *
140
+ * @param array $atts attributes.
141
+ * @return string
142
+ */
143
+ public function optin_shortcode_markup( $atts ) {
144
+
145
+ if ( ! function_exists( 'wc_print_notices' ) ) {
146
+ $notice_out = '<p class="woocommerce-notice">' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '</p>';
147
+ $notice_out .= '<button onClick="location.reload()">' . __( 'Click Here to Reload', 'cartflows' ) . '</button>';
148
+
149
+ return $notice_out;
150
+ }
151
+
152
+ $atts = shortcode_atts(
153
+ array(
154
+ 'id' => 0,
155
+ ),
156
+ $atts
157
+ );
158
+
159
+ $optin_id = intval( $atts['id'] );
160
+
161
+ if ( empty( $optin_id ) ) {
162
+
163
+ if ( ! _is_wcf_optin_type() ) {
164
+
165
+ return '<h4>' . __( 'Please place shortcode on Optin step-type only.', 'cartflows' ) . '</h4>';
166
+ }
167
+
168
+ global $post;
169
+
170
+ $optin_id = intval( $post->ID );
171
+ }
172
+
173
+ $output = '';
174
+
175
+ ob_start();
176
+
177
+ do_action( 'cartflows_optin_form_before', $optin_id );
178
+
179
+ $optin_layout = 'default';
180
+
181
+ $template_default = CARTFLOWS_OPTIN_DIR . 'templates/optin-template-simple.php';
182
+
183
+ include $template_default;
184
+
185
+ $output .= ob_get_clean();
186
+
187
+ return $output;
188
+ }
189
+
190
+ /**
191
+ * Configure Cart Data.
192
+ *
193
+ * @since 1.0.0
194
+ *
195
+ * @return void
196
+ */
197
+ public function preconfigured_cart_data() {
198
+
199
+ if ( is_admin() ) {
200
+ return;
201
+ }
202
+
203
+ global $post;
204
+
205
+ if ( _is_wcf_optin_type() ) {
206
+
207
+ if ( wp_doing_ajax() ) {
208
+ return;
209
+ } else {
210
+
211
+ $optin_id = $post->ID;
212
+
213
+ do_action( 'cartflows_optin_before_configure_cart', $optin_id );
214
+
215
+ $products = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-optin-product' );
216
+
217
+ if ( ! is_array( $products ) ) {
218
+ return;
219
+ }
220
+
221
+ /* Empty the current cart */
222
+ WC()->cart->empty_cart();
223
+
224
+ if ( is_array( $products ) && count( $products ) < 1 ) {
225
+ wc_add_notice( __( 'No product is selected. Please select a Simple, Virtual and Free product from the meta settings.', 'cartflows' ), 'error' );
226
+ return;
227
+ }
228
+
229
+ /* Set customer session if not set */
230
+ if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
231
+ WC()->session->set_customer_session_cookie( true );
232
+ }
233
+
234
+ $product_id = reset( $products );
235
+ $_product = wc_get_product( $product_id );
236
+
237
+ if ( ! empty( $_product ) ) {
238
+
239
+ if ( $_product->is_type( 'simple' ) && $_product->is_virtual() ) {
240
+
241
+ if ( $_product->get_price() > 0 ) {
242
+ wc_add_notice( __( 'Please update the selected product\'s price to zero (0).', 'cartflows' ), 'error' );
243
+ } else {
244
+
245
+ $quantity = 1;
246
+
247
+ WC()->cart->add_to_cart( $product_id, $quantity );
248
+ }
249
+ } else {
250
+
251
+ wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' );
252
+ }
253
+ } else {
254
+
255
+ wc_add_notice( __( 'Please select a Simple, Virtual and Free product.', 'cartflows' ), 'error' );
256
+ }
257
+
258
+ do_action( 'cartflows_optin_after_configure_cart', $optin_id );
259
+ }
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Load shortcode data.
265
+ *
266
+ * @return void
267
+ */
268
+ public function shortcode_load_data() {
269
+
270
+ if ( _is_wcf_optin_type() ) {
271
+
272
+ add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
273
+
274
+ /* Show notices if cart has errors */
275
+ add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
276
+
277
+ // Outputting the hidden field in checkout page.
278
+ add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
279
+ add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
280
+
281
+ /* Remove unnecessary option */
282
+ add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
283
+ add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' );
284
+
285
+ remove_all_actions( 'woocommerce_before_checkout_form' );
286
+ remove_all_actions( 'woocommerce_checkout_billing' );
287
+ remove_all_actions( 'woocommerce_checkout_shipping' );
288
+ remove_all_actions( 'woocommerce_checkout_before_order_review' );
289
+ remove_all_actions( 'woocommerce_checkout_order_review' );
290
+ remove_all_actions( 'woocommerce_checkout_after_order_review' );
291
+ add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
292
+ add_filter( 'woocommerce_available_payment_gateways', array( $this, 'disable_payment_gateways' ) );
293
+
294
+ /* Paypal Expresss remove */
295
+
296
+ if ( function_exists( 'wc_gateway_ppec' ) ) {
297
+ remove_action( 'wp_enqueue_scripts', array( wc_gateway_ppec()->cart, 'enqueue_scripts' ) );
298
+ }
299
+
300
+ // Hook in actions once.
301
+ add_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 );
302
+ add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
303
+ add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
304
+ add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
305
+
306
+ /* Submit Button */
307
+ add_filter( 'woocommerce_order_button_text', array( $this, 'place_order_button_text' ), 10, 1 );
308
+
309
+ add_filter( 'woocommerce_get_terms_and_conditions_checkbox_text', '__return_false' );
310
+
311
+ global $post;
312
+
313
+ $optin_id = $post->ID;
314
+
315
+ do_action( 'cartflows_optin_before_shortcode', $optin_id );
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Disable payment gateways.
321
+ *
322
+ * @param array $available_gateways gateways.
323
+ * @return array
324
+ */
325
+ public function disable_payment_gateways( $available_gateways ) {
326
+
327
+ if ( ! is_admin() ) {
328
+
329
+ $available_gateways = array();
330
+ }
331
+
332
+ return $available_gateways;
333
+ }
334
+
335
+ /**
336
+ * Render checkout ID hidden field.
337
+ *
338
+ * @param array $checkout checkout session data.
339
+ * @return void
340
+ */
341
+ public function checkout_shortcode_post_id( $checkout ) {
342
+
343
+ if ( ! _is_wcf_optin_type() ) {
344
+ return;
345
+ }
346
+
347
+ global $post;
348
+
349
+ $optin_id = $post->ID;
350
+
351
+ $flow_id = get_post_meta( $optin_id, 'wcf-flow-id', true );
352
+
353
+ echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
354
+ echo '<input type="hidden" class="input-hidden _wcf_optin_id" name="_wcf_optin_id" value="' . intval( $optin_id ) . '">';
355
+ }
356
+
357
+ /**
358
+ * Load shortcode scripts.
359
+ *
360
+ * @return void
361
+ */
362
+ public function shortcode_scripts() {
363
+
364
+ wp_enqueue_style( 'wcf-optin-template', wcf()->utils->get_css_url( 'optin-template' ), '', CARTFLOWS_VER );
365
+
366
+ wp_enqueue_script(
367
+ 'wcf-optin-template',
368
+ wcf()->utils->get_js_url( 'optin-template' ),
369
+ array( 'jquery' ),
370
+ CARTFLOWS_VER,
371
+ true
372
+ );
373
+
374
+ do_action( 'cartflows_optin_scripts' );
375
+
376
+ $style = $this->generate_style();
377
+
378
+ wp_add_inline_style( 'wcf-optin-template', $style );
379
+ }
380
+
381
+ /**
382
+ * Generate styles.
383
+ *
384
+ * @return string
385
+ */
386
+ public function generate_style() {
387
+
388
+ global $post;
389
+
390
+ $optin_id = $post->ID;
391
+
392
+ /* Load all fonts */
393
+ CartFlows_Font_Families::render_fonts( $optin_id );
394
+
395
+ $r = '';
396
+ $g = '';
397
+ $b = '';
398
+ $output = '';
399
+
400
+ /* Global */
401
+ $primary_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-primary-color' );
402
+ $base_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-base-font-family' );
403
+
404
+ /* Input Fields */
405
+ $input_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-family' );
406
+ $input_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-font-weight' );
407
+ $field_input_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-input-field-size' );
408
+ $field_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-tb-padding' );
409
+ $field_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-lr-padding' );
410
+ $field_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-color' );
411
+ $field_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-bg-color' );
412
+ $field_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-border-color' );
413
+ $field_label_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-field-label-color' );
414
+
415
+ if ( 'custom' == $field_input_size ) {
416
+ $field_input_size = '38px';
417
+ }
418
+
419
+ /* Submit Button */
420
+ $submit_button_width = '100%';
421
+ $optin_button_position = '';
422
+ $button_font_size = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-font-size' );
423
+ $button_font_family = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-family' );
424
+ $button_font_weight = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-button-font-weight' );
425
+ $submit_button_height = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-size' );
426
+ $submit_tb_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-tb-padding' );
427
+ $submit_lr_padding = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-lr-padding' );
428
+ $submit_button_position = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-position' );
429
+ $submit_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-color' );
430
+ $submit_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-hover-color' );
431
+ $submit_bg_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-color', $primary_color );
432
+ $submit_bg_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-bg-hover-color', $primary_color );
433
+ $submit_border_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-color', $primary_color );
434
+ $submit_border_hover_color = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-border-hover-color', $primary_color );
435
+
436
+ if ( 'custom' == $submit_button_height ) {
437
+ $submit_button_height = '38px';
438
+ $submit_button_width = 'auto';
439
+
440
+ switch ( $submit_button_position ) {
441
+ case 'left':
442
+ $optin_button_position = '0 auto 0 0';
443
+ break;
444
+ case 'center':
445
+ $optin_button_position = '0 auto';
446
+ break;
447
+ case 'right':
448
+ $optin_button_position = '0 0 0 auto';
449
+ break;
450
+
451
+ default:
452
+ $optin_button_position = '0 auto';
453
+ break;
454
+ }
455
+
456
+ $output .= ".wcf-optin-form .woocommerce #order_review #payment button{
457
+ margin: {$optin_button_position};
458
+ }";
459
+ }
460
+
461
+ $output .= "
462
+ .wcf-optin-form .woocommerce #payment input[type=checkbox]:checked:before,
463
+ .wcf-optin-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
464
+ color: {$primary_color};
465
+ }
466
+ .wcf-optin-form .woocommerce #payment input[type=radio]:checked:before{
467
+ background-color: {$primary_color};
468
+ }
469
+ .wcf-optin-form .woocommerce #payment input[type=checkbox]:focus,
470
+ .wcf-optin-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
471
+ .wcf-optin-form .woocommerce #payment input[type=radio]:checked:focus,
472
+ .wcf-optin-form .woocommerce #payment input[type=radio]:not(:checked):focus{
473
+ border-color: {$primary_color};
474
+ box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
475
+ }
476
+ .wcf-optin-form .woocommerce-checkout label{
477
+ color: {$field_label_color};
478
+ }
479
+
480
+ .wcf-optin-form #order_review .wcf-custom-coupon-field input[type='text'],
481
+ .wcf-optin-form .woocommerce form .form-row input.input-text,
482
+ .wcf-optin-form .woocommerce form .form-row textarea,
483
+ .wcf-optin-form .select2-container--default .select2-selection--single {
484
+ color: {$field_color};
485
+ background: {$field_bg_color};
486
+ border-color: {$field_border_color};
487
+ padding-top: {$field_tb_padding}px;
488
+ padding-bottom: {$field_tb_padding}px;
489
+ padding-left: {$field_lr_padding}px;
490
+ padding-right: {$field_lr_padding}px;
491
+ min-height: {$field_input_size};
492
+ font-family: {$input_font_family};
493
+ font-weight: {$input_font_weight};
494
+ }
495
+
496
+ .wcf-optin-form .woocommerce .col2-set .col-1,
497
+ .wcf-optin-form .woocommerce .col2-set .col-2,
498
+ .wcf-optin-form .woocommerce-checkout .shop_table,
499
+ .wcf-optin-form .woocommerce-checkout #order_review_heading,
500
+ .wcf-optin-form .woocommerce-checkout #payment,
501
+ .wcf-optin-form .woocommerce form.checkout_coupon {
502
+ font-family: {$input_font_family};
503
+ font-weight: {$input_font_weight};
504
+ }
505
+
506
+ .woocommerce table.shop_table th{
507
+ color: {$field_label_color};
508
+ }
509
+
510
+ .wcf-optin-form .woocommerce a{
511
+ color: {$primary_color};
512
+ }
513
+ .wcf-optin-form .select2-container--default .select2-selection--single .select2-selection__rendered {
514
+ color: {$field_color};
515
+ }
516
+ .wcf-optin-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
517
+ color: {$field_color};
518
+ }
519
+ .wcf-optin-form ::-moz-placeholder { /* Firefox 19+ */
520
+ color: {$field_color};
521
+ }
522
+ .wcf-optin-form :-ms-input-placeholder { /* IE 10+ */
523
+ color: {$field_color};
524
+ }
525
+ .wcf-optin-form :-moz-placeholder { /* Firefox 18- */
526
+ color: {$field_color};
527
+ }
528
+ .wcf-optin-form .woocommerce form p.form-row label {
529
+ color: {$field_label_color};
530
+ font-family: {$input_font_family};
531
+ font-weight: {$input_font_weight};
532
+ }
533
+ .wcf-optin-form .woocommerce #order_review button,
534
+ .wcf-optin-form .woocommerce form.woocommerce-form-login .form-row button,
535
+ .wcf-optin-form .woocommerce #order_review button.wcf-btn-small {
536
+ color: {$submit_color};
537
+ background: {$submit_bg_color};
538
+ padding-top: {$submit_tb_padding}px;
539
+ padding-bottom: {$submit_tb_padding}px;
540
+ padding-left: {$submit_lr_padding}px;
541
+ padding-right: {$submit_lr_padding}px;
542
+ border-color: {$submit_border_color};
543
+ min-height: {$submit_button_height};
544
+ font-size: {$button_font_size}px;
545
+ font-family: {$button_font_family};
546
+ font-weight: {$button_font_weight};
547
+ width: {$submit_button_width};
548
+
549
+ }
550
+
551
+ .wcf-optin-form .woocommerce-checkout form.woocommerce-form-login .button,
552
+ .wcf-optin-form .woocommerce-checkout form.checkout_coupon .button{
553
+ background: {$submit_bg_color};
554
+ border: 1px {$submit_border_color} solid;
555
+ color: {$submit_color};
556
+ min-height: {$submit_button_height};
557
+ font-family: {$button_font_family};
558
+ font-weight: {$button_font_weight};
559
+ }
560
+ .wcf-optin-form .woocommerce-checkout form.login .button:hover,
561
+ .wcf-optin-form .woocommerce-checkout form.checkout_coupon .button:hover,
562
+ .wcf-optin-form .woocommerce #payment #place_order:hover,
563
+ .wcf-optin-form .woocommerce #order_review button.wcf-btn-small:hover{
564
+ color: {$submit_hover_color};
565
+ background-color: {$submit_bg_hover_color};
566
+ border-color: {$submit_border_hover_color};
567
+ }
568
+ .wcf-optin-form .woocommerce-info::before,
569
+ .wcf-optin-form .woocommerce-message::before{
570
+ color: {$primary_color};
571
+ }
572
+ .wcf-optin-form{
573
+ font-family: {$base_font_family};
574
+ }
575
+ img.emoji, img.wp-smiley {}";
576
+
577
+ return $output;
578
+ }
579
+
580
+ /**
581
+ * Get ajax end points.
582
+ *
583
+ * @param string $endpoint_url end point URL.
584
+ * @param string $request end point request.
585
+ * @return string
586
+ */
587
+ public function get_ajax_endpoint( $endpoint_url, $request ) {
588
+
589
+ global $post;
590
+
591
+ if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
592
+
593
+ if ( _is_wcf_optin_type() ) {
594
+
595
+ if ( mb_strpos( $endpoint_url, 'checkout', 0, 'utf-8' ) === false ) {
596
+
597
+ if ( '' === $request ) {
598
+ $query_args = array(
599
+ 'wc-ajax' => '%%endpoint%%',
600
+ );
601
+ } else {
602
+ $query_args = array(
603
+ 'wc-ajax' => $request,
604
+ );
605
+ }
606
+
607
+ $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 ); //phpcs:ignore
608
+ $uri = $uri[0];
609
+
610
+ $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
611
+ }
612
+ }
613
+ }
614
+
615
+ return $endpoint_url;
616
+ }
617
+
618
+
619
+ /**
620
+ * Save checkout fields.
621
+ *
622
+ * @param int $order_id order id.
623
+ * @param array $posted posted data.
624
+ * @return void
625
+ */
626
+ public function save_optin_fields( $order_id, $posted ) {
627
+
628
+ if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore
629
+
630
+ $optin_id = wc_clean( wp_unslash( $_POST['_wcf_optin_id'] ) ); //phpcs:ignore
631
+
632
+ update_post_meta( $order_id, '_wcf_optin_id', $optin_id );
633
+
634
+ if ( isset( $_POST['_wcf_flow_id'] ) ) { //phpcs:ignore
635
+
636
+ $flow_id = wc_clean( wp_unslash( $_POST['_wcf_flow_id'] ) ); //phpcs:ignore
637
+
638
+ update_post_meta( $order_id, '_wcf_flow_id', $flow_id );
639
+ }
640
+ }
641
+
642
+ }
643
+
644
+ /**
645
+ * Redirect users to our checkout if hidden param
646
+ *
647
+ * @param string $redirect redirect url.
648
+ * @param object $user user.
649
+ * @return string
650
+ */
651
+ public function after_login_redirect( $redirect, $user ) {
652
+
653
+ if ( isset( $_POST['_wcf_optin_id'] ) ) { //phpcs:ignore
654
+
655
+ $optin_id = intval( $_POST['_wcf_optin_id'] ); //phpcs:ignore
656
+
657
+ $redirect = get_permalink( $optin_id );
658
+ }
659
+
660
+ return $redirect;
661
+ }
662
+
663
+
664
+ /**
665
+ * Add custom class to the fields to change the UI to three column.
666
+ *
667
+ * @param array $fields fields.
668
+ */
669
+ public function set_optin_default_fields( $fields ) {
670
+
671
+ if ( _is_wcf_optin_type() ) {
672
+
673
+ global $post;
674
+
675
+ $optin_id = $post->ID;
676
+ } else {
677
+
678
+ if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
679
+
680
+ $optin_id = wcf()->utils->get_optin_id_from_post_data();
681
+ } else {
682
+ return $fields;
683
+ }
684
+ }
685
+
686
+ $first_name = $fields['first_name'];
687
+ $last_name = $fields['last_name'];
688
+
689
+ /* Make fields required */
690
+ $first_name['required'] = true;
691
+ $last_name['required'] = true;
692
+
693
+ $fields = array(
694
+ 'first_name' => $first_name,
695
+ 'last_name' => $last_name,
696
+ );
697
+
698
+ return apply_filters( 'cartflows_optin_default_fields', $fields, $optin_id );
699
+ }
700
+
701
+ /**
702
+ * Add custom class to the fields to change the UI to three column.
703
+ *
704
+ * @param array $fields fields.
705
+ */
706
+ public function set_optin_fields( $fields ) {
707
+
708
+ if ( _is_wcf_optin_type() ) {
709
+
710
+ global $post;
711
+
712
+ $optin_id = $post->ID;
713
+ } else {
714
+
715
+ if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
716
+
717
+ $optin_id = wcf()->utils->get_optin_id_from_post_data();
718
+ } else {
719
+ return $fields;
720
+ }
721
+ }
722
+
723
+ $billing_first_name = $fields['billing']['billing_first_name'];
724
+ $billing_last_name = $fields['billing']['billing_last_name'];
725
+ $billing_email = $fields['billing']['billing_email'];
726
+
727
+ $fields['billing'] = array(
728
+ 'billing_first_name' => $billing_first_name,
729
+ 'billing_last_name' => $billing_last_name,
730
+ 'billing_email' => $billing_email,
731
+ );
732
+
733
+ return apply_filters( 'cartflows_optin_fields', $fields, $optin_id );
734
+ }
735
+
736
+ /**
737
+ * Billing field customization.
738
+ *
739
+ * @param array $fields fields data.
740
+ * @param string $country country name.
741
+ * @return array
742
+ */
743
+ public function billing_optin_fields( $fields, $country ) {
744
+
745
+ if ( _is_wcf_optin_type() ) {
746
+
747
+ global $post;
748
+
749
+ $optin_id = $post->ID;
750
+ } else {
751
+
752
+ if ( _is_wcf_doing_optin_ajax() && wcf()->utils->get_optin_id_from_post_data() ) {
753
+ $optin_id = wcf()->utils->get_optin_id_from_post_data();
754
+ } else {
755
+ return $fields;
756
+ }
757
+ }
758
+
759
+ if ( is_wc_endpoint_url( 'edit-address' ) ) {
760
+ return $fields;
761
+ }
762
+
763
+ $billing_first_name = $fields['billing_first_name'];
764
+ $billing_last_name = $fields['billing_last_name'];
765
+ $billing_email = $fields['billing_email'];
766
+
767
+ /* Make fields required */
768
+ $billing_first_name['required'] = true;
769
+ $billing_last_name['required'] = true;
770
+
771
+ $fields = array(
772
+ 'billing_first_name' => $billing_first_name,
773
+ 'billing_last_name' => $billing_last_name,
774
+ 'billing_email' => $billing_email,
775
+ );
776
+
777
+ return apply_filters( 'cartflows_billing_optin_fields', $fields, $country, $optin_id );
778
+ }
779
+
780
+
781
+ /**
782
+ * Replace billing label.
783
+ *
784
+ * @param string $notice Notice.
785
+ * @param string $field_label Field name.
786
+ * @return string
787
+ */
788
+ public function change_field_label_in_required_notice( $notice, $field_label ) {
789
+
790
+ if ( _is_wcf_doing_optin_ajax() ) {
791
+
792
+ $notice = str_replace( 'Billing ', '', $notice );
793
+ }
794
+
795
+ return $notice;
796
+ }
797
+ }
798
+
799
+ /**
800
+ * Kicking this off by calling 'get_instance()' method
801
+ */
802
+ Cartflows_Optin_Markup::get_instance();
modules/optin/classes/class-cartflows-optin-meta.php CHANGED
@@ -1,672 +1,672 @@
1
- <?php
2
- /**
3
- * Checkout post meta
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Meta Boxes setup
10
- */
11
- class Cartflows_Optin_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
- * 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
- public function setup_meta_box() {
61
-
62
- if ( _is_wcf_optin_type() ) {
63
- add_meta_box(
64
- 'wcf-optin-settings', // Id.
65
- __( 'Optin 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
- public function markup_meta_box( $post ) {
81
-
82
- wp_nonce_field( 'save-nonce-optin-step-meta', 'nonce-optin-step-meta' );
83
-
84
- $stored = get_post_meta( $post->ID );
85
-
86
- $optin_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, $optin_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
- $optin_meta = array();
100
-
101
- foreach ( $meta as $key => $value ) {
102
- $optin_meta[ $key ] = $meta[ $key ]['default'];
103
- }
104
-
105
- do_action( 'wcf_optin_settings_markup_before' );
106
- $this->tabs_markup( $optin_meta, $post->ID );
107
- do_action( 'wcf_optin_settings_markup_after' );
108
- }
109
-
110
- /**
111
- * Page Header Tabs
112
- *
113
- * @param array $options options.
114
- * @param int $post_id post ID.
115
- */
116
- public function tabs_markup( $options, $post_id ) {
117
-
118
- $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
119
-
120
- if ( empty( $active_tab ) ) {
121
- $active_tab = 'wcf-optin-shortcodes';
122
- }
123
-
124
- $tab_array = array(
125
- array(
126
- 'title' => __( 'Shortcodes', 'cartflows' ),
127
- 'id' => 'wcf-optin-shortcodes',
128
- 'class' => 'wcf-optin-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
129
- 'icon' => 'dashicons-editor-code',
130
- ),
131
- array(
132
- 'title' => __( 'Select Product', 'cartflows' ),
133
- 'id' => 'wcf-optin-general',
134
- 'class' => 'wcf-optin-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
135
- 'icon' => 'dashicons-info',
136
- ),
137
- array(
138
- 'title' => __( 'Design', 'cartflows' ),
139
- 'id' => 'wcf-optin-style',
140
- 'class' => 'wcf-optin-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
141
- 'icon' => 'dashicons-admin-customizer',
142
- ),
143
- array(
144
- 'title' => __( 'Form Fields', 'cartflows' ),
145
- 'id' => 'wcf-optin-custom-fields',
146
- 'class' => 'wcf-optin-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
147
- 'icon' => 'dashicons-welcome-widgets-menus',
148
- ),
149
- array(
150
- 'title' => __( 'Settings', 'cartflows' ),
151
- 'id' => 'wcf-optin-custom-settings',
152
- 'class' => 'wcf-optin-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
153
- 'icon' => 'dashicons-admin-generic',
154
- ),
155
- array(
156
- 'title' => __( 'Custom Script', 'cartflows' ),
157
- 'id' => 'wcf-optin-custom-script-header',
158
- 'class' => 'wcf-optin-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
159
- 'icon' => 'dashicons-format-aside',
160
- ),
161
- );
162
-
163
- $tabs = $tab_array;
164
-
165
- ?>
166
- <div class="wcf-optin-table wcf-metabox-wrap widefat">
167
- <div class="wcf-table-container">
168
- <div class="wcf-column-left">
169
- <div class="wcf-tab-wrapper">
170
-
171
- <?php foreach ( $tabs as $key => $tab ) { ?>
172
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
173
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
174
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
175
- </div>
176
- <?php } ?>
177
-
178
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
179
- </div>
180
- </div>
181
- <div class="wcf-column-right">
182
- <?php $this->tab_shortcodes( $options, $post_id ); ?>
183
- <?php $this->tab_general( $options, $post_id ); ?>
184
- <?php $this->tab_style( $options, $post_id ); ?>
185
- <?php $this->tab_custom_fields( $options, $post_id ); ?>
186
- <?php $this->tab_custom_settings( $options, $post_id ); ?>
187
- <?php $this->tab_custom_script( $options, $post_id ); ?>
188
- <?php $this->right_column_footer( $options, $post_id ); ?>
189
- </div>
190
- </div>
191
- </div>
192
-
193
- <?php
194
- }
195
-
196
- /**
197
- * Shortcodes tab
198
- *
199
- * @param array $options options.
200
- * @param int $post_id post ID.
201
- */
202
- public function tab_shortcodes( $options, $post_id ) {
203
- ?>
204
- <div class="wcf-optin-shortcodes wcf-tab-content widefat">
205
-
206
- <?php
207
-
208
- echo wcf()->meta->get_shortcode_field(
209
- array(
210
- 'label' => 'Optin Page',
211
- 'name' => 'wcf-optin-shortcode',
212
- 'content' => '[cartflows_optin]',
213
- 'help' => esc_html__( 'Add this shortcode to your optin page', 'cartflows' ),
214
- )
215
- );
216
- ?>
217
- </div>
218
- <?php
219
- }
220
-
221
-
222
- /**
223
- * General tab
224
- *
225
- * @param array $options options.
226
- * @param int $post_id post ID.
227
- */
228
- public function tab_general( $options, $post_id ) {
229
- ?>
230
- <div class="wcf-optin-general wcf-tab-content widefat">
231
-
232
- <?php
233
-
234
- echo wcf()->meta->get_product_selection_field(
235
- array(
236
- 'name' => 'wcf-optin-product',
237
- 'value' => $options['wcf-optin-product'],
238
- 'label' => __( 'Select Free Product', 'cartflows' ),
239
- 'help' => __( 'Select Free and Virtual product only.', 'cartflows' ),
240
- 'multiple' => false,
241
- 'allow_clear' => true,
242
- )
243
- );
244
-
245
- ?>
246
- </div>
247
- <?php
248
- }
249
-
250
- /**
251
- * Tab custom fields
252
- *
253
- * @param array $options options.
254
- * @param int $post_id post ID.
255
- */
256
- public function tab_custom_fields( $options, $post_id ) {
257
- ?>
258
- <div class="wcf-optin-custom-fields wcf-tab-content widefat">
259
- <?php
260
- /* Custom Checkout Fields Section */
261
-
262
- if ( ! _is_cartflows_pro() ) {
263
- echo wcf()->meta->get_description_field(
264
- array(
265
- 'name' => 'wcf-upgrade-to-pro',
266
- /* translators: %s: link */
267
- 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
268
- )
269
- );
270
- }
271
- ?>
272
- <?php do_action( 'cartflows_optin_custom_fields_tab_content', $options, $post_id ); ?>
273
- </div>
274
- <?php
275
- }
276
-
277
- /**
278
- * Tab custom settings
279
- *
280
- * @param array $options options.
281
- * @param int $post_id post ID.
282
- */
283
- public function tab_custom_settings( $options, $post_id ) {
284
- ?>
285
- <div class="wcf-optin-custom-settings wcf-tab-content widefat">
286
- <div class="wcf-custom-settings-fields">
287
- <?php
288
- echo wcf()->meta->get_checkbox_field(
289
- array(
290
- 'label' => __( 'Pass Fields as URL Parameters', 'cartflows' ),
291
- 'name' => 'wcf-optin-pass-fields',
292
- 'value' => $options['wcf-optin-pass-fields'],
293
- 'after' => __( 'Enable', 'cartflows' ),
294
- 'help' => __( 'You can pass specific fields from the form to next step as URL query parameters.', 'cartflows' ),
295
- 'toggle' => array(
296
- 'fields' => array(
297
- 'yes' => array( 'wcf-optin-pass-specific-fields' ),
298
- ),
299
- ),
300
- )
301
- );
302
-
303
- echo wcf()->meta->get_text_field(
304
- array(
305
- 'label' => __( 'Enter form field', 'cartflows' ),
306
- 'name' => 'wcf-optin-pass-specific-fields',
307
- 'value' => $options['wcf-optin-pass-specific-fields'],
308
- 'help' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ),
309
- 'attr' => array(
310
- 'placeholder' => __( 'Fields to pass, separated by commas', 'cartflows' ),
311
- ),
312
- )
313
- );
314
-
315
- echo wcf()->meta->get_description_field(
316
- array(
317
- 'name' => 'wcf-optin-pass-fields-doc',
318
- 'content' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ),
319
- /* translators: %s: link */
320
- 'content' => sprintf( esc_html__( 'You can pass field value as a URL parameter to the next step. %1$sClick here%2$s for more information.', 'cartflows' ), '<a href="https://cartflows.com/docs/pass-variable-as-query-parameters-to-url/" target="_blank">', '</a>' ),
321
- )
322
- );
323
-
324
- ?>
325
- </div>
326
- </div>
327
- <?php
328
- }
329
-
330
- /**
331
- * Tab style
332
- *
333
- * @param array $options options.
334
- * @param int $post_id post ID.
335
- */
336
- public function tab_style( $options, $post_id ) {
337
- ?>
338
-
339
- <div class="wcf-optin-style wcf-tab-content widefat">
340
- <?php
341
- echo wcf()->meta->get_color_picker_field(
342
- array(
343
- 'label' => __( 'Primary Color', 'cartflows' ),
344
- 'name' => 'wcf-primary-color',
345
- 'value' => $options['wcf-primary-color'],
346
- )
347
- );
348
-
349
- echo wcf()->meta->get_font_family_field(
350
- array(
351
- 'for' => 'wcf-base',
352
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
353
- 'name' => 'wcf-base-font-family',
354
- 'value' => $options['wcf-base-font-family'],
355
- )
356
- );
357
- ?>
358
- <div class="wcf-cs-fields">
359
- <div class="wcf-cs-fields-options">
360
- <?php
361
- echo wcf()->meta->get_section(
362
- array(
363
- 'label' => __( 'Input Fields', 'cartflows' ),
364
- )
365
- );
366
-
367
- $fields_skin_pro_option = array();
368
- if ( ! _is_cartflows_pro() ) {
369
- $fields_skin_pro_option = array(
370
- 'floating-labels' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
371
- );
372
- }
373
-
374
- echo wcf()->meta->get_select_field(
375
- array(
376
- 'label' => __( 'Style', 'cartflows' ),
377
- 'name' => 'wcf-input-fields-skins',
378
- 'value' => $options['wcf-input-fields-skins'],
379
- 'options' => array(
380
- 'default' => esc_html__( 'Default', 'cartflows' ),
381
- 'floating-labels' => esc_html__( 'Floating Labels', 'cartflows' ),
382
- ),
383
- 'pro-options' => $fields_skin_pro_option,
384
-
385
- )
386
- );
387
-
388
- echo wcf()->meta->get_font_family_field(
389
- array(
390
- 'for' => 'wcf-input',
391
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
392
- 'name' => 'wcf-input-font-family',
393
- 'value' => $options['wcf-input-font-family'],
394
- )
395
- );
396
-
397
- echo wcf()->meta->get_font_weight_field(
398
- array(
399
- 'for' => 'wcf-input',
400
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
401
- 'name' => 'wcf-input-font-weight',
402
- 'value' => $options['wcf-input-font-weight'],
403
- )
404
- );
405
-
406
- echo wcf()->meta->get_select_field(
407
- array(
408
- 'label' => __( 'Size', 'cartflows' ),
409
- 'name' => 'wcf-input-field-size',
410
- 'value' => $options['wcf-input-field-size'],
411
- 'options' => array(
412
- '33px' => esc_html__( 'Extra Small', 'cartflows' ),
413
- '38px' => esc_html__( 'Small', 'cartflows' ),
414
- '44px' => esc_html__( 'Medium', 'cartflows' ),
415
- '58px' => esc_html__( 'Large', 'cartflows' ),
416
- '68px' => esc_html__( 'Extra Large', 'cartflows' ),
417
- 'custom' => esc_html__( 'Custom', 'cartflows' ),
418
- ),
419
- )
420
- );
421
-
422
- echo wcf()->meta->get_number_field(
423
- array(
424
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
425
- 'name' => 'wcf-field-tb-padding',
426
- 'value' => $options['wcf-field-tb-padding'],
427
- )
428
- );
429
-
430
- echo wcf()->meta->get_number_field(
431
- array(
432
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
433
- 'name' => 'wcf-field-lr-padding',
434
- 'value' => $options['wcf-field-lr-padding'],
435
- )
436
- );
437
-
438
- echo wcf()->meta->get_color_picker_field(
439
- array(
440
- 'label' => __( 'Label Color', 'cartflows' ),
441
- 'name' => 'wcf-field-label-color',
442
- 'value' => $options['wcf-field-label-color'],
443
- )
444
- );
445
-
446
- echo wcf()->meta->get_color_picker_field(
447
- array(
448
- 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
449
- 'name' => 'wcf-field-color',
450
- 'value' => $options['wcf-field-color'],
451
- )
452
- );
453
-
454
- echo wcf()->meta->get_color_picker_field(
455
- array(
456
- 'label' => __( 'Background Color', 'cartflows' ),
457
- 'name' => 'wcf-field-bg-color',
458
- 'value' => $options['wcf-field-bg-color'],
459
- )
460
- );
461
-
462
- echo wcf()->meta->get_color_picker_field(
463
- array(
464
- 'label' => __( 'Border Color', 'cartflows' ),
465
- 'name' => 'wcf-field-border-color',
466
- 'value' => $options['wcf-field-border-color'],
467
- )
468
- );
469
-
470
- ?>
471
- </div>
472
- <div class="wcf-cs-button-options">
473
- <?php
474
-
475
- echo wcf()->meta->get_section(
476
- array(
477
- 'label' => __( 'Submit Button', 'cartflows' ),
478
- )
479
- );
480
-
481
- echo wcf()->meta->get_text_field(
482
- array(
483
- 'label' => __( 'Button Text', 'cartflows' ),
484
- 'name' => 'wcf-submit-button-text',
485
- 'value' => $options['wcf-submit-button-text'],
486
- 'attr' => array(
487
- 'placeholder' => __( 'Submit', 'cartflows' ),
488
- ),
489
- )
490
- );
491
-
492
- echo wcf()->meta->get_number_field(
493
- array(
494
- 'label' => __( 'Font Size', 'cartflows' ),
495
- 'name' => 'wcf-submit-font-size',
496
- 'value' => $options['wcf-submit-font-size'],
497
- )
498
- );
499
-
500
- echo wcf()->meta->get_font_family_field(
501
- array(
502
- 'for' => 'wcf-button',
503
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
504
- 'name' => 'wcf-button-font-family',
505
- 'value' => $options['wcf-button-font-family'],
506
- )
507
- );
508
-
509
- echo wcf()->meta->get_font_weight_field(
510
- array(
511
- 'for' => 'wcf-button',
512
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
513
- 'name' => 'wcf-button-font-weight',
514
- 'value' => $options['wcf-button-font-weight'],
515
- )
516
- );
517
-
518
- echo wcf()->meta->get_select_field(
519
- array(
520
- 'label' => __( 'Size', 'cartflows' ),
521
- 'name' => 'wcf-submit-button-size',
522
- 'value' => $options['wcf-submit-button-size'],
523
- 'options' => array(
524
- '33px' => esc_html__( 'Extra Small', 'cartflows' ),
525
- '38px' => esc_html__( 'Small', 'cartflows' ),
526
- '44px' => esc_html__( 'Medium', 'cartflows' ),
527
- '58px' => esc_html__( 'Large', 'cartflows' ),
528
- '68px' => esc_html__( 'Extra Large', 'cartflows' ),
529
- 'custom' => esc_html__( 'Custom', 'cartflows' ),
530
- ),
531
- )
532
- );
533
-
534
- echo wcf()->meta->get_number_field(
535
- array(
536
- 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
537
- 'name' => 'wcf-submit-tb-padding',
538
- 'value' => $options['wcf-submit-tb-padding'],
539
- )
540
- );
541
-
542
- echo wcf()->meta->get_number_field(
543
- array(
544
- 'label' => __( 'Left Right Spacing', 'cartflows' ),
545
- 'name' => 'wcf-submit-lr-padding',
546
- 'value' => $options['wcf-submit-lr-padding'],
547
- )
548
- );
549
-
550
- echo wcf()->meta->get_select_field(
551
- array(
552
- 'label' => __( 'Position', 'cartflows' ),
553
- 'name' => 'wcf-submit-button-position',
554
- 'value' => $options['wcf-submit-button-position'],
555
- 'options' => array(
556
- 'left' => esc_html__( 'Left', 'cartflows' ),
557
- 'center' => esc_html__( 'Center', 'cartflows' ),
558
- 'right' => esc_html__( 'Right', 'cartflows' ),
559
- ),
560
- )
561
- );
562
-
563
- echo wcf()->meta->get_color_picker_field(
564
- array(
565
- 'label' => __( 'Text Color', 'cartflows' ),
566
- 'name' => 'wcf-submit-color',
567
- 'value' => $options['wcf-submit-color'],
568
- )
569
- );
570
-
571
- echo wcf()->meta->get_color_picker_field(
572
- array(
573
- 'label' => __( 'Text Hover Color', 'cartflows' ),
574
- 'name' => 'wcf-submit-hover-color',
575
- 'value' => $options['wcf-submit-hover-color'],
576
- )
577
- );
578
-
579
- echo wcf()->meta->get_color_picker_field(
580
- array(
581
- 'label' => __( 'Background Color', 'cartflows' ),
582
- 'name' => 'wcf-submit-bg-color',
583
- 'value' => $options['wcf-submit-bg-color'],
584
- )
585
- );
586
-
587
- echo wcf()->meta->get_color_picker_field(
588
- array(
589
- 'label' => __( 'Background Hover Color', 'cartflows' ),
590
- 'name' => 'wcf-submit-bg-hover-color',
591
- 'value' => $options['wcf-submit-bg-hover-color'],
592
- )
593
- );
594
-
595
- echo wcf()->meta->get_color_picker_field(
596
- array(
597
- 'label' => __( 'Border Color', 'cartflows' ),
598
- 'name' => 'wcf-submit-border-color',
599
- 'value' => $options['wcf-submit-border-color'],
600
- )
601
- );
602
-
603
- echo wcf()->meta->get_color_picker_field(
604
- array(
605
- 'label' => __( 'Border Hover Color', 'cartflows' ),
606
- 'name' => 'wcf-submit-border-hover-color',
607
- 'value' => $options['wcf-submit-border-hover-color'],
608
- )
609
- );
610
-
611
- ?>
612
- </div>
613
- </div>
614
- <?php
615
- echo wcf()->meta->get_hidden_field(
616
- array(
617
- 'name' => 'wcf-field-google-font-url',
618
- 'value' => $options['wcf-field-google-font-url'],
619
- )
620
- );
621
- ?>
622
- </div>
623
- <?php
624
- }
625
-
626
- /**
627
- * Get metabox options
628
- *
629
- * @param int $post_id post ID.
630
- */
631
- public static function get_meta_option( $post_id ) {
632
-
633
- if ( null === self::$meta_option ) {
634
-
635
- /**
636
- * Set metabox options
637
- *
638
- * @see http://php.net/manual/en/filter.filters.sanitize.php
639
- */
640
- self::$meta_option = wcf()->options->get_optin_fields( $post_id );
641
- }
642
-
643
- return self::$meta_option;
644
- }
645
-
646
- /**
647
- * Metabox Save
648
- *
649
- * @param number $post_id Post ID.
650
- * @return void
651
- */
652
- public function save_meta_box( $post_id ) {
653
-
654
- // Checks save status.
655
- $is_autosave = wp_is_post_autosave( $post_id );
656
- $is_revision = wp_is_post_revision( $post_id );
657
-
658
- $is_valid_nonce = ( isset( $_POST['nonce-optin-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-optin-step-meta'] ) ), 'save-nonce-optin-step-meta' ) ) ? true : false;
659
-
660
- // Exits script depending on save status.
661
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
662
- return;
663
- }
664
-
665
- wcf()->options->save_optin_fields( $post_id );
666
- }
667
- }
668
-
669
- /**
670
- * Kicking this off by calling 'get_instance()' method
671
- */
672
- Cartflows_Optin_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_Optin_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
+ * 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
+ public function setup_meta_box() {
61
+
62
+ if ( _is_wcf_optin_type() ) {
63
+ add_meta_box(
64
+ 'wcf-optin-settings', // Id.
65
+ __( 'Optin 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
+ public function markup_meta_box( $post ) {
81
+
82
+ wp_nonce_field( 'save-nonce-optin-step-meta', 'nonce-optin-step-meta' );
83
+
84
+ $stored = get_post_meta( $post->ID );
85
+
86
+ $optin_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, $optin_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
+ $optin_meta = array();
100
+
101
+ foreach ( $meta as $key => $value ) {
102
+ $optin_meta[ $key ] = $meta[ $key ]['default'];
103
+ }
104
+
105
+ do_action( 'wcf_optin_settings_markup_before' );
106
+ $this->tabs_markup( $optin_meta, $post->ID );
107
+ do_action( 'wcf_optin_settings_markup_after' );
108
+ }
109
+
110
+ /**
111
+ * Page Header Tabs
112
+ *
113
+ * @param array $options options.
114
+ * @param int $post_id post ID.
115
+ */
116
+ public function tabs_markup( $options, $post_id ) {
117
+
118
+ $active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
119
+
120
+ if ( empty( $active_tab ) ) {
121
+ $active_tab = 'wcf-optin-shortcodes';
122
+ }
123
+
124
+ $tab_array = array(
125
+ array(
126
+ 'title' => __( 'Shortcodes', 'cartflows' ),
127
+ 'id' => 'wcf-optin-shortcodes',
128
+ 'class' => 'wcf-optin-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
129
+ 'icon' => 'dashicons-editor-code',
130
+ ),
131
+ array(
132
+ 'title' => __( 'Select Product', 'cartflows' ),
133
+ 'id' => 'wcf-optin-general',
134
+ 'class' => 'wcf-optin-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
135
+ 'icon' => 'dashicons-info',
136
+ ),
137
+ array(
138
+ 'title' => __( 'Design', 'cartflows' ),
139
+ 'id' => 'wcf-optin-style',
140
+ 'class' => 'wcf-optin-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
141
+ 'icon' => 'dashicons-admin-customizer',
142
+ ),
143
+ array(
144
+ 'title' => __( 'Form Fields', 'cartflows' ),
145
+ 'id' => 'wcf-optin-custom-fields',
146
+ 'class' => 'wcf-optin-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
147
+ 'icon' => 'dashicons-welcome-widgets-menus',
148
+ ),
149
+ array(
150
+ 'title' => __( 'Settings', 'cartflows' ),
151
+ 'id' => 'wcf-optin-custom-settings',
152
+ 'class' => 'wcf-optin-custom-settings' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
153
+ 'icon' => 'dashicons-admin-generic',
154
+ ),
155
+ array(
156
+ 'title' => __( 'Custom Script', 'cartflows' ),
157
+ 'id' => 'wcf-optin-custom-script-header',
158
+ 'class' => 'wcf-optin-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
159
+ 'icon' => 'dashicons-format-aside',
160
+ ),
161
+ );
162
+
163
+ $tabs = $tab_array;
164
+
165
+ ?>
166
+ <div class="wcf-optin-table wcf-metabox-wrap widefat">
167
+ <div class="wcf-table-container">
168
+ <div class="wcf-column-left">
169
+ <div class="wcf-tab-wrapper">
170
+
171
+ <?php foreach ( $tabs as $key => $tab ) { ?>
172
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
173
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
174
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
175
+ </div>
176
+ <?php } ?>
177
+
178
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
179
+ </div>
180
+ </div>
181
+ <div class="wcf-column-right">
182
+ <?php $this->tab_shortcodes( $options, $post_id ); ?>
183
+ <?php $this->tab_general( $options, $post_id ); ?>
184
+ <?php $this->tab_style( $options, $post_id ); ?>
185
+ <?php $this->tab_custom_fields( $options, $post_id ); ?>
186
+ <?php $this->tab_custom_settings( $options, $post_id ); ?>
187
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
188
+ <?php $this->right_column_footer( $options, $post_id ); ?>
189
+ </div>
190
+ </div>
191
+ </div>
192
+
193
+ <?php
194
+ }
195
+
196
+ /**
197
+ * Shortcodes tab
198
+ *
199
+ * @param array $options options.
200
+ * @param int $post_id post ID.
201
+ */
202
+ public function tab_shortcodes( $options, $post_id ) {
203
+ ?>
204
+ <div class="wcf-optin-shortcodes wcf-tab-content widefat">
205
+
206
+ <?php
207
+
208
+ echo wcf()->meta->get_shortcode_field(
209
+ array(
210
+ 'label' => 'Optin Page',
211
+ 'name' => 'wcf-optin-shortcode',
212
+ 'content' => '[cartflows_optin]',
213
+ 'help' => esc_html__( 'Add this shortcode to your optin page', 'cartflows' ),
214
+ )
215
+ );
216
+ ?>
217
+ </div>
218
+ <?php
219
+ }
220
+
221
+
222
+ /**
223
+ * General tab
224
+ *
225
+ * @param array $options options.
226
+ * @param int $post_id post ID.
227
+ */
228
+ public function tab_general( $options, $post_id ) {
229
+ ?>
230
+ <div class="wcf-optin-general wcf-tab-content widefat">
231
+
232
+ <?php
233
+
234
+ echo wcf()->meta->get_product_selection_field(
235
+ array(
236
+ 'name' => 'wcf-optin-product',
237
+ 'value' => $options['wcf-optin-product'],
238
+ 'label' => __( 'Select Free Product', 'cartflows' ),
239
+ 'help' => __( 'Select Free and Virtual product only.', 'cartflows' ),
240
+ 'multiple' => false,
241
+ 'allow_clear' => true,
242
+ )
243
+ );
244
+
245
+ ?>
246
+ </div>
247
+ <?php
248
+ }
249
+
250
+ /**
251
+ * Tab custom fields
252
+ *
253
+ * @param array $options options.
254
+ * @param int $post_id post ID.
255
+ */
256
+ public function tab_custom_fields( $options, $post_id ) {
257
+ ?>
258
+ <div class="wcf-optin-custom-fields wcf-tab-content widefat">
259
+ <?php
260
+ /* Custom Checkout Fields Section */
261
+
262
+ if ( ! _is_cartflows_pro() ) {
263
+ echo wcf()->meta->get_description_field(
264
+ array(
265
+ 'name' => 'wcf-upgrade-to-pro',
266
+ /* translators: %s: link */
267
+ 'content' => '<i>' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature.', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
268
+ )
269
+ );
270
+ }
271
+ ?>
272
+ <?php do_action( 'cartflows_optin_custom_fields_tab_content', $options, $post_id ); ?>
273
+ </div>
274
+ <?php
275
+ }
276
+
277
+ /**
278
+ * Tab custom settings
279
+ *
280
+ * @param array $options options.
281
+ * @param int $post_id post ID.
282
+ */
283
+ public function tab_custom_settings( $options, $post_id ) {
284
+ ?>
285
+ <div class="wcf-optin-custom-settings wcf-tab-content widefat">
286
+ <div class="wcf-custom-settings-fields">
287
+ <?php
288
+ echo wcf()->meta->get_checkbox_field(
289
+ array(
290
+ 'label' => __( 'Pass Fields as URL Parameters', 'cartflows' ),
291
+ 'name' => 'wcf-optin-pass-fields',
292
+ 'value' => $options['wcf-optin-pass-fields'],
293
+ 'after' => __( 'Enable', 'cartflows' ),
294
+ 'help' => __( 'You can pass specific fields from the form to next step as URL query parameters.', 'cartflows' ),
295
+ 'toggle' => array(
296
+ 'fields' => array(
297
+ 'yes' => array( 'wcf-optin-pass-specific-fields' ),
298
+ ),
299
+ ),
300
+ )
301
+ );
302
+
303
+ echo wcf()->meta->get_text_field(
304
+ array(
305
+ 'label' => __( 'Enter form field', 'cartflows' ),
306
+ 'name' => 'wcf-optin-pass-specific-fields',
307
+ 'value' => $options['wcf-optin-pass-specific-fields'],
308
+ 'help' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ),
309
+ 'attr' => array(
310
+ 'placeholder' => __( 'Fields to pass, separated by commas', 'cartflows' ),
311
+ ),
312
+ )
313
+ );
314
+
315
+ echo wcf()->meta->get_description_field(
316
+ array(
317
+ 'name' => 'wcf-optin-pass-fields-doc',
318
+ 'content' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ),
319
+ /* translators: %s: link */
320
+ 'content' => sprintf( esc_html__( 'You can pass field value as a URL parameter to the next step. %1$sClick here%2$s for more information.', 'cartflows' ), '<a href="https://cartflows.com/docs/pass-variable-as-query-parameters-to-url/" target="_blank">', '</a>' ),
321
+ )
322
+ );
323
+
324
+ ?>
325
+ </div>
326
+ </div>
327
+ <?php
328
+ }
329
+
330
+ /**
331
+ * Tab style
332
+ *
333
+ * @param array $options options.
334
+ * @param int $post_id post ID.
335
+ */
336
+ public function tab_style( $options, $post_id ) {
337
+ ?>
338
+
339
+ <div class="wcf-optin-style wcf-tab-content widefat">
340
+ <?php
341
+ echo wcf()->meta->get_color_picker_field(
342
+ array(
343
+ 'label' => __( 'Primary Color', 'cartflows' ),
344
+ 'name' => 'wcf-primary-color',
345
+ 'value' => $options['wcf-primary-color'],
346
+ )
347
+ );
348
+
349
+ echo wcf()->meta->get_font_family_field(
350
+ array(
351
+ 'for' => 'wcf-base',
352
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
353
+ 'name' => 'wcf-base-font-family',
354
+ 'value' => $options['wcf-base-font-family'],
355
+ )
356
+ );
357
+ ?>
358
+ <div class="wcf-cs-fields">
359
+ <div class="wcf-cs-fields-options">
360
+ <?php
361
+ echo wcf()->meta->get_section(
362
+ array(
363
+ 'label' => __( 'Input Fields', 'cartflows' ),
364
+ )
365
+ );
366
+
367
+ $fields_skin_pro_option = array();
368
+ if ( ! _is_cartflows_pro() ) {
369
+ $fields_skin_pro_option = array(
370
+ 'floating-labels' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
371
+ );
372
+ }
373
+
374
+ echo wcf()->meta->get_select_field(
375
+ array(
376
+ 'label' => __( 'Style', 'cartflows' ),
377
+ 'name' => 'wcf-input-fields-skins',
378
+ 'value' => $options['wcf-input-fields-skins'],
379
+ 'options' => array(
380
+ 'default' => esc_html__( 'Default', 'cartflows' ),
381
+ 'floating-labels' => esc_html__( 'Floating Labels', 'cartflows' ),
382
+ ),
383
+ 'pro-options' => $fields_skin_pro_option,
384
+
385
+ )
386
+ );
387
+
388
+ echo wcf()->meta->get_font_family_field(
389
+ array(
390
+ 'for' => 'wcf-input',
391
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
392
+ 'name' => 'wcf-input-font-family',
393
+ 'value' => $options['wcf-input-font-family'],
394
+ )
395
+ );
396
+
397
+ echo wcf()->meta->get_font_weight_field(
398
+ array(
399
+ 'for' => 'wcf-input',
400
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
401
+ 'name' => 'wcf-input-font-weight',
402
+ 'value' => $options['wcf-input-font-weight'],
403
+ )
404
+ );
405
+
406
+ echo wcf()->meta->get_select_field(
407
+ array(
408
+ 'label' => __( 'Size', 'cartflows' ),
409
+ 'name' => 'wcf-input-field-size',
410
+ 'value' => $options['wcf-input-field-size'],
411
+ 'options' => array(
412
+ '33px' => esc_html__( 'Extra Small', 'cartflows' ),
413
+ '38px' => esc_html__( 'Small', 'cartflows' ),
414
+ '44px' => esc_html__( 'Medium', 'cartflows' ),
415
+ '58px' => esc_html__( 'Large', 'cartflows' ),
416
+ '68px' => esc_html__( 'Extra Large', 'cartflows' ),
417
+ 'custom' => esc_html__( 'Custom', 'cartflows' ),
418
+ ),
419
+ )
420
+ );
421
+
422
+ echo wcf()->meta->get_number_field(
423
+ array(
424
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
425
+ 'name' => 'wcf-field-tb-padding',
426
+ 'value' => $options['wcf-field-tb-padding'],
427
+ )
428
+ );
429
+
430
+ echo wcf()->meta->get_number_field(
431
+ array(
432
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
433
+ 'name' => 'wcf-field-lr-padding',
434
+ 'value' => $options['wcf-field-lr-padding'],
435
+ )
436
+ );
437
+
438
+ echo wcf()->meta->get_color_picker_field(
439
+ array(
440
+ 'label' => __( 'Label Color', 'cartflows' ),
441
+ 'name' => 'wcf-field-label-color',
442
+ 'value' => $options['wcf-field-label-color'],
443
+ )
444
+ );
445
+
446
+ echo wcf()->meta->get_color_picker_field(
447
+ array(
448
+ 'label' => __( 'Text / Placeholder Color', 'cartflows' ),
449
+ 'name' => 'wcf-field-color',
450
+ 'value' => $options['wcf-field-color'],
451
+ )
452
+ );
453
+
454
+ echo wcf()->meta->get_color_picker_field(
455
+ array(
456
+ 'label' => __( 'Background Color', 'cartflows' ),
457
+ 'name' => 'wcf-field-bg-color',
458
+ 'value' => $options['wcf-field-bg-color'],
459
+ )
460
+ );
461
+
462
+ echo wcf()->meta->get_color_picker_field(
463
+ array(
464
+ 'label' => __( 'Border Color', 'cartflows' ),
465
+ 'name' => 'wcf-field-border-color',
466
+ 'value' => $options['wcf-field-border-color'],
467
+ )
468
+ );
469
+
470
+ ?>
471
+ </div>
472
+ <div class="wcf-cs-button-options">
473
+ <?php
474
+
475
+ echo wcf()->meta->get_section(
476
+ array(
477
+ 'label' => __( 'Submit Button', 'cartflows' ),
478
+ )
479
+ );
480
+
481
+ echo wcf()->meta->get_text_field(
482
+ array(
483
+ 'label' => __( 'Button Text', 'cartflows' ),
484
+ 'name' => 'wcf-submit-button-text',
485
+ 'value' => $options['wcf-submit-button-text'],
486
+ 'attr' => array(
487
+ 'placeholder' => __( 'Submit', 'cartflows' ),
488
+ ),
489
+ )
490
+ );
491
+
492
+ echo wcf()->meta->get_number_field(
493
+ array(
494
+ 'label' => __( 'Font Size', 'cartflows' ),
495
+ 'name' => 'wcf-submit-font-size',
496
+ 'value' => $options['wcf-submit-font-size'],
497
+ )
498
+ );
499
+
500
+ echo wcf()->meta->get_font_family_field(
501
+ array(
502
+ 'for' => 'wcf-button',
503
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
504
+ 'name' => 'wcf-button-font-family',
505
+ 'value' => $options['wcf-button-font-family'],
506
+ )
507
+ );
508
+
509
+ echo wcf()->meta->get_font_weight_field(
510
+ array(
511
+ 'for' => 'wcf-button',
512
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
513
+ 'name' => 'wcf-button-font-weight',
514
+ 'value' => $options['wcf-button-font-weight'],
515
+ )
516
+ );
517
+
518
+ echo wcf()->meta->get_select_field(
519
+ array(
520
+ 'label' => __( 'Size', 'cartflows' ),
521
+ 'name' => 'wcf-submit-button-size',
522
+ 'value' => $options['wcf-submit-button-size'],
523
+ 'options' => array(
524
+ '33px' => esc_html__( 'Extra Small', 'cartflows' ),
525
+ '38px' => esc_html__( 'Small', 'cartflows' ),
526
+ '44px' => esc_html__( 'Medium', 'cartflows' ),
527
+ '58px' => esc_html__( 'Large', 'cartflows' ),
528
+ '68px' => esc_html__( 'Extra Large', 'cartflows' ),
529
+ 'custom' => esc_html__( 'Custom', 'cartflows' ),
530
+ ),
531
+ )
532
+ );
533
+
534
+ echo wcf()->meta->get_number_field(
535
+ array(
536
+ 'label' => __( 'Top Bottom Spacing', 'cartflows' ),
537
+ 'name' => 'wcf-submit-tb-padding',
538
+ 'value' => $options['wcf-submit-tb-padding'],
539
+ )
540
+ );
541
+
542
+ echo wcf()->meta->get_number_field(
543
+ array(
544
+ 'label' => __( 'Left Right Spacing', 'cartflows' ),
545
+ 'name' => 'wcf-submit-lr-padding',
546
+ 'value' => $options['wcf-submit-lr-padding'],
547
+ )
548
+ );
549
+
550
+ echo wcf()->meta->get_select_field(
551
+ array(
552
+ 'label' => __( 'Position', 'cartflows' ),
553
+ 'name' => 'wcf-submit-button-position',
554
+ 'value' => $options['wcf-submit-button-position'],
555
+ 'options' => array(
556
+ 'left' => esc_html__( 'Left', 'cartflows' ),
557
+ 'center' => esc_html__( 'Center', 'cartflows' ),
558
+ 'right' => esc_html__( 'Right', 'cartflows' ),
559
+ ),
560
+ )
561
+ );
562
+
563
+ echo wcf()->meta->get_color_picker_field(
564
+ array(
565
+ 'label' => __( 'Text Color', 'cartflows' ),
566
+ 'name' => 'wcf-submit-color',
567
+ 'value' => $options['wcf-submit-color'],
568
+ )
569
+ );
570
+
571
+ echo wcf()->meta->get_color_picker_field(
572
+ array(
573
+ 'label' => __( 'Text Hover Color', 'cartflows' ),
574
+ 'name' => 'wcf-submit-hover-color',
575
+ 'value' => $options['wcf-submit-hover-color'],
576
+ )
577
+ );
578
+
579
+ echo wcf()->meta->get_color_picker_field(
580
+ array(
581
+ 'label' => __( 'Background Color', 'cartflows' ),
582
+ 'name' => 'wcf-submit-bg-color',
583
+ 'value' => $options['wcf-submit-bg-color'],
584
+ )
585
+ );
586
+
587
+ echo wcf()->meta->get_color_picker_field(
588
+ array(
589
+ 'label' => __( 'Background Hover Color', 'cartflows' ),
590
+ 'name' => 'wcf-submit-bg-hover-color',
591
+ 'value' => $options['wcf-submit-bg-hover-color'],
592
+ )
593
+ );
594
+
595
+ echo wcf()->meta->get_color_picker_field(
596
+ array(
597
+ 'label' => __( 'Border Color', 'cartflows' ),
598
+ 'name' => 'wcf-submit-border-color',
599
+ 'value' => $options['wcf-submit-border-color'],
600
+ )
601
+ );
602
+
603
+ echo wcf()->meta->get_color_picker_field(
604
+ array(
605
+ 'label' => __( 'Border Hover Color', 'cartflows' ),
606
+ 'name' => 'wcf-submit-border-hover-color',
607
+ 'value' => $options['wcf-submit-border-hover-color'],
608
+ )
609
+ );
610
+
611
+ ?>
612
+ </div>
613
+ </div>
614
+ <?php
615
+ echo wcf()->meta->get_hidden_field(
616
+ array(
617
+ 'name' => 'wcf-field-google-font-url',
618
+ 'value' => $options['wcf-field-google-font-url'],
619
+ )
620
+ );
621
+ ?>
622
+ </div>
623
+ <?php
624
+ }
625
+
626
+ /**
627
+ * Get metabox options
628
+ *
629
+ * @param int $post_id post ID.
630
+ */
631
+ public static function get_meta_option( $post_id ) {
632
+
633
+ if ( null === self::$meta_option ) {
634
+
635
+ /**
636
+ * Set metabox options
637
+ *
638
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
639
+ */
640
+ self::$meta_option = wcf()->options->get_optin_fields( $post_id );
641
+ }
642
+
643
+ return self::$meta_option;
644
+ }
645
+
646
+ /**
647
+ * Metabox Save
648
+ *
649
+ * @param number $post_id Post ID.
650
+ * @return void
651
+ */
652
+ public function save_meta_box( $post_id ) {
653
+
654
+ // Checks save status.
655
+ $is_autosave = wp_is_post_autosave( $post_id );
656
+ $is_revision = wp_is_post_revision( $post_id );
657
+
658
+ $is_valid_nonce = ( isset( $_POST['nonce-optin-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-optin-step-meta'] ) ), 'save-nonce-optin-step-meta' ) ) ? true : false;
659
+
660
+ // Exits script depending on save status.
661
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
662
+ return;
663
+ }
664
+
665
+ wcf()->options->save_optin_fields( $post_id );
666
+ }
667
+ }
668
+
669
+ /**
670
+ * Kicking this off by calling 'get_instance()' method
671
+ */
672
+ Cartflows_Optin_Meta::get_instance();
modules/thankyou/classes/class-cartflows-thankyou-markup.php CHANGED
@@ -1,372 +1,372 @@
1
- <?php
2
- /**
3
- * Front end and markup
4
- *
5
- * @package CartFlows
6
- */
7
-
8
- /**
9
- * Checkout Markup
10
- *
11
- * @since 1.0.0
12
- */
13
- class Cartflows_Thankyou_Markup {
14
-
15
-
16
- /**
17
- * Member Variable
18
- *
19
- * @var object instance
20
- */
21
- private static $instance;
22
-
23
- /**
24
- * Initiator
25
- */
26
- public static function get_instance() {
27
- if ( ! isset( self::$instance ) ) {
28
- self::$instance = new self();
29
- }
30
- return self::$instance;
31
- }
32
-
33
- /**
34
- * Constructor
35
- */
36
- public function __construct() {
37
-
38
- /* Downsell Shortcode */
39
- add_shortcode( 'cartflows_order_details', array( $this, 'cartflows_order_details_shortcode_markup' ) );
40
-
41
- add_action( 'wp_enqueue_scripts', array( $this, 'thank_you_scripts' ), 21 );
42
-
43
- add_action( 'woocommerce_is_order_received_page', array( $this, 'set_order_received_page' ) );
44
-
45
- /* Set is checkout flag */
46
- add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
47
-
48
- /* Custom redirection of thank you page */
49
- add_action( 'template_redirect', array( $this, 'redirect_tq_page_to_custom_url' ) );
50
-
51
- add_action( 'cartflows_thank_you_scripts', array( $this, 'add_divi_compatibility_css' ) );
52
- }
53
-
54
- /**
55
- * Redirect to custom url instead of thank you page.
56
- */
57
- public function redirect_tq_page_to_custom_url() {
58
- global $post;
59
-
60
- if ( _is_wcf_thankyou_type() ) {
61
-
62
- $thank_you_id = $post->ID;
63
- $enable_redirection = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-tq-redirect-section' );
64
- $redirect_link = wp_http_validate_url( wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-redirect-link' ) );
65
-
66
- if ( 'yes' === $enable_redirection && ! empty( $redirect_link ) ) {
67
- exit( wp_redirect( $redirect_link ) ); //phpcs:ignore
68
- }
69
- }
70
- }
71
- /**
72
- * Order shortcode markup
73
- *
74
- * @param array $atts attributes.
75
- * @since 1.0.0
76
- */
77
- public function cartflows_order_details_shortcode_markup( $atts ) {
78
-
79
- $output = '';
80
-
81
- if ( _is_wcf_thankyou_type() ) {
82
- /* Remove order item link */
83
- add_filter( 'woocommerce_order_item_permalink', '__return_false' );
84
-
85
- /* Change order text */
86
- add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'custom_tq_text' ), 10, 2 );
87
-
88
- if ( ! function_exists( 'wc_print_notices' ) ) {
89
-
90
- $notice_out = '<p class="woocommerce-notice">' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '</p>';
91
- $notice_out .= '<button onClick="location.reload()">' . __( 'Click Here to Reload', 'cartflows' ) . '</button>';
92
-
93
- return $notice_out;
94
- }
95
-
96
- $order = false;
97
-
98
- $id_param = 'wcf-order';
99
- $key_param = 'wcf-key';
100
-
101
- if ( isset( $_GET['wcf-opt-order'] ) ) { //phpcs:ignore
102
- $id_param = 'wcf-opt-order';
103
- $key_param = 'wcf-opt-key';
104
- }
105
-
106
- if ( ! isset( $_GET[ $id_param ] ) && wcf()->flow->is_flow_testmode() ) { //phpcs:ignore
107
- $args = array(
108
- 'limit' => 1,
109
- 'order' => 'DESC',
110
- 'post_type' => 'shop_order',
111
- 'status' => array( 'completed', 'processing' ),
112
- );
113
-
114
- $latest_order = wc_get_orders( $args );
115
-
116
- $order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
117
-
118
- if ( $order_id > 0 ) {
119
- $order = wc_get_order( $order_id );
120
-
121
- if ( ! $order ) {
122
- $order = false;
123
- }
124
- }
125
- } else {
126
- if ( ! isset( $_GET[ $id_param ] ) ) { //phpcs:ignore
127
- return '<p class="woocommerce-notice">Order not found. You cannot access this page directly.</p>';
128
- }
129
-
130
- // Get the order.
131
- $order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET[ $id_param ] ) ? 0 : intval( $_GET[ $id_param ] ) ); //phpcs:ignore
132
- $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET[ $key_param ] ) ? '' : wc_clean( wp_unslash( $_GET[ $key_param ] ) ) ); //phpcs:ignore
133
-
134
- if ( $order_id > 0 ) {
135
- $order = wc_get_order( $order_id );
136
-
137
- if ( ! $order || $order->get_order_key() !== $order_key ) {
138
- $order = false;
139
- }
140
- }
141
- }
142
-
143
- // Empty awaiting payment session.
144
- unset( WC()->session->order_awaiting_payment );
145
-
146
- if ( null !== WC()->session ) {
147
- if ( ! isset( WC()->cart ) || '' === WC()->cart ) {
148
- WC()->cart = new WC_Cart();
149
- }
150
-
151
- if ( ! WC()->cart->is_empty() ) {
152
- // wc_empty_cart();
153
- // Empty current cart.
154
- WC()->cart->empty_cart( true );
155
-
156
- wc_clear_notices();
157
- }
158
-
159
- wc_print_notices();
160
- }
161
-
162
- ob_start();
163
- echo "<div class='wcf-thankyou-wrap' id='wcf-thankyou-wrap'>";
164
- wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
165
- echo '</div>';
166
- $output = ob_get_clean();
167
- }
168
-
169
- return $output;
170
- }
171
-
172
- /**
173
- * Load Thank You scripts.
174
- *
175
- * @return void
176
- */
177
- public function thank_you_scripts() {
178
-
179
- if ( _is_wcf_thankyou_type() ) {
180
-
181
- do_action( 'cartflows_thank_you_scripts' );
182
-
183
- $style = $this->generate_thank_you_style();
184
-
185
- wp_add_inline_style( 'wcf-frontend-global', $style );
186
- }
187
- }
188
-
189
- /**
190
- * Load DIVI compatibility Thank You style.
191
- *
192
- * @return void
193
- */
194
- public function add_divi_compatibility_css() {
195
-
196
- global $post;
197
-
198
- $thank_you_id = $post->ID;
199
-
200
- if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
201
- Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $thank_you_id )
202
- ) {
203
- wp_enqueue_style( 'wcf-frontend-global-divi', wcf()->utils->get_css_url( 'frontend-divi' ), array(), CARTFLOWS_VER );
204
- }
205
- }
206
-
207
- /**
208
- * Set thank you as a order received page.
209
- *
210
- * @param boolean $is_order_page order page.
211
- * @return boolean
212
- */
213
- public function set_order_received_page( $is_order_page ) {
214
-
215
- if ( _is_wcf_thankyou_type() ) {
216
- $is_order_page = true;
217
- }
218
-
219
- return $is_order_page;
220
- }
221
-
222
- /**
223
- * Generate Thank You Styles.
224
- *
225
- * @return string
226
- */
227
- public function generate_thank_you_style() {
228
-
229
- global $post;
230
-
231
- if ( _is_wcf_thankyou_type() ) {
232
- $thank_you_id = $post->ID;
233
- } else {
234
- $thank_you_id = _get_wcf_thankyou_id( $post->post_content );
235
- }
236
-
237
- CartFlows_Font_Families::render_fonts( $thank_you_id );
238
-
239
- $text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text-color' );
240
- $text_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-family' );
241
- $text_font_size = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-size' );
242
- $heading_text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-color' );
243
- $heading_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-family' );
244
- $heading_font_weight = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-wt' );
245
- $container_width = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-container-width' );
246
- $section_bg_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-section-bg-color' );
247
-
248
- $show_order_review = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-overview-section' );
249
-
250
- $show_order_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-details-section' );
251
-
252
- $show_billing_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-billing-section' );
253
-
254
- $show_shipping_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-shipping-section' );
255
-
256
- $output = "
257
- .wcf-thankyou-wrap{
258
- color: {$text_color};
259
- font-family: {$text_font_family};
260
- max-width:{$container_width}px;
261
- font-size: {$text_font_size}px;
262
- }
263
-
264
- .woocommerce-order h2.woocommerce-column__title,
265
- .woocommerce-order h2.woocommerce-order-details__title,
266
- .woocommerce-order .woocommerce-thankyou-order-received,
267
- .woocommerce-order-details h2,
268
- .woocommerce-order h2.wc-bacs-bank-details-heading,
269
- .woocommerce-order h2.woocommerce-order-downloads__title {
270
- color: {$heading_text_color};
271
- font-family: {$heading_font_family};
272
- font-weight: {$heading_font_weight};
273
- }
274
-
275
- .woocommerce-order ul.order_details,
276
- .woocommerce-order .woocommerce-order-details,
277
- .woocommerce-order .woocommerce-customer-details,
278
- .woocommerce-order .woocommerce-bacs-bank-details,
279
- .woocommerce-order .woocommerce-order-downloads{
280
- background-color: {$section_bg_color}
281
- }
282
- img.emoji, img.wp-smiley {}
283
- ";
284
-
285
- if ( 'no' == $show_order_review ) {
286
- $output .= '
287
- .woocommerce-order ul.order_details{
288
- display: none;
289
- }
290
- ';
291
- }
292
-
293
- if ( 'no' == $show_order_details ) {
294
- $output .= '
295
- .woocommerce-order .woocommerce-order-details{
296
- display: none;
297
- }
298
- ';
299
- }
300
-
301
- if ( 'no' == $show_billing_details ) {
302
- $output .= '
303
- .woocommerce-order .woocommerce-customer-details .woocommerce-column--billing-address{
304
- display: none;
305
- }
306
- ';
307
- }
308
-
309
- if ( 'no' == $show_shipping_details ) {
310
- $output .= '
311
- .woocommerce-order .woocommerce-customer-details .woocommerce-column--shipping-address{
312
- display: none;
313
- }
314
- ';
315
- }
316
-
317
- if ( 'no' == $show_billing_details && 'no' == $show_shipping_details ) {
318
- $output .= '
319
- .woocommerce-order .woocommerce-customer-details{
320
- display: none;
321
- }
322
- ';
323
- }
324
-
325
- return $output;
326
- }
327
-
328
- /**
329
- * Set as a checkout page if it is thank you page.
330
- * Thank you page need to be set as a checkout page.
331
- * Becauye ayment gateways will not load if it is not checkout.
332
- *
333
- * @param bool $is_checkout is checkout.
334
- *
335
- * @return bool
336
- */
337
- public function woo_checkout_flag( $is_checkout ) {
338
-
339
- if ( ! is_admin() ) {
340
- if ( _is_wcf_thankyou_type() ) {
341
- $is_checkout = true;
342
- }
343
- }
344
-
345
- return $is_checkout;
346
- }
347
-
348
- /**
349
- * Add custom text on thank you page.
350
- *
351
- * @param string $woo_text Default text.
352
- * @param int $order order.
353
- */
354
- public function custom_tq_text( $woo_text, $order ) {
355
-
356
- global $post;
357
-
358
- $thank_you_id = $post->ID;
359
- $new_text = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text' );
360
-
361
- if ( ! empty( $new_text ) ) {
362
- $woo_text = do_shortcode( $new_text );
363
- }
364
-
365
- return $woo_text;
366
- }
367
- }
368
-
369
- /**
370
- * Kicking this off by calling 'get_instance()' method
371
- */
372
- Cartflows_Thankyou_Markup::get_instance();
1
+ <?php
2
+ /**
3
+ * Front end and markup
4
+ *
5
+ * @package CartFlows
6
+ */
7
+
8
+ /**
9
+ * Checkout Markup
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ class Cartflows_Thankyou_Markup {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var object instance
20
+ */
21
+ private static $instance;
22
+
23
+ /**
24
+ * Initiator
25
+ */
26
+ public static function get_instance() {
27
+ if ( ! isset( self::$instance ) ) {
28
+ self::$instance = new self();
29
+ }
30
+ return self::$instance;
31
+ }
32
+
33
+ /**
34
+ * Constructor
35
+ */
36
+ public function __construct() {
37
+
38
+ /* Downsell Shortcode */
39
+ add_shortcode( 'cartflows_order_details', array( $this, 'cartflows_order_details_shortcode_markup' ) );
40
+
41
+ add_action( 'wp_enqueue_scripts', array( $this, 'thank_you_scripts' ), 21 );
42
+
43
+ add_action( 'woocommerce_is_order_received_page', array( $this, 'set_order_received_page' ) );
44
+
45
+ /* Set is checkout flag */
46
+ add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
47
+
48
+ /* Custom redirection of thank you page */
49
+ add_action( 'template_redirect', array( $this, 'redirect_tq_page_to_custom_url' ) );
50
+
51
+ add_action( 'cartflows_thank_you_scripts', array( $this, 'add_divi_compatibility_css' ) );
52
+ }
53
+
54
+ /**
55
+ * Redirect to custom url instead of thank you page.
56
+ */
57
+ public function redirect_tq_page_to_custom_url() {
58
+ global $post;
59
+
60
+ if ( _is_wcf_thankyou_type() ) {
61
+
62
+ $thank_you_id = $post->ID;
63
+ $enable_redirection = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-tq-redirect-section' );
64
+ $redirect_link = wp_http_validate_url( wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-redirect-link' ) );
65
+
66
+ if ( 'yes' === $enable_redirection && ! empty( $redirect_link ) ) {
67
+ exit( wp_redirect( $redirect_link ) ); //phpcs:ignore
68
+ }
69
+ }
70
+ }
71
+ /**
72
+ * Order shortcode markup
73
+ *
74
+ * @param array $atts attributes.
75
+ * @since 1.0.0
76
+ */
77
+ public function cartflows_order_details_shortcode_markup( $atts ) {
78
+
79
+ $output = '';
80
+
81
+ if ( _is_wcf_thankyou_type() ) {
82
+ /* Remove order item link */
83
+ add_filter( 'woocommerce_order_item_permalink', '__return_false' );
84
+
85
+ /* Change order text */
86
+ add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'custom_tq_text' ), 10, 2 );
87
+
88
+ if ( ! function_exists( 'wc_print_notices' ) ) {
89
+
90
+ $notice_out = '<p class="woocommerce-notice">' . __( 'WooCommerce functions do not exist. If you are in an IFrame, please reload it.', 'cartflows' ) . '</p>';
91
+ $notice_out .= '<button onClick="location.reload()">' . __( 'Click Here to Reload', 'cartflows' ) . '</button>';
92
+
93
+ return $notice_out;
94
+ }
95
+
96
+ $order = false;
97
+
98
+ $id_param = 'wcf-order';
99
+ $key_param = 'wcf-key';
100
+
101
+ if ( isset( $_GET['wcf-opt-order'] ) ) { //phpcs:ignore
102
+ $id_param = 'wcf-opt-order';
103
+ $key_param = 'wcf-opt-key';
104
+ }
105
+
106
+ if ( ! isset( $_GET[ $id_param ] ) && wcf()->flow->is_flow_testmode() ) { //phpcs:ignore
107
+ $args = array(
108
+ 'limit' => 1,
109
+ 'order' => 'DESC',
110
+ 'post_type' => 'shop_order',
111
+ 'status' => array( 'completed', 'processing' ),
112
+ );
113
+
114
+ $latest_order = wc_get_orders( $args );
115
+
116
+ $order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
117
+
118
+ if ( $order_id > 0 ) {
119
+ $order = wc_get_order( $order_id );
120
+
121
+ if ( ! $order ) {
122
+ $order = false;
123
+ }
124
+ }
125
+ } else {
126
+ if ( ! isset( $_GET[ $id_param ] ) ) { //phpcs:ignore
127
+ return '<p class="woocommerce-notice">Order not found. You cannot access this page directly.</p>';
128
+ }
129
+
130
+ // Get the order.
131
+ $order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET[ $id_param ] ) ? 0 : intval( $_GET[ $id_param ] ) ); //phpcs:ignore
132
+ $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET[ $key_param ] ) ? '' : wc_clean( wp_unslash( $_GET[ $key_param ] ) ) ); //phpcs:ignore
133
+
134
+ if ( $order_id > 0 ) {
135
+ $order = wc_get_order( $order_id );
136
+
137
+ if ( ! $order || $order->get_order_key() !== $order_key ) {
138
+ $order = false;
139
+ }
140
+ }
141
+ }
142
+
143
+ // Empty awaiting payment session.
144
+ unset( WC()->session->order_awaiting_payment );
145
+
146
+ if ( null !== WC()->session ) {
147
+ if ( ! isset( WC()->cart ) || '' === WC()->cart ) {
148
+ WC()->cart = new WC_Cart();
149
+ }
150
+
151
+ if ( ! WC()->cart->is_empty() ) {
152
+ // wc_empty_cart();
153
+ // Empty current cart.
154
+ WC()->cart->empty_cart( true );
155
+
156
+ wc_clear_notices();
157
+ }
158
+
159
+ wc_print_notices();
160
+ }
161
+
162
+ ob_start();
163
+ echo "<div class='wcf-thankyou-wrap' id='wcf-thankyou-wrap'>";
164
+ wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
165
+ echo '</div>';
166
+ $output = ob_get_clean();
167
+ }
168
+
169
+ return $output;
170
+ }
171
+
172
+ /**
173
+ * Load Thank You scripts.
174
+ *
175
+ * @return void
176
+ */
177
+ public function thank_you_scripts() {
178
+
179
+ if ( _is_wcf_thankyou_type() ) {
180
+
181
+ do_action( 'cartflows_thank_you_scripts' );
182
+
183
+ $style = $this->generate_thank_you_style();
184
+
185
+ wp_add_inline_style( 'wcf-frontend-global', $style );
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Load DIVI compatibility Thank You style.
191
+ *
192
+ * @return void
193
+ */
194
+ public function add_divi_compatibility_css() {
195
+
196
+ global $post;
197
+
198
+ $thank_you_id = $post->ID;
199
+
200
+ if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
201
+ Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $thank_you_id )
202
+ ) {
203
+ wp_enqueue_style( 'wcf-frontend-global-divi', wcf()->utils->get_css_url( 'frontend-divi' ), array(), CARTFLOWS_VER );
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Set thank you as a order received page.
209
+ *
210
+ * @param boolean $is_order_page order page.
211
+ * @return boolean
212
+ */
213
+ public function set_order_received_page( $is_order_page ) {
214
+
215
+ if ( _is_wcf_thankyou_type() ) {
216
+ $is_order_page = true;
217
+ }
218
+
219
+ return $is_order_page;
220
+ }
221
+
222
+ /**
223
+ * Generate Thank You Styles.
224
+ *
225
+ * @return string
226
+ */
227
+ public function generate_thank_you_style() {
228
+
229
+ global $post;
230
+
231
+ if ( _is_wcf_thankyou_type() ) {
232
+ $thank_you_id = $post->ID;
233
+ } else {
234
+ $thank_you_id = _get_wcf_thankyou_id( $post->post_content );
235
+ }
236
+
237
+ CartFlows_Font_Families::render_fonts( $thank_you_id );
238
+
239
+ $text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text-color' );
240
+ $text_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-family' );
241
+ $text_font_size = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-size' );
242
+ $heading_text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-color' );
243
+ $heading_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-family' );
244
+ $heading_font_weight = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-wt' );
245
+ $container_width = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-container-width' );
246
+ $section_bg_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-section-bg-color' );
247
+
248
+ $show_order_review = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-overview-section' );
249
+
250
+ $show_order_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-details-section' );
251
+
252
+ $show_billing_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-billing-section' );
253
+
254
+ $show_shipping_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-shipping-section' );
255
+
256
+ $output = "
257
+ .wcf-thankyou-wrap{
258
+ color: {$text_color};
259
+ font-family: {$text_font_family};
260
+ max-width:{$container_width}px;
261
+ font-size: {$text_font_size}px;
262
+ }
263
+
264
+ .woocommerce-order h2.woocommerce-column__title,
265
+ .woocommerce-order h2.woocommerce-order-details__title,
266
+ .woocommerce-order .woocommerce-thankyou-order-received,
267
+ .woocommerce-order-details h2,
268
+ .woocommerce-order h2.wc-bacs-bank-details-heading,
269
+ .woocommerce-order h2.woocommerce-order-downloads__title {
270
+ color: {$heading_text_color};
271
+ font-family: {$heading_font_family};
272
+ font-weight: {$heading_font_weight};
273
+ }
274
+
275
+ .woocommerce-order ul.order_details,
276
+ .woocommerce-order .woocommerce-order-details,
277
+ .woocommerce-order .woocommerce-customer-details,
278
+ .woocommerce-order .woocommerce-bacs-bank-details,
279
+ .woocommerce-order .woocommerce-order-downloads{
280
+ background-color: {$section_bg_color}
281
+ }
282
+ img.emoji, img.wp-smiley {}
283
+ ";
284
+
285
+ if ( 'no' == $show_order_review ) {
286
+ $output .= '
287
+ .woocommerce-order ul.order_details{
288
+ display: none;
289
+ }
290
+ ';
291
+ }
292
+
293
+ if ( 'no' == $show_order_details ) {
294
+ $output .= '
295
+ .woocommerce-order .woocommerce-order-details{
296
+ display: none;
297
+ }
298
+ ';
299
+ }
300
+
301
+ if ( 'no' == $show_billing_details ) {
302
+ $output .= '
303
+ .woocommerce-order .woocommerce-customer-details .woocommerce-column--billing-address{
304
+ display: none;
305
+ }
306
+ ';
307
+ }
308
+
309
+ if ( 'no' == $show_shipping_details ) {
310
+ $output .= '
311
+ .woocommerce-order .woocommerce-customer-details .woocommerce-column--shipping-address{
312
+ display: none;
313
+ }
314
+ ';
315
+ }
316
+
317
+ if ( 'no' == $show_billing_details && 'no' == $show_shipping_details ) {
318
+ $output .= '
319
+ .woocommerce-order .woocommerce-customer-details{
320
+ display: none;
321
+ }
322
+ ';
323
+ }
324
+
325
+ return $output;
326
+ }
327
+
328
+ /**
329
+ * Set as a checkout page if it is thank you page.
330
+ * Thank you page need to be set as a checkout page.
331
+ * Becauye ayment gateways will not load if it is not checkout.
332
+ *
333
+ * @param bool $is_checkout is checkout.
334
+ *
335
+ * @return bool
336
+ */
337
+ public function woo_checkout_flag( $is_checkout ) {
338
+
339
+ if ( ! is_admin() ) {
340
+ if ( _is_wcf_thankyou_type() ) {
341
+ $is_checkout = true;
342
+ }
343
+ }
344
+
345
+ return $is_checkout;
346
+ }
347
+
348
+ /**
349
+ * Add custom text on thank you page.
350
+ *
351
+ * @param string $woo_text Default text.
352
+ * @param int $order order.
353
+ */
354
+ public function custom_tq_text( $woo_text, $order ) {
355
+
356
+ global $post;
357
+
358
+ $thank_you_id = $post->ID;
359
+ $new_text = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text' );
360
+
361
+ if ( ! empty( $new_text ) ) {
362
+ $woo_text = do_shortcode( $new_text );
363
+ }
364
+
365
+ return $woo_text;
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Kicking this off by calling 'get_instance()' method
371
+ */
372
+ Cartflows_Thankyou_Markup::get_instance();
modules/thankyou/classes/class-cartflows-thankyou-meta.php CHANGED
@@ -1,423 +1,423 @@
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
- public 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
- public 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
- public 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' => __( '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' => __( 'Edit 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' => __( 'Settings', 'cartflows' ),
149
- 'id' => 'wcf-thankyou-redirect',
150
- 'class' => 'wcf-thankyou-redirect' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
- 'icon' => 'dashicons-randomize',
152
- ),
153
- array(
154
- 'title' => __( 'Custom Script', 'cartflows' ),
155
- 'id' => 'wcf-thankyou-custom-script-header',
156
- 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
157
- 'icon' => 'dashicons-format-aside',
158
- ),
159
- );
160
-
161
- ?>
162
- <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
163
- <div class="wcf-table-container">
164
- <div class="wcf-column-left">
165
- <div class="wcf-tab-wrapper">
166
-
167
- <?php foreach ( $tabs as $key => $tab ) { ?>
168
- <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
169
- <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
170
- <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
171
- </div>
172
- <?php } ?>
173
- <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
174
-
175
- </div>
176
- </div>
177
- <div class="wcf-column-right">
178
- <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
179
- <?php
180
- echo wcf()->meta->get_shortcode_field(
181
- array(
182
- 'label' => __( 'Order Details', 'cartflows' ),
183
- 'name' => 'wcf-order-details',
184
- 'content' => esc_html( '[cartflows_order_details]' ),
185
- )
186
- );
187
- ?>
188
- </div>
189
- <div class="wcf-thankyou-design wcf-tab-content widefat">
190
- <?php
191
-
192
- echo wcf()->meta->get_section(
193
- array(
194
- 'label' => __( 'Text', 'cartflows' ),
195
- )
196
- );
197
-
198
- echo wcf()->meta->get_color_picker_field(
199
- array(
200
- 'label' => __( 'Color', 'cartflows' ),
201
- 'name' => 'wcf-tq-text-color',
202
- 'value' => $options['wcf-tq-text-color'],
203
- )
204
- );
205
-
206
- echo wcf()->meta->get_font_family_field(
207
- array(
208
- 'for' => 'wcf-tq-font-family',
209
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
210
- 'name' => 'wcf-tq-font-family',
211
- 'value' => $options['wcf-tq-font-family'],
212
- )
213
- );
214
-
215
- echo wcf()->meta->get_number_field(
216
- array(
217
- 'label' => __( 'Font Size', 'cartflows' ),
218
- 'name' => 'wcf-tq-font-size',
219
- 'value' => $options['wcf-tq-font-size'],
220
- )
221
- );
222
-
223
- echo wcf()->meta->get_section(
224
- array(
225
- 'label' => __( 'Heading', 'cartflows' ),
226
- )
227
- );
228
-
229
- echo wcf()->meta->get_color_picker_field(
230
- array(
231
- 'label' => __( 'Color', 'cartflows' ),
232
- 'name' => 'wcf-tq-heading-color',
233
- 'value' => $options['wcf-tq-heading-color'],
234
- )
235
- );
236
-
237
- echo wcf()->meta->get_font_family_field(
238
- array(
239
- 'for' => 'wcf-tq-heading-font-family',
240
- 'label' => esc_html__( 'Font Family', 'cartflows' ),
241
- 'name' => 'wcf-tq-heading-font-family',
242
- 'value' => $options['wcf-tq-heading-font-family'],
243
- )
244
- );
245
-
246
- echo wcf()->meta->get_font_weight_field(
247
- array(
248
- 'for' => 'wcf-tq-heading-font-family',
249
- 'label' => esc_html__( 'Font Weight', 'cartflows' ),
250
- 'name' => 'wcf-tq-heading-font-wt',
251
- 'value' => $options['wcf-tq-heading-font-wt'],
252
- )
253
- );
254
-
255
- echo wcf()->meta->get_checkbox_field(
256
- array(
257
- 'label' => __( 'Advanced Options', 'cartflows' ),
258
- 'name' => 'wcf-tq-advance-options-fields',
259
- 'value' => $options['wcf-tq-advance-options-fields'],
260
- 'after' => 'Enable',
261
- )
262
- );
263
-
264
- echo wcf()->meta->get_number_field(
265
- array(
266
- 'for' => 'wcf-heading',
267
- 'label' => esc_html__( 'Container Width (In px)', 'cartflows' ),
268
- 'name' => 'wcf-tq-container-width',
269
- 'value' => $options['wcf-tq-container-width'],
270
- )
271
- );
272
-
273
- echo wcf()->meta->get_color_picker_field(
274
- array(
275
- 'label' => __( 'Section Background Color', 'cartflows' ),
276
- 'name' => 'wcf-tq-section-bg-color',
277
- 'value' => $options['wcf-tq-section-bg-color'],
278
- )
279
- );
280
-
281
- ?>
282
- </div>
283
- <div class="wcf-thankyou-fields wcf-tab-content widefat">
284
- <?php
285
- echo wcf()->meta->get_checkbox_field(
286
- array(
287
- 'name' => 'wcf-show-overview-section',
288
- 'value' => $options['wcf-show-overview-section'],
289
- 'after' => esc_html__( 'Enable Order Overview ', 'cartflows' ),
290
- )
291
- );
292
-
293
- echo wcf()->meta->get_checkbox_field(
294
- array(
295
- 'name' => 'wcf-show-details-section',
296
- 'value' => $options['wcf-show-details-section'],
297
- 'after' => esc_html__( 'Enable Order Details ', 'cartflows' ),
298
- )
299
- );
300
-
301
- echo wcf()->meta->get_checkbox_field(
302
- array(
303
- 'name' => 'wcf-show-billing-section',
304
- 'value' => $options['wcf-show-billing-section'],
305
- 'after' => esc_html__( 'Enable Billing Details ', 'cartflows' ),
306
- )
307
- );
308
-
309
- echo wcf()->meta->get_checkbox_field(
310
- array(
311
- 'name' => 'wcf-show-shipping-section',
312
- 'value' => $options['wcf-show-shipping-section'],
313
- 'after' => esc_html__( 'Enable Shipping Details ', 'cartflows' ),
314
- )
315
- );
316
-
317
- echo wcf()->meta->get_hidden_field(
318
- array(
319
- 'name' => 'wcf-field-google-font-url',
320
- 'value' => $options['wcf-field-google-font-url'],
321
- )
322
- );
323
- ?>
324
- </div>
325
- <div class="wcf-thankyou-redirect wcf-tab-content widefat" >
326
- <?php
327
- echo wcf()->meta->get_text_field(
328
- array(
329
- 'label' => __( 'Thank You Page Text', 'cartflows' ),
330
- 'name' => 'wcf-tq-text',
331
- 'value' => $options['wcf-tq-text'],
332
- 'attr' => array(
333
- 'placeholder' => __( 'Thank you. Your order has been received.', 'cartflows' ),
334
- ),
335
- 'help' => __( 'It will change the default text on thank you page.', 'cartflows' ),
336
- )
337
- );
338
-
339
- echo wcf()->meta->get_hr_line_field( array() );
340
-
341
- echo wcf()->meta->get_checkbox_field(
342
- array(
343
- 'label' => __( 'Redirect After Purchase', 'cartflows' ),
344
- 'name' => 'wcf-show-tq-redirect-section',
345
- 'value' => $options['wcf-show-tq-redirect-section'],
346
- 'after' => 'Enable',
347
- )
348
- );
349
-
350
- echo wcf()->meta->get_text_field(
351
- array(
352
- 'label' => __( 'Redirect Link', 'cartflows' ),
353
- 'name' => 'wcf-tq-redirect-link',
354
- 'value' => $options['wcf-tq-redirect-link'],
355
- 'attr' => array(
356
- 'placeholder' => __( 'https://', 'cartflows' ),
357
- ),
358
- )
359
- );
360
-
361
- ?>
362
- </div>
363
-
364
- <?php $this->tab_custom_script( $options, $post_id ); ?>
365
-
366
- <?php $this->right_column_footer( $options, $post_id ); ?>
367
- </div>
368
- </div>
369
- </div>
370
-
371
- <?php
372
-
373
- }
374
-
375
- /**
376
- * Get metabox options
377
- *
378
- * @param int $post_id post ID.
379
- * @return array
380
- */
381
- public static function get_meta_option( $post_id ) {
382
-
383
- if ( null === self::$meta_option ) {
384
-
385
- /**
386
- * Set metabox options
387
- *
388
- * @see http://php.net/manual/en/filter.filters.sanitize.php
389
- */
390
- self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
391
- }
392
-
393
- return self::$meta_option;
394
-
395
- }
396
-
397
- /**
398
- * Metabox Save
399
- *
400
- * @param number $post_id Post ID.
401
- * @return void
402
- */
403
- public function save_meta_box( $post_id ) {
404
-
405
- // Checks save status.
406
- $is_autosave = wp_is_post_autosave( $post_id );
407
- $is_revision = wp_is_post_revision( $post_id );
408
-
409
- $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-thankyou-step-meta'] ) ), 'save-nonce-thankyou-step-meta' ) ) ? true : false;
410
-
411
- // Exits script depending on save status.
412
- if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
413
- return;
414
- }
415
-
416
- wcf()->options->save_thankyou_fields( $post_id );
417
- }
418
- }
419
-
420
- /**
421
- * Kicking this off by calling 'get_instance()' method
422
- */
423
- 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
+ public 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
+ public 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
+ public 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' => __( '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' => __( 'Edit 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' => __( 'Settings', 'cartflows' ),
149
+ 'id' => 'wcf-thankyou-redirect',
150
+ 'class' => 'wcf-thankyou-redirect' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
151
+ 'icon' => 'dashicons-randomize',
152
+ ),
153
+ array(
154
+ 'title' => __( 'Custom Script', 'cartflows' ),
155
+ 'id' => 'wcf-thankyou-custom-script-header',
156
+ 'class' => 'wcf-thankyou-custom-script-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
157
+ 'icon' => 'dashicons-format-aside',
158
+ ),
159
+ );
160
+
161
+ ?>
162
+ <div class="wcf-thankyou-table wcf-metabox-wrap widefat">
163
+ <div class="wcf-table-container">
164
+ <div class="wcf-column-left">
165
+ <div class="wcf-tab-wrapper">
166
+
167
+ <?php foreach ( $tabs as $key => $tab ) { ?>
168
+ <div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
169
+ <span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
170
+ <span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
171
+ </div>
172
+ <?php } ?>
173
+ <input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
174
+
175
+ </div>
176
+ </div>
177
+ <div class="wcf-column-right">
178
+ <div class="wcf-thankyou-shortcodes wcf-tab-content active widefat">
179
+ <?php
180
+ echo wcf()->meta->get_shortcode_field(
181
+ array(
182
+ 'label' => __( 'Order Details', 'cartflows' ),
183
+ 'name' => 'wcf-order-details',
184
+ 'content' => esc_html( '[cartflows_order_details]' ),
185
+ )
186
+ );
187
+ ?>
188
+ </div>
189
+ <div class="wcf-thankyou-design wcf-tab-content widefat">
190
+ <?php
191
+
192
+ echo wcf()->meta->get_section(
193
+ array(
194
+ 'label' => __( 'Text', 'cartflows' ),
195
+ )
196
+ );
197
+
198
+ echo wcf()->meta->get_color_picker_field(
199
+ array(
200
+ 'label' => __( 'Color', 'cartflows' ),
201
+ 'name' => 'wcf-tq-text-color',
202
+ 'value' => $options['wcf-tq-text-color'],
203
+ )
204
+ );
205
+
206
+ echo wcf()->meta->get_font_family_field(
207
+ array(
208
+ 'for' => 'wcf-tq-font-family',
209
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
210
+ 'name' => 'wcf-tq-font-family',
211
+ 'value' => $options['wcf-tq-font-family'],
212
+ )
213
+ );
214
+
215
+ echo wcf()->meta->get_number_field(
216
+ array(
217
+ 'label' => __( 'Font Size', 'cartflows' ),
218
+ 'name' => 'wcf-tq-font-size',
219
+ 'value' => $options['wcf-tq-font-size'],
220
+ )
221
+ );
222
+
223
+ echo wcf()->meta->get_section(
224
+ array(
225
+ 'label' => __( 'Heading', 'cartflows' ),
226
+ )
227
+ );
228
+
229
+ echo wcf()->meta->get_color_picker_field(
230
+ array(
231
+ 'label' => __( 'Color', 'cartflows' ),
232
+ 'name' => 'wcf-tq-heading-color',
233
+ 'value' => $options['wcf-tq-heading-color'],
234
+ )
235
+ );
236
+
237
+ echo wcf()->meta->get_font_family_field(
238
+ array(
239
+ 'for' => 'wcf-tq-heading-font-family',
240
+ 'label' => esc_html__( 'Font Family', 'cartflows' ),
241
+ 'name' => 'wcf-tq-heading-font-family',
242
+ 'value' => $options['wcf-tq-heading-font-family'],
243
+ )
244
+ );
245
+
246
+ echo wcf()->meta->get_font_weight_field(
247
+ array(
248
+ 'for' => 'wcf-tq-heading-font-family',
249
+ 'label' => esc_html__( 'Font Weight', 'cartflows' ),
250
+ 'name' => 'wcf-tq-heading-font-wt',
251
+ 'value' => $options['wcf-tq-heading-font-wt'],
252
+ )
253
+ );
254
+
255
+ echo wcf()->meta->get_checkbox_field(
256
+ array(
257
+ 'label' => __( 'Advanced Options', 'cartflows' ),
258
+ 'name' => 'wcf-tq-advance-options-fields',
259
+ 'value' => $options['wcf-tq-advance-options-fields'],
260
+ 'after' => 'Enable',
261
+ )
262
+ );
263
+
264
+ echo wcf()->meta->get_number_field(
265
+ array(
266
+ 'for' => 'wcf-heading',
267
+ 'label' => esc_html__( 'Container Width (In px)', 'cartflows' ),
268
+ 'name' => 'wcf-tq-container-width',
269
+ 'value' => $options['wcf-tq-container-width'],
270
+ )
271
+ );
272
+
273
+ echo wcf()->meta->get_color_picker_field(
274
+ array(
275
+ 'label' => __( 'Section Background Color', 'cartflows' ),
276
+ 'name' => 'wcf-tq-section-bg-color',
277
+ 'value' => $options['wcf-tq-section-bg-color'],
278
+ )
279
+ );
280
+
281
+ ?>
282
+ </div>
283
+ <div class="wcf-thankyou-fields wcf-tab-content widefat">
284
+ <?php
285
+ echo wcf()->meta->get_checkbox_field(
286
+ array(
287
+ 'name' => 'wcf-show-overview-section',
288
+ 'value' => $options['wcf-show-overview-section'],
289
+ 'after' => esc_html__( 'Enable Order Overview ', 'cartflows' ),
290
+ )
291
+ );
292
+
293
+ echo wcf()->meta->get_checkbox_field(
294
+ array(
295
+ 'name' => 'wcf-show-details-section',
296
+ 'value' => $options['wcf-show-details-section'],
297
+ 'after' => esc_html__( 'Enable Order Details ', 'cartflows' ),
298
+ )
299
+ );
300
+
301
+ echo wcf()->meta->get_checkbox_field(
302
+ array(
303
+ 'name' => 'wcf-show-billing-section',
304
+ 'value' => $options['wcf-show-billing-section'],
305
+ 'after' => esc_html__( 'Enable Billing Details ', 'cartflows' ),
306
+ )
307
+ );
308
+
309
+ echo wcf()->meta->get_checkbox_field(
310
+ array(
311
+ 'name' => 'wcf-show-shipping-section',
312
+ 'value' => $options['wcf-show-shipping-section'],
313
+ 'after' => esc_html__( 'Enable Shipping Details ', 'cartflows' ),
314
+ )
315
+ );
316
+
317
+ echo wcf()->meta->get_hidden_field(
318
+ array(
319
+ 'name' => 'wcf-field-google-font-url',
320
+ 'value' => $options['wcf-field-google-font-url'],
321
+ )
322
+ );
323
+ ?>
324
+ </div>
325
+ <div class="wcf-thankyou-redirect wcf-tab-content widefat" >
326
+ <?php
327
+ echo wcf()->meta->get_text_field(
328
+ array(
329
+ 'label' => __( 'Thank You Page Text', 'cartflows' ),
330
+ 'name' => 'wcf-tq-text',
331
+ 'value' => $options['wcf-tq-text'],
332
+ 'attr' => array(
333
+ 'placeholder' => __( 'Thank you. Your order has been received.', 'cartflows' ),
334
+ ),
335
+ 'help' => __( 'It will change the default text on thank you page.', 'cartflows' ),
336
+ )
337
+ );
338
+
339
+ echo wcf()->meta->get_hr_line_field( array() );
340
+
341
+ echo wcf()->meta->get_checkbox_field(
342
+ array(
343
+ 'label' => __( 'Redirect After Purchase', 'cartflows' ),
344
+ 'name' => 'wcf-show-tq-redirect-section',
345
+ 'value' => $options['wcf-show-tq-redirect-section'],
346
+ 'after' => 'Enable',
347
+ )
348
+ );
349
+
350
+ echo wcf()->meta->get_text_field(
351
+ array(
352
+ 'label' => __( 'Redirect Link', 'cartflows' ),
353
+ 'name' => 'wcf-tq-redirect-link',
354
+ 'value' => $options['wcf-tq-redirect-link'],
355
+ 'attr' => array(
356
+ 'placeholder' => __( 'https://', 'cartflows' ),
357
+ ),
358
+ )
359
+ );
360
+
361
+ ?>
362
+ </div>
363
+
364
+ <?php $this->tab_custom_script( $options, $post_id ); ?>
365
+
366
+ <?php $this->right_column_footer( $options, $post_id ); ?>
367
+ </div>
368
+ </div>
369
+ </div>
370
+
371
+ <?php
372
+
373
+ }
374
+
375
+ /**
376
+ * Get metabox options
377
+ *
378
+ * @param int $post_id post ID.
379
+ * @return array
380
+ */
381
+ public static function get_meta_option( $post_id ) {
382
+
383
+ if ( null === self::$meta_option ) {
384
+
385
+ /**
386
+ * Set metabox options
387
+ *
388
+ * @see http://php.net/manual/en/filter.filters.sanitize.php
389
+ */
390
+ self::$meta_option = wcf()->options->get_thankyou_fields( $post_id );
391
+ }
392
+
393
+ return self::$meta_option;
394
+
395
+ }
396
+
397
+ /**
398
+ * Metabox Save
399
+ *
400
+ * @param number $post_id Post ID.
401
+ * @return void
402
+ */
403
+ public function save_meta_box( $post_id ) {
404
+
405
+ // Checks save status.
406
+ $is_autosave = wp_is_post_autosave( $post_id );
407
+ $is_revision = wp_is_post_revision( $post_id );
408
+
409
+ $is_valid_nonce = ( isset( $_POST['nonce-thankyou-step-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-thankyou-step-meta'] ) ), 'save-nonce-thankyou-step-meta' ) ) ? true : false;
410
+
411
+ // Exits script depending on save status.
412
+ if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
413
+ return;
414
+ }
415
+
416
+ wcf()->options->save_thankyou_fields( $post_id );
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Kicking this off by calling 'get_instance()' method
422
+ */
423
+ Cartflows_Thankyou_Meta::get_instance();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: woocommerce, funnel builder, sales funnels, elementor, beaver builder
5
  Requires at least: 4.4
6
  Tested up to: 5.3.2
7
- Stable tag: 1.5.1
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -125,6 +125,13 @@ Glad you asked! CartFlows Pro is an optional add-on to CartFlows that adds addit
125
 
126
  == Changelog ==
127
 
 
 
 
 
 
 
 
128
  = Version 1.5.1 - Thursday, 12th March 2020 =
129
  * Improvement: WooCommerce version 4.0.0 compatibility tested.
130
 
4
  Tags: woocommerce, funnel builder, sales funnels, elementor, beaver builder
5
  Requires at least: 4.4
6
  Tested up to: 5.3.2
7
+ Stable tag: 1.5.2
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
125
 
126
  == Changelog ==
127
 
128
+ = Version 1.5.2 - Wednesday, 18th March 2020 =
129
+ * New: Added an option to enable Facebook pixel's Pageview event on the whole site.
130
+ * Improvement: Added compatibility for the Pro theme.
131
+ * Improvement: Added compatibility for the Kallyas theme.
132
+ * Improvement: Added compatibility for a future release of CartFlows Pro.
133
+ * Fix: Dynamic CSS was not working properly in some DIVI cases.
134
+
135
  = Version 1.5.1 - Thursday, 12th March 2020 =
136
  * Improvement: WooCommerce version 4.0.0 compatibility tested.
137