Version Description
Download this release
Release Info
Developer | Nikschavan |
Plugin | Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress |
Version | 1.1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.1.0 to 1.1.0.1
- cartflows.php +24 -24
- changelog.txt +3 -0
- classes/class-cartflows-admin-fields.php +157 -157
- classes/class-cartflows-admin.php +398 -398
- classes/class-cartflows-frontend.php +322 -325
- classes/class-cartflows-importer.php +1038 -1038
- classes/class-cartflows-loader.php +416 -416
- classes/class-cartflows-meta-fields.php +962 -962
- modules/checkout/classes/class-cartflows-checkout-markup.php +942 -942
- modules/checkout/classes/class-cartflows-checkout-meta.php +759 -759
- modules/flow/classes/class-cartflows-step-post-type.php +449 -449
- modules/flow/view/meta-flow-steps.php +168 -168
- modules/thankyou/classes/class-cartflows-thankyou-markup.php +260 -260
- readme.txt +76 -2
cartflows.php
CHANGED
@@ -1,24 +1,24 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Plugin Name: CartFlows
|
4 |
-
* Plugin URI: https://cartflows.com/
|
5 |
-
* Description: Create beautiful checkout pages & sales flows for WooCommerce.
|
6 |
-
* Version: 1.1.0
|
7 |
-
* Author: CartFlows Inc
|
8 |
-
* Author URI: https://cartflows.com/
|
9 |
-
* Text Domain: cartflows
|
10 |
-
* WC requires at least: 3.0
|
11 |
-
* WC tested up to: 3.5.1
|
12 |
-
*
|
13 |
-
* @package CartFlows
|
14 |
-
*/
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Set constants.
|
18 |
-
*/
|
19 |
-
define( 'CARTFLOWS_FILE', __FILE__ );
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Extensions
|
23 |
-
*/
|
24 |
-
require_once 'classes/class-cartflows-loader.php';
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: CartFlows
|
4 |
+
* Plugin URI: https://cartflows.com/
|
5 |
+
* Description: Create beautiful checkout pages & sales flows for WooCommerce.
|
6 |
+
* Version: 1.1.0.1
|
7 |
+
* Author: CartFlows Inc
|
8 |
+
* Author URI: https://cartflows.com/
|
9 |
+
* Text Domain: cartflows
|
10 |
+
* WC requires at least: 3.0
|
11 |
+
* WC tested up to: 3.5.1
|
12 |
+
*
|
13 |
+
* @package CartFlows
|
14 |
+
*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Set constants.
|
18 |
+
*/
|
19 |
+
define( 'CARTFLOWS_FILE', __FILE__ );
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Extensions
|
23 |
+
*/
|
24 |
+
require_once 'classes/class-cartflows-loader.php';
|
changelog.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
Version 1.1.0 - Wednesday, 5th December 2018
|
2 |
- New: Ready for Order Bump Positions.
|
3 |
- Improvement: PixelYourSite compatibility added.
|
1 |
+
Version 1.1.0.1 - Friday, 7th December 2018
|
2 |
+
- Fix: Checkout breaking issue.
|
3 |
+
|
4 |
Version 1.1.0 - Wednesday, 5th December 2018
|
5 |
- New: Ready for Order Bump Positions.
|
6 |
- Improvement: PixelYourSite compatibility added.
|
classes/class-cartflows-admin-fields.php
CHANGED
@@ -1,157 +1,157 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* CARTFLOWS Admin Fields.
|
4 |
-
*
|
5 |
-
* @package CARTFLOWS
|
6 |
-
*/
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class Cartflows_Admin_Fields.
|
10 |
-
*/
|
11 |
-
class Cartflows_Admin_Fields {
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Text Field
|
15 |
-
*
|
16 |
-
* @param array $args Args.
|
17 |
-
* @return string
|
18 |
-
*/
|
19 |
-
static public function text_field( $args ) {
|
20 |
-
|
21 |
-
$id = $args['id'];
|
22 |
-
$name = $args['name'];
|
23 |
-
$title = $args['title'];
|
24 |
-
$value = $args['value'];
|
25 |
-
|
26 |
-
$output = '<div class="form-field">';
|
27 |
-
$output .= '<label for="' . $id . '">' . $title . '</label>';
|
28 |
-
$output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_attr( $value ) . '">';
|
29 |
-
$output .= '</div>';
|
30 |
-
|
31 |
-
return $output;
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* URL Field
|
36 |
-
*
|
37 |
-
* @param array $args Args.
|
38 |
-
* @return string
|
39 |
-
*/
|
40 |
-
static public function url_field( $args ) {
|
41 |
-
|
42 |
-
$id = $args['id'];
|
43 |
-
$name = $args['name'];
|
44 |
-
$title = $args['title'];
|
45 |
-
$value = $args['value'];
|
46 |
-
|
47 |
-
$output = '<div class="form-field">';
|
48 |
-
$output .= '<label for="' . $id . '">' . $title . '</label>';
|
49 |
-
$output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_url( $value ) . '">';
|
50 |
-
$output .= '</div>';
|
51 |
-
|
52 |
-
return $output;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Checkbox Field
|
57 |
-
*
|
58 |
-
* @param array $args Args.
|
59 |
-
* @return string
|
60 |
-
*/
|
61 |
-
static public function checkobox_field( $args ) {
|
62 |
-
|
63 |
-
$id = $args['id'];
|
64 |
-
$name = $args['name'];
|
65 |
-
$title = $args['title'];
|
66 |
-
$value = $args['value'];
|
67 |
-
|
68 |
-
$output = '<div class="form-field">';
|
69 |
-
$output .= '<label for="' . $id . '">';
|
70 |
-
$output .= '<input type="hidden" id="wcf_hid_' . $id . '" name="' . $name . '" value="disable">';
|
71 |
-
$output .= '<input type="checkbox" id="wcf_' . $id . '" name="' . $name . '" value="enable" ' . checked( $value, 'enable', false ) . '>';
|
72 |
-
$output .= $title;
|
73 |
-
$output .= '</label>';
|
74 |
-
$output .= '</div>';
|
75 |
-
|
76 |
-
return $output;
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Checkout Selection Field
|
81 |
-
*
|
82 |
-
* @param array $args Args.
|
83 |
-
* @return string
|
84 |
-
*/
|
85 |
-
static public function flow_checkout_selection_field( $args ) {
|
86 |
-
|
87 |
-
$id = $args['id'];
|
88 |
-
$name = $args['name'];
|
89 |
-
$title = $args['title'];
|
90 |
-
$value = $args['value'];
|
91 |
-
|
92 |
-
$checkout_steps = get_posts(
|
93 |
-
array(
|
94 |
-
'posts_per_page' => -1,
|
95 |
-
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
96 |
-
'post_status' => 'publish',
|
97 |
-
'orderby' => 'ID',
|
98 |
-
'order' => 'ASC',
|
99 |
-
'tax_query' => array(
|
100 |
-
array(
|
101 |
-
'taxonomy' => CARTFLOWS_TAXONOMY_STEP_TYPE,
|
102 |
-
'field' => 'slug',
|
103 |
-
'terms' => 'checkout',
|
104 |
-
),
|
105 |
-
),
|
106 |
-
)
|
107 |
-
);
|
108 |
-
|
109 |
-
$output = '<div class="form-field">';
|
110 |
-
|
111 |
-
$output .= '<div class="form-field-label">';
|
112 |
-
$output .= '<label for="' . $id . '">';
|
113 |
-
$output .= $title;
|
114 |
-
$output .= '</label>';
|
115 |
-
$output .= '</div>';
|
116 |
-
|
117 |
-
$output .= '<div class="form-field-data">';
|
118 |
-
$output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
|
119 |
-
|
120 |
-
if ( ! empty( $checkout_steps ) ) {
|
121 |
-
$output .= '<option value="">' . __( 'Select', 'cartflows' ) . '</option>';
|
122 |
-
} else {
|
123 |
-
|
124 |
-
$output .= '<option value="">' . __( 'No Checkout Steps', 'cartflows' ) . '</option>';
|
125 |
-
}
|
126 |
-
|
127 |
-
foreach ( $checkout_steps as $index => $step_data ) {
|
128 |
-
|
129 |
-
$output .= '<option value="' . $step_data->ID . '" ' . selected( $value, $step_data->ID, false ) . '>' . $step_data->post_title . ' (#' . $step_data->ID . ') </option>';
|
130 |
-
}
|
131 |
-
|
132 |
-
$output .= '</select>';
|
133 |
-
$output .= '</div>';
|
134 |
-
|
135 |
-
if ( '' !== $value ) {
|
136 |
-
$output .= '<div class="form-field-actions">';
|
137 |
-
$output .= '<a href="' . get_edit_post_link( $value ) . '" target="_blank" class="" title="Edit">';
|
138 |
-
$output .= '<span class="dashicons dashicons-edit"></span>';
|
139 |
-
$output .= '<span class="">Edit</span>';
|
140 |
-
$output .= '</a>';
|
141 |
-
$output .= '<a href="' . get_permalink( $value ) . '" target="_blank" class="" title="View">';
|
142 |
-
$output .= '<span class="dashicons dashicons-visibility"></span>';
|
143 |
-
$output .= '<span class="">View</span>';
|
144 |
-
$output .= '</a>';
|
145 |
-
$output .= '</div>';
|
146 |
-
}
|
147 |
-
|
148 |
-
$output .= '<div class="form-field-desc">';
|
149 |
-
/* translators: %s: link */
|
150 |
-
$output .= '<p>' . sprintf( __( 'Be sure not to add any product in above selected Global Checkout step. Please read information about how to set up Global Checkout %1$shere%2$s.', 'cartflows' ), '<a href="https://cartflows.com/docs/global-checkout/" target="_blank">', '</a>' ) . '</p>';
|
151 |
-
$output .= '</div>';
|
152 |
-
|
153 |
-
$output .= '</div>';
|
154 |
-
|
155 |
-
return $output;
|
156 |
-
}
|
157 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CARTFLOWS Admin Fields.
|
4 |
+
*
|
5 |
+
* @package CARTFLOWS
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class Cartflows_Admin_Fields.
|
10 |
+
*/
|
11 |
+
class Cartflows_Admin_Fields {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Text Field
|
15 |
+
*
|
16 |
+
* @param array $args Args.
|
17 |
+
* @return string
|
18 |
+
*/
|
19 |
+
static public function text_field( $args ) {
|
20 |
+
|
21 |
+
$id = $args['id'];
|
22 |
+
$name = $args['name'];
|
23 |
+
$title = $args['title'];
|
24 |
+
$value = $args['value'];
|
25 |
+
|
26 |
+
$output = '<div class="form-field">';
|
27 |
+
$output .= '<label for="' . $id . '">' . $title . '</label>';
|
28 |
+
$output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_attr( $value ) . '">';
|
29 |
+
$output .= '</div>';
|
30 |
+
|
31 |
+
return $output;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* URL Field
|
36 |
+
*
|
37 |
+
* @param array $args Args.
|
38 |
+
* @return string
|
39 |
+
*/
|
40 |
+
static public function url_field( $args ) {
|
41 |
+
|
42 |
+
$id = $args['id'];
|
43 |
+
$name = $args['name'];
|
44 |
+
$title = $args['title'];
|
45 |
+
$value = $args['value'];
|
46 |
+
|
47 |
+
$output = '<div class="form-field">';
|
48 |
+
$output .= '<label for="' . $id . '">' . $title . '</label>';
|
49 |
+
$output .= '<input type="text" name="' . $name . '" id="' . $id . '" class="placeholder placeholder-active" value="' . esc_url( $value ) . '">';
|
50 |
+
$output .= '</div>';
|
51 |
+
|
52 |
+
return $output;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Checkbox Field
|
57 |
+
*
|
58 |
+
* @param array $args Args.
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
static public function checkobox_field( $args ) {
|
62 |
+
|
63 |
+
$id = $args['id'];
|
64 |
+
$name = $args['name'];
|
65 |
+
$title = $args['title'];
|
66 |
+
$value = $args['value'];
|
67 |
+
|
68 |
+
$output = '<div class="form-field">';
|
69 |
+
$output .= '<label for="' . $id . '">';
|
70 |
+
$output .= '<input type="hidden" id="wcf_hid_' . $id . '" name="' . $name . '" value="disable">';
|
71 |
+
$output .= '<input type="checkbox" id="wcf_' . $id . '" name="' . $name . '" value="enable" ' . checked( $value, 'enable', false ) . '>';
|
72 |
+
$output .= $title;
|
73 |
+
$output .= '</label>';
|
74 |
+
$output .= '</div>';
|
75 |
+
|
76 |
+
return $output;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Checkout Selection Field
|
81 |
+
*
|
82 |
+
* @param array $args Args.
|
83 |
+
* @return string
|
84 |
+
*/
|
85 |
+
static public function flow_checkout_selection_field( $args ) {
|
86 |
+
|
87 |
+
$id = $args['id'];
|
88 |
+
$name = $args['name'];
|
89 |
+
$title = $args['title'];
|
90 |
+
$value = $args['value'];
|
91 |
+
|
92 |
+
$checkout_steps = get_posts(
|
93 |
+
array(
|
94 |
+
'posts_per_page' => -1,
|
95 |
+
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
96 |
+
'post_status' => 'publish',
|
97 |
+
'orderby' => 'ID',
|
98 |
+
'order' => 'ASC',
|
99 |
+
'tax_query' => array(
|
100 |
+
array(
|
101 |
+
'taxonomy' => CARTFLOWS_TAXONOMY_STEP_TYPE,
|
102 |
+
'field' => 'slug',
|
103 |
+
'terms' => 'checkout',
|
104 |
+
),
|
105 |
+
),
|
106 |
+
)
|
107 |
+
);
|
108 |
+
|
109 |
+
$output = '<div class="form-field">';
|
110 |
+
|
111 |
+
$output .= '<div class="form-field-label">';
|
112 |
+
$output .= '<label for="' . $id . '">';
|
113 |
+
$output .= $title;
|
114 |
+
$output .= '</label>';
|
115 |
+
$output .= '</div>';
|
116 |
+
|
117 |
+
$output .= '<div class="form-field-data">';
|
118 |
+
$output .= '<select id="wcf_' . $id . '" name="' . $name . '">';
|
119 |
+
|
120 |
+
if ( ! empty( $checkout_steps ) ) {
|
121 |
+
$output .= '<option value="">' . __( 'Select', 'cartflows' ) . '</option>';
|
122 |
+
} else {
|
123 |
+
|
124 |
+
$output .= '<option value="">' . __( 'No Checkout Steps', 'cartflows' ) . '</option>';
|
125 |
+
}
|
126 |
+
|
127 |
+
foreach ( $checkout_steps as $index => $step_data ) {
|
128 |
+
|
129 |
+
$output .= '<option value="' . $step_data->ID . '" ' . selected( $value, $step_data->ID, false ) . '>' . $step_data->post_title . ' (#' . $step_data->ID . ') </option>';
|
130 |
+
}
|
131 |
+
|
132 |
+
$output .= '</select>';
|
133 |
+
$output .= '</div>';
|
134 |
+
|
135 |
+
if ( '' !== $value ) {
|
136 |
+
$output .= '<div class="form-field-actions">';
|
137 |
+
$output .= '<a href="' . get_edit_post_link( $value ) . '" target="_blank" class="" title="Edit">';
|
138 |
+
$output .= '<span class="dashicons dashicons-edit"></span>';
|
139 |
+
$output .= '<span class="">Edit</span>';
|
140 |
+
$output .= '</a>';
|
141 |
+
$output .= '<a href="' . get_permalink( $value ) . '" target="_blank" class="" title="View">';
|
142 |
+
$output .= '<span class="dashicons dashicons-visibility"></span>';
|
143 |
+
$output .= '<span class="">View</span>';
|
144 |
+
$output .= '</a>';
|
145 |
+
$output .= '</div>';
|
146 |
+
}
|
147 |
+
|
148 |
+
$output .= '<div class="form-field-desc">';
|
149 |
+
/* translators: %s: link */
|
150 |
+
$output .= '<p>' . sprintf( __( 'Be sure not to add any product in above selected Global Checkout step. Please read information about how to set up Global Checkout %1$shere%2$s.', 'cartflows' ), '<a href="https://cartflows.com/docs/global-checkout/" target="_blank">', '</a>' ) . '</p>';
|
151 |
+
$output .= '</div>';
|
152 |
+
|
153 |
+
$output .= '</div>';
|
154 |
+
|
155 |
+
return $output;
|
156 |
+
}
|
157 |
+
}
|
classes/class-cartflows-admin.php
CHANGED
@@ -1,398 +1,398 @@
|
|
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 |
-
static public 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 |
-
// Add CARTFLOWS menu option to admin.
|
39 |
-
add_action( 'network_admin_menu', __CLASS__ . '::menu' );
|
40 |
-
add_action( 'admin_menu', __CLASS__ . '::menu' );
|
41 |
-
add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
|
42 |
-
|
43 |
-
add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
|
44 |
-
|
45 |
-
// Enqueue admin scripts.
|
46 |
-
if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) {
|
47 |
-
|
48 |
-
add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
|
49 |
-
|
50 |
-
self::save_settings();
|
51 |
-
}
|
52 |
-
|
53 |
-
/* Global Addmin Script */
|
54 |
-
add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
|
55 |
-
|
56 |
-
add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Initialises the Plugin Name.
|
61 |
-
*
|
62 |
-
* @since 1.0.0
|
63 |
-
* @return void
|
64 |
-
*/
|
65 |
-
static public function initialise_plugin() {
|
66 |
-
|
67 |
-
$name = 'Cartflows';
|
68 |
-
$short_name = 'Cflows';
|
69 |
-
|
70 |
-
define( 'CARTFLOWS_PLUGIN_NAME', $name );
|
71 |
-
define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Renders the admin settings menu.
|
76 |
-
*
|
77 |
-
* @since 1.0.0
|
78 |
-
* @return void
|
79 |
-
*/
|
80 |
-
static public function menu() {
|
81 |
-
|
82 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
83 |
-
return;
|
84 |
-
}
|
85 |
-
|
86 |
-
add_menu_page(
|
87 |
-
'CartFlows',
|
88 |
-
'CartFlows',
|
89 |
-
'manage_options',
|
90 |
-
CARTFLOWS_SLUG,
|
91 |
-
__CLASS__ . '::render',
|
92 |
-
'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),
|
93 |
-
39.7
|
94 |
-
);
|
95 |
-
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Add submenu to admin menu.
|
100 |
-
*
|
101 |
-
* @since 1.0.0
|
102 |
-
*/
|
103 |
-
static function submenu() {
|
104 |
-
|
105 |
-
$parent_slug = CARTFLOWS_SLUG;
|
106 |
-
$page_title = __( 'Settings', 'cartflows' );
|
107 |
-
$menu_title = __( 'Settings', 'cartflows' );
|
108 |
-
$capability = 'manage_options';
|
109 |
-
$menu_slug = 'cartflows_settings';
|
110 |
-
$callback = __CLASS__ . '::render';
|
111 |
-
|
112 |
-
add_submenu_page(
|
113 |
-
$parent_slug,
|
114 |
-
$page_title,
|
115 |
-
$menu_title,
|
116 |
-
$capability,
|
117 |
-
$menu_slug,
|
118 |
-
$callback
|
119 |
-
);
|
120 |
-
}
|
121 |
-
|
122 |
-
/**
|
123 |
-
* Renders the admin settings.
|
124 |
-
*
|
125 |
-
* @since 1.0.0
|
126 |
-
* @return void
|
127 |
-
*/
|
128 |
-
static public function render() {
|
129 |
-
$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
|
130 |
-
$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
|
131 |
-
$action = str_replace( '_', '-', $action );
|
132 |
-
|
133 |
-
// Enable header icon filter below.
|
134 |
-
$header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
|
135 |
-
|
136 |
-
include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Renders the admin settings content.
|
141 |
-
*
|
142 |
-
* @since 1.0.0
|
143 |
-
* @return void
|
144 |
-
*/
|
145 |
-
static public function render_content() {
|
146 |
-
|
147 |
-
$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
|
148 |
-
$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
|
149 |
-
$action = str_replace( '_', '-', $action );
|
150 |
-
$action = 'general';
|
151 |
-
|
152 |
-
$header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
|
153 |
-
|
154 |
-
include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Save Global Setting options.
|
159 |
-
*
|
160 |
-
* @since 1.0.0
|
161 |
-
*/
|
162 |
-
static public function save_common_settings() {
|
163 |
-
|
164 |
-
if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) {
|
165 |
-
|
166 |
-
$url = $_SERVER['REQUEST_URI'];
|
167 |
-
$input_settings = array();
|
168 |
-
$new_settings = array();
|
169 |
-
|
170 |
-
if ( isset( $_POST['_cartflows_common'] ) ) {
|
171 |
-
|
172 |
-
$input_settings = $_POST['_cartflows_common'];
|
173 |
-
|
174 |
-
// Loop through the input and sanitize each of the values.
|
175 |
-
foreach ( $input_settings as $key => $val ) {
|
176 |
-
|
177 |
-
if ( is_array( $val ) ) {
|
178 |
-
foreach ( $val as $k => $v ) {
|
179 |
-
$new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
|
180 |
-
}
|
181 |
-
} else {
|
182 |
-
$new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
|
183 |
-
}
|
184 |
-
}
|
185 |
-
}
|
186 |
-
|
187 |
-
Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true );
|
188 |
-
|
189 |
-
$query = array(
|
190 |
-
'message' => 'saved',
|
191 |
-
);
|
192 |
-
|
193 |
-
$redirect_to = add_query_arg( $query, $url );
|
194 |
-
|
195 |
-
wp_redirect( $redirect_to );
|
196 |
-
exit;
|
197 |
-
} // End if statement.
|
198 |
-
}
|
199 |
-
|
200 |
-
/**
|
201 |
-
* Check is cartflows admin.
|
202 |
-
*
|
203 |
-
* @since 1.0.0
|
204 |
-
* @return boolean
|
205 |
-
*/
|
206 |
-
static public function is_global_admin() {
|
207 |
-
|
208 |
-
$current_screen = get_current_screen();
|
209 |
-
|
210 |
-
if (
|
211 |
-
is_object( $current_screen ) &&
|
212 |
-
isset( $current_screen->post_type ) &&
|
213 |
-
( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
|
214 |
-
CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
|
215 |
-
)
|
216 |
-
) {
|
217 |
-
return true;
|
218 |
-
}
|
219 |
-
return false;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Check is flow admin.
|
224 |
-
*
|
225 |
-
* @since 1.0.0
|
226 |
-
* @return boolean
|
227 |
-
*/
|
228 |
-
static public function is_flow_edit_admin() {
|
229 |
-
|
230 |
-
$current_screen = get_current_screen();
|
231 |
-
|
232 |
-
if (
|
233 |
-
is_object( $current_screen ) &&
|
234 |
-
isset( $current_screen->post_type ) &&
|
235 |
-
( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
|
236 |
-
isset( $current_screen->base ) &&
|
237 |
-
( 'post' === $current_screen->base )
|
238 |
-
) {
|
239 |
-
return true;
|
240 |
-
}
|
241 |
-
return false;
|
242 |
-
}
|
243 |
-
|
244 |
-
/**
|
245 |
-
* Global Admin Scripts.
|
246 |
-
*
|
247 |
-
* @since 1.0.0
|
248 |
-
*/
|
249 |
-
static public function global_admin_scripts() {
|
250 |
-
|
251 |
-
$localize = array(
|
252 |
-
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
253 |
-
'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
|
254 |
-
);
|
255 |
-
|
256 |
-
wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
|
257 |
-
|
258 |
-
if ( self::is_global_admin() ) {
|
259 |
-
|
260 |
-
// Styles.
|
261 |
-
wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
|
262 |
-
wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
|
263 |
-
|
264 |
-
wp_enqueue_script(
|
265 |
-
'wcf-global-admin',
|
266 |
-
CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
|
267 |
-
array( 'jquery' ),
|
268 |
-
CARTFLOWS_VER,
|
269 |
-
true
|
270 |
-
);
|
271 |
-
|
272 |
-
do_action( 'cartflows_global_admin_scripts' );
|
273 |
-
}
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Global Admin Data.
|
278 |
-
*
|
279 |
-
* @since 1.0.0
|
280 |
-
*/
|
281 |
-
static public function global_admin_data() {
|
282 |
-
|
283 |
-
$current_screen = get_current_screen();
|
284 |
-
|
285 |
-
if ( CARTFLOWS_FLOW_POST_TYPE !== $current_screen->post_type ) {
|
286 |
-
return;
|
287 |
-
}
|
288 |
-
|
289 |
-
?>
|
290 |
-
|
291 |
-
<div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
|
292 |
-
<div class="wcf-templates-popup-content">
|
293 |
-
<div class="spinner"></div>
|
294 |
-
<div class="wcf-templates-wrap wcf-templates-wrap-flows">
|
295 |
-
|
296 |
-
<div id="wcf-remote-flow-actions" class="wcf-template-header">
|
297 |
-
<div class="wcf-template-logo-wrap">
|
298 |
-
<span class="wcf-cartflows-logo-img">
|
299 |
-
<span class="cartflows-icon"></span>
|
300 |
-
</span>
|
301 |
-
<span class="wcf-cartflows-title"><?php _e( 'Flows Library', 'cartflows' ); ?></span>
|
302 |
-
</div>
|
303 |
-
<div class="wcf-tab-wrapper">
|
304 |
-
<div id="wcf-page-builders">
|
305 |
-
<ul class="wcf-page-builder-links filter-links">
|
306 |
-
<li><a href="#" class="current" data-id="elementor"><?php _e( 'Elementor', 'cartflows' ); ?></a></li>
|
307 |
-
<li><a href="#" data-id="divi"><?php _e( 'Divi', 'cartflows' ); ?></a></li>
|
308 |
-
<li><a href="#" data-id="bb"><?php _e( 'Beaver Builder', 'cartflows' ); ?></a></li>
|
309 |
-
</ul>
|
310 |
-
</div>
|
311 |
-
<!-- <div id="wcf-remote-flow-filters">
|
312 |
-
<div id="cartflows-flow-funnel-type"></div>
|
313 |
-
</div> -->
|
314 |
-
</div>
|
315 |
-
<div class="wcf-popup-close-wrap">
|
316 |
-
<span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
|
317 |
-
</div>
|
318 |
-
</div>
|
319 |
-
<!-- <div class="wcf-search-form">
|
320 |
-
<label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
|
321 |
-
<input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
|
322 |
-
</div> -->
|
323 |
-
|
324 |
-
<div id="wcf-remote-content">
|
325 |
-
<div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"></div>
|
326 |
-
<div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
|
327 |
-
</div>
|
328 |
-
</div>
|
329 |
-
</div>
|
330 |
-
</div>
|
331 |
-
|
332 |
-
<?php
|
333 |
-
}
|
334 |
-
|
335 |
-
/**
|
336 |
-
* Enqueues the needed CSS/JS for the builder's admin settings page.
|
337 |
-
*
|
338 |
-
* @since 1.0.0
|
339 |
-
*/
|
340 |
-
static public function styles_scripts() {
|
341 |
-
|
342 |
-
// Styles.
|
343 |
-
wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
|
344 |
-
wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
|
345 |
-
|
346 |
-
// Script.
|
347 |
-
wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
|
348 |
-
|
349 |
-
$localize = array(
|
350 |
-
'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
|
351 |
-
);
|
352 |
-
|
353 |
-
wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
|
354 |
-
}
|
355 |
-
|
356 |
-
/**
|
357 |
-
* Save All admin settings here
|
358 |
-
*/
|
359 |
-
static public function save_settings() {
|
360 |
-
|
361 |
-
// Only admins can save settings.
|
362 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
363 |
-
return;
|
364 |
-
}
|
365 |
-
|
366 |
-
self::save_common_settings();
|
367 |
-
|
368 |
-
// Let extensions hook into saving.
|
369 |
-
do_action( 'cartflows_admin_settings_save' );
|
370 |
-
}
|
371 |
-
|
372 |
-
/**
|
373 |
-
* Get and return page URL
|
374 |
-
*
|
375 |
-
* @param string $menu_slug Menu name.
|
376 |
-
* @since 1.0.0
|
377 |
-
* @return string page url
|
378 |
-
*/
|
379 |
-
static public function get_page_url( $menu_slug ) {
|
380 |
-
|
381 |
-
$parent_page = self::$default_menu_position;
|
382 |
-
|
383 |
-
if ( strpos( $parent_page, '?' ) !== false ) {
|
384 |
-
$query_var = '&page=' . self::$plugin_slug;
|
385 |
-
} else {
|
386 |
-
$query_var = '?page=' . self::$plugin_slug;
|
387 |
-
}
|
388 |
-
|
389 |
-
$parent_page_url = admin_url( $parent_page . $query_var );
|
390 |
-
|
391 |
-
$url = $parent_page_url . '&action=' . $menu_slug;
|
392 |
-
|
393 |
-
return esc_url( $url );
|
394 |
-
}
|
395 |
-
|
396 |
-
}
|
397 |
-
|
398 |
-
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 |
+
static public 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 |
+
// Add CARTFLOWS menu option to admin.
|
39 |
+
add_action( 'network_admin_menu', __CLASS__ . '::menu' );
|
40 |
+
add_action( 'admin_menu', __CLASS__ . '::menu' );
|
41 |
+
add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
|
42 |
+
|
43 |
+
add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );
|
44 |
+
|
45 |
+
// Enqueue admin scripts.
|
46 |
+
if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) {
|
47 |
+
|
48 |
+
add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );
|
49 |
+
|
50 |
+
self::save_settings();
|
51 |
+
}
|
52 |
+
|
53 |
+
/* Global Addmin Script */
|
54 |
+
add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );
|
55 |
+
|
56 |
+
add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Initialises the Plugin Name.
|
61 |
+
*
|
62 |
+
* @since 1.0.0
|
63 |
+
* @return void
|
64 |
+
*/
|
65 |
+
static public function initialise_plugin() {
|
66 |
+
|
67 |
+
$name = 'Cartflows';
|
68 |
+
$short_name = 'Cflows';
|
69 |
+
|
70 |
+
define( 'CARTFLOWS_PLUGIN_NAME', $name );
|
71 |
+
define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name );
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Renders the admin settings menu.
|
76 |
+
*
|
77 |
+
* @since 1.0.0
|
78 |
+
* @return void
|
79 |
+
*/
|
80 |
+
static public function menu() {
|
81 |
+
|
82 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
83 |
+
return;
|
84 |
+
}
|
85 |
+
|
86 |
+
add_menu_page(
|
87 |
+
'CartFlows',
|
88 |
+
'CartFlows',
|
89 |
+
'manage_options',
|
90 |
+
CARTFLOWS_SLUG,
|
91 |
+
__CLASS__ . '::render',
|
92 |
+
'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ),
|
93 |
+
39.7
|
94 |
+
);
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Add submenu to admin menu.
|
100 |
+
*
|
101 |
+
* @since 1.0.0
|
102 |
+
*/
|
103 |
+
static function submenu() {
|
104 |
+
|
105 |
+
$parent_slug = CARTFLOWS_SLUG;
|
106 |
+
$page_title = __( 'Settings', 'cartflows' );
|
107 |
+
$menu_title = __( 'Settings', 'cartflows' );
|
108 |
+
$capability = 'manage_options';
|
109 |
+
$menu_slug = 'cartflows_settings';
|
110 |
+
$callback = __CLASS__ . '::render';
|
111 |
+
|
112 |
+
add_submenu_page(
|
113 |
+
$parent_slug,
|
114 |
+
$page_title,
|
115 |
+
$menu_title,
|
116 |
+
$capability,
|
117 |
+
$menu_slug,
|
118 |
+
$callback
|
119 |
+
);
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Renders the admin settings.
|
124 |
+
*
|
125 |
+
* @since 1.0.0
|
126 |
+
* @return void
|
127 |
+
*/
|
128 |
+
static public function render() {
|
129 |
+
$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
|
130 |
+
$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
|
131 |
+
$action = str_replace( '_', '-', $action );
|
132 |
+
|
133 |
+
// Enable header icon filter below.
|
134 |
+
$header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
|
135 |
+
|
136 |
+
include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php';
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Renders the admin settings content.
|
141 |
+
*
|
142 |
+
* @since 1.0.0
|
143 |
+
* @return void
|
144 |
+
*/
|
145 |
+
static public function render_content() {
|
146 |
+
|
147 |
+
$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : '';
|
148 |
+
$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
|
149 |
+
$action = str_replace( '_', '-', $action );
|
150 |
+
$action = 'general';
|
151 |
+
|
152 |
+
$header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) );
|
153 |
+
|
154 |
+
include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php';
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Save Global Setting options.
|
159 |
+
*
|
160 |
+
* @since 1.0.0
|
161 |
+
*/
|
162 |
+
static public function save_common_settings() {
|
163 |
+
|
164 |
+
if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) {
|
165 |
+
|
166 |
+
$url = $_SERVER['REQUEST_URI'];
|
167 |
+
$input_settings = array();
|
168 |
+
$new_settings = array();
|
169 |
+
|
170 |
+
if ( isset( $_POST['_cartflows_common'] ) ) {
|
171 |
+
|
172 |
+
$input_settings = $_POST['_cartflows_common'];
|
173 |
+
|
174 |
+
// Loop through the input and sanitize each of the values.
|
175 |
+
foreach ( $input_settings as $key => $val ) {
|
176 |
+
|
177 |
+
if ( is_array( $val ) ) {
|
178 |
+
foreach ( $val as $k => $v ) {
|
179 |
+
$new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : '';
|
180 |
+
}
|
181 |
+
} else {
|
182 |
+
$new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : '';
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true );
|
188 |
+
|
189 |
+
$query = array(
|
190 |
+
'message' => 'saved',
|
191 |
+
);
|
192 |
+
|
193 |
+
$redirect_to = add_query_arg( $query, $url );
|
194 |
+
|
195 |
+
wp_redirect( $redirect_to );
|
196 |
+
exit;
|
197 |
+
} // End if statement.
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Check is cartflows admin.
|
202 |
+
*
|
203 |
+
* @since 1.0.0
|
204 |
+
* @return boolean
|
205 |
+
*/
|
206 |
+
static public function is_global_admin() {
|
207 |
+
|
208 |
+
$current_screen = get_current_screen();
|
209 |
+
|
210 |
+
if (
|
211 |
+
is_object( $current_screen ) &&
|
212 |
+
isset( $current_screen->post_type ) &&
|
213 |
+
( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ||
|
214 |
+
CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type
|
215 |
+
)
|
216 |
+
) {
|
217 |
+
return true;
|
218 |
+
}
|
219 |
+
return false;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Check is flow admin.
|
224 |
+
*
|
225 |
+
* @since 1.0.0
|
226 |
+
* @return boolean
|
227 |
+
*/
|
228 |
+
static public function is_flow_edit_admin() {
|
229 |
+
|
230 |
+
$current_screen = get_current_screen();
|
231 |
+
|
232 |
+
if (
|
233 |
+
is_object( $current_screen ) &&
|
234 |
+
isset( $current_screen->post_type ) &&
|
235 |
+
( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) &&
|
236 |
+
isset( $current_screen->base ) &&
|
237 |
+
( 'post' === $current_screen->base )
|
238 |
+
) {
|
239 |
+
return true;
|
240 |
+
}
|
241 |
+
return false;
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Global Admin Scripts.
|
246 |
+
*
|
247 |
+
* @since 1.0.0
|
248 |
+
*/
|
249 |
+
static public function global_admin_scripts() {
|
250 |
+
|
251 |
+
$localize = array(
|
252 |
+
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
253 |
+
'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ),
|
254 |
+
);
|
255 |
+
|
256 |
+
wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) );
|
257 |
+
|
258 |
+
if ( self::is_global_admin() ) {
|
259 |
+
|
260 |
+
// Styles.
|
261 |
+
wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER );
|
262 |
+
wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' );
|
263 |
+
|
264 |
+
wp_enqueue_script(
|
265 |
+
'wcf-global-admin',
|
266 |
+
CARTFLOWS_URL . 'admin/assets/js/global-admin.js',
|
267 |
+
array( 'jquery' ),
|
268 |
+
CARTFLOWS_VER,
|
269 |
+
true
|
270 |
+
);
|
271 |
+
|
272 |
+
do_action( 'cartflows_global_admin_scripts' );
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Global Admin Data.
|
278 |
+
*
|
279 |
+
* @since 1.0.0
|
280 |
+
*/
|
281 |
+
static public function global_admin_data() {
|
282 |
+
|
283 |
+
$current_screen = get_current_screen();
|
284 |
+
|
285 |
+
if ( CARTFLOWS_FLOW_POST_TYPE !== $current_screen->post_type ) {
|
286 |
+
return;
|
287 |
+
}
|
288 |
+
|
289 |
+
?>
|
290 |
+
|
291 |
+
<div id="wcf-remote-flow-importer" class="wcf-templates-popup-overlay">
|
292 |
+
<div class="wcf-templates-popup-content">
|
293 |
+
<div class="spinner"></div>
|
294 |
+
<div class="wcf-templates-wrap wcf-templates-wrap-flows">
|
295 |
+
|
296 |
+
<div id="wcf-remote-flow-actions" class="wcf-template-header">
|
297 |
+
<div class="wcf-template-logo-wrap">
|
298 |
+
<span class="wcf-cartflows-logo-img">
|
299 |
+
<span class="cartflows-icon"></span>
|
300 |
+
</span>
|
301 |
+
<span class="wcf-cartflows-title"><?php _e( 'Flows Library', 'cartflows' ); ?></span>
|
302 |
+
</div>
|
303 |
+
<div class="wcf-tab-wrapper">
|
304 |
+
<div id="wcf-page-builders">
|
305 |
+
<ul class="wcf-page-builder-links filter-links">
|
306 |
+
<li><a href="#" class="current" data-id="elementor"><?php _e( 'Elementor', 'cartflows' ); ?></a></li>
|
307 |
+
<li><a href="#" data-id="divi"><?php _e( 'Divi', 'cartflows' ); ?></a></li>
|
308 |
+
<li><a href="#" data-id="bb"><?php _e( 'Beaver Builder', 'cartflows' ); ?></a></li>
|
309 |
+
</ul>
|
310 |
+
</div>
|
311 |
+
<!-- <div id="wcf-remote-flow-filters">
|
312 |
+
<div id="cartflows-flow-funnel-type"></div>
|
313 |
+
</div> -->
|
314 |
+
</div>
|
315 |
+
<div class="wcf-popup-close-wrap">
|
316 |
+
<span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
|
317 |
+
</div>
|
318 |
+
</div>
|
319 |
+
<!-- <div class="wcf-search-form">
|
320 |
+
<label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
|
321 |
+
<input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
|
322 |
+
</div> -->
|
323 |
+
|
324 |
+
<div id="wcf-remote-content">
|
325 |
+
<div id="wcf-remote-flow-list" class="wcf-remote-list wcf-template-list-wrap"></div>
|
326 |
+
<div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
|
327 |
+
</div>
|
328 |
+
</div>
|
329 |
+
</div>
|
330 |
+
</div>
|
331 |
+
|
332 |
+
<?php
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Enqueues the needed CSS/JS for the builder's admin settings page.
|
337 |
+
*
|
338 |
+
* @since 1.0.0
|
339 |
+
*/
|
340 |
+
static public function styles_scripts() {
|
341 |
+
|
342 |
+
// Styles.
|
343 |
+
wp_enqueue_style( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/css/admin-menu-settings.css', array(), CARTFLOWS_VER );
|
344 |
+
wp_style_add_data( 'cartflows-admin-settings', 'rtl', 'replace' );
|
345 |
+
|
346 |
+
// Script.
|
347 |
+
wp_enqueue_script( 'cartflows-admin-settings', CARTFLOWS_URL . 'admin/assets/js/admin-menu-settings.js', array( 'jquery', 'wp-util', 'updates' ), CARTFLOWS_VER );
|
348 |
+
|
349 |
+
$localize = array(
|
350 |
+
'ajax_nonce' => wp_create_nonce( 'cartflows-widget-nonce' ),
|
351 |
+
);
|
352 |
+
|
353 |
+
wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) );
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Save All admin settings here
|
358 |
+
*/
|
359 |
+
static public function save_settings() {
|
360 |
+
|
361 |
+
// Only admins can save settings.
|
362 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
363 |
+
return;
|
364 |
+
}
|
365 |
+
|
366 |
+
self::save_common_settings();
|
367 |
+
|
368 |
+
// Let extensions hook into saving.
|
369 |
+
do_action( 'cartflows_admin_settings_save' );
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Get and return page URL
|
374 |
+
*
|
375 |
+
* @param string $menu_slug Menu name.
|
376 |
+
* @since 1.0.0
|
377 |
+
* @return string page url
|
378 |
+
*/
|
379 |
+
static public function get_page_url( $menu_slug ) {
|
380 |
+
|
381 |
+
$parent_page = self::$default_menu_position;
|
382 |
+
|
383 |
+
if ( strpos( $parent_page, '?' ) !== false ) {
|
384 |
+
$query_var = '&page=' . self::$plugin_slug;
|
385 |
+
} else {
|
386 |
+
$query_var = '?page=' . self::$plugin_slug;
|
387 |
+
}
|
388 |
+
|
389 |
+
$parent_page_url = admin_url( $parent_page . $query_var );
|
390 |
+
|
391 |
+
$url = $parent_page_url . '&action=' . $menu_slug;
|
392 |
+
|
393 |
+
return esc_url( $url );
|
394 |
+
}
|
395 |
+
|
396 |
+
}
|
397 |
+
|
398 |
+
Cartflows_Admin::init();
|
classes/class-cartflows-frontend.php
CHANGED
@@ -1,325 +1,322 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* CartFlows Frontend.
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class Cartflows_Frontend.
|
10 |
-
*/
|
11 |
-
class Cartflows_Frontend {
|
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 |
-
|
35 |
-
/* Set / Destroy Flow Sessions. Set data */
|
36 |
-
add_action( 'wp', array( $this, 'init_actions' ), 1 );
|
37 |
-
|
38 |
-
/* Enqueue global required scripts */
|
39 |
-
add_action( 'wp', array( $this, 'wp_actions' ), 55 );
|
40 |
-
|
41 |
-
/* Modify the checkout order received url to go thank you page in our flow */
|
42 |
-
add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
*
|
50 |
-
*
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
wcf()->
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
*
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
$
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
*
|
180 |
-
*
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
'
|
190 |
-
'
|
191 |
-
|
192 |
-
|
193 |
-
'
|
194 |
-
|
195 |
-
|
196 |
-
'
|
197 |
-
'
|
198 |
-
|
199 |
-
|
200 |
-
'
|
201 |
-
|
202 |
-
|
203 |
-
'
|
204 |
-
'
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
$
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
'
|
300 |
-
'
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
* Kicking this off by calling 'get_instance()' method
|
324 |
-
*/
|
325 |
-
Cartflows_Frontend::get_instance();
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CartFlows Frontend.
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class Cartflows_Frontend.
|
10 |
+
*/
|
11 |
+
class Cartflows_Frontend {
|
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 |
+
|
35 |
+
/* Set / Destroy Flow Sessions. Set data */
|
36 |
+
add_action( 'wp', array( $this, 'init_actions' ), 1 );
|
37 |
+
|
38 |
+
/* Enqueue global required scripts */
|
39 |
+
add_action( 'wp', array( $this, 'wp_actions' ), 55 );
|
40 |
+
|
41 |
+
/* Modify the checkout order received url to go thank you page in our flow */
|
42 |
+
add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Redirect to thank page if upsell not exists
|
47 |
+
*
|
48 |
+
* @param string $order_recieve_url url.
|
49 |
+
* @param object $order order object.
|
50 |
+
* @since 1.0.0
|
51 |
+
*/
|
52 |
+
function redirect_to_thankyou_page( $order_recieve_url, $order ) {
|
53 |
+
|
54 |
+
/* Only for thank you page */
|
55 |
+
wcf()->logger->log( 'Start-' . __CLASS__ . '::' . __FUNCTION__ );
|
56 |
+
wcf()->logger->log( 'Only for thank you page' );
|
57 |
+
|
58 |
+
if ( wcf()->flow->is_thankyou_page_exists( $order ) ) {
|
59 |
+
|
60 |
+
if ( _is_wcf_doing_checkout_ajax() ) {
|
61 |
+
|
62 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_post_data();
|
63 |
+
|
64 |
+
if ( ! $checkout_id ) {
|
65 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
|
66 |
+
}
|
67 |
+
} else {
|
68 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
|
69 |
+
}
|
70 |
+
|
71 |
+
wcf()->logger->log( 'Checkout ID : ' . $checkout_id );
|
72 |
+
|
73 |
+
if ( $checkout_id ) {
|
74 |
+
|
75 |
+
$thankyou_step_id = wcf()->flow->get_thankyou_page_id( $order );
|
76 |
+
|
77 |
+
if ( $thankyou_step_id ) {
|
78 |
+
|
79 |
+
$order_recieve_url = get_permalink( $thankyou_step_id );
|
80 |
+
|
81 |
+
$order_recieve_url = add_query_arg(
|
82 |
+
array(
|
83 |
+
'wcf-order' => $order->get_id(),
|
84 |
+
'wcf-key' => $order->get_order_key(),
|
85 |
+
),
|
86 |
+
$order_recieve_url
|
87 |
+
);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
wcf()->logger->log( 'End-' . __CLASS__ . '::' . __FUNCTION__ );
|
93 |
+
|
94 |
+
return $order_recieve_url;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Cancel and redirect to checkout
|
99 |
+
*
|
100 |
+
* @param string $return_url url.
|
101 |
+
* @since 1.0.0
|
102 |
+
*/
|
103 |
+
function redirect_to_checkout_on_cancel( $return_url ) {
|
104 |
+
|
105 |
+
if ( _is_wcf_doing_checkout_ajax() ) {
|
106 |
+
|
107 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_post_data();
|
108 |
+
|
109 |
+
if ( ! $checkout_id ) {
|
110 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
|
111 |
+
}
|
112 |
+
} else {
|
113 |
+
$checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( $checkout_id ) {
|
117 |
+
|
118 |
+
$return_url = add_query_arg(
|
119 |
+
array(
|
120 |
+
'cancel_order' => 'true',
|
121 |
+
'_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
|
122 |
+
),
|
123 |
+
get_permalink( $checkout_id )
|
124 |
+
);
|
125 |
+
}
|
126 |
+
|
127 |
+
return $return_url;
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Remove theme styles.
|
133 |
+
*
|
134 |
+
* @since 1.0.0
|
135 |
+
*/
|
136 |
+
function remove_theme_styles() {
|
137 |
+
|
138 |
+
// get all styles data.
|
139 |
+
global $wp_styles;
|
140 |
+
global $wp_scripts;
|
141 |
+
|
142 |
+
$get_stylesheet = get_stylesheet();
|
143 |
+
$get_template = get_template();
|
144 |
+
|
145 |
+
if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
|
146 |
+
return;
|
147 |
+
}
|
148 |
+
|
149 |
+
$get_stylesheet = 'themes/' . get_stylesheet();
|
150 |
+
$get_template = 'themes/' . get_template();
|
151 |
+
|
152 |
+
// loop over all of the registered scripts..
|
153 |
+
foreach ( $wp_styles->registered as $handle => $data ) {
|
154 |
+
|
155 |
+
if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
|
156 |
+
|
157 |
+
// remove it.
|
158 |
+
wp_deregister_style( $handle );
|
159 |
+
wp_dequeue_style( $handle );
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
// loop over all of the registered scripts.
|
164 |
+
foreach ( $wp_scripts->registered as $handle => $data ) {
|
165 |
+
|
166 |
+
if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
|
167 |
+
|
168 |
+
// remove it.
|
169 |
+
wp_deregister_script( $handle );
|
170 |
+
wp_dequeue_script( $handle );
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Update main order data in transient.
|
177 |
+
*
|
178 |
+
* @param array $woo_styles new styles array.
|
179 |
+
* @since 1.0.0
|
180 |
+
* @return array.
|
181 |
+
*/
|
182 |
+
function woo_default_css( $woo_styles ) {
|
183 |
+
|
184 |
+
$woo_styles = array(
|
185 |
+
'woocommerce-layout' => array(
|
186 |
+
'src' => plugins_url( 'assets/css/woocommerce-layout.css', WC_PLUGIN_FILE ),
|
187 |
+
'deps' => '',
|
188 |
+
'version' => WC_VERSION,
|
189 |
+
'media' => 'all',
|
190 |
+
'has_rtl' => true,
|
191 |
+
),
|
192 |
+
'woocommerce-smallscreen' => array(
|
193 |
+
'src' => plugins_url( 'assets/css/woocommerce-smallscreen.css', WC_PLUGIN_FILE ),
|
194 |
+
'deps' => 'woocommerce-layout',
|
195 |
+
'version' => WC_VERSION,
|
196 |
+
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
|
197 |
+
'has_rtl' => true,
|
198 |
+
),
|
199 |
+
'woocommerce-general' => array(
|
200 |
+
'src' => plugins_url( 'assets/css/woocommerce.css', WC_PLUGIN_FILE ),
|
201 |
+
'deps' => '',
|
202 |
+
'version' => WC_VERSION,
|
203 |
+
'media' => 'all',
|
204 |
+
'has_rtl' => true,
|
205 |
+
),
|
206 |
+
);
|
207 |
+
|
208 |
+
return $woo_styles;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Init Actions.
|
213 |
+
*
|
214 |
+
* @since 1.0.0
|
215 |
+
*/
|
216 |
+
function init_actions() {
|
217 |
+
|
218 |
+
$this->set_flow_session();
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Set flow session.
|
223 |
+
*
|
224 |
+
* @since 1.0.0
|
225 |
+
*/
|
226 |
+
function set_flow_session() {
|
227 |
+
|
228 |
+
if ( wcf()->utils->is_step_post_type() ) {
|
229 |
+
|
230 |
+
add_action( 'wp_head', array( $this, 'noindex_flow' ) );
|
231 |
+
|
232 |
+
wcf()->utils->do_not_cache();
|
233 |
+
|
234 |
+
/* Set key to support pixel */
|
235 |
+
if ( isset( $_GET['wcf-key'] ) ) {
|
236 |
+
$_GET['key'] = $_GET['wcf-key'];
|
237 |
+
$_REQUEST['key'] = $_GET['wcf-key'];
|
238 |
+
}
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Add noindex, nofollow.
|
244 |
+
*
|
245 |
+
* @since 1.0.0
|
246 |
+
*/
|
247 |
+
function noindex_flow() {
|
248 |
+
|
249 |
+
$common = Cartflows_Helper::get_common_settings();
|
250 |
+
|
251 |
+
if ( 'enable' === $common['disallow_indexing'] ) {
|
252 |
+
echo '<meta name="robots" content="noindex,nofollow">';
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* WP Actions.
|
258 |
+
*
|
259 |
+
* @since 1.0.0
|
260 |
+
*/
|
261 |
+
function wp_actions() {
|
262 |
+
|
263 |
+
if ( wcf()->utils->is_step_post_type() ) {
|
264 |
+
|
265 |
+
/* CSS Compatibility for All theme */
|
266 |
+
add_filter( 'woocommerce_enqueue_styles', array( $this, 'woo_default_css' ), 9999 );
|
267 |
+
|
268 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'remove_theme_styles' ), 9999 );
|
269 |
+
|
270 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'global_flow_scripts' ), 20 );
|
271 |
+
}
|
272 |
+
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Global flow scripts.
|
277 |
+
*
|
278 |
+
* @since 1.0.0
|
279 |
+
*/
|
280 |
+
function global_flow_scripts() {
|
281 |
+
|
282 |
+
global $post;
|
283 |
+
|
284 |
+
$flow = get_post_meta( $post->ID, 'wcf-flow-id', true );
|
285 |
+
$current_step = $post->ID;
|
286 |
+
$next_step_link = '';
|
287 |
+
$compatibility = Cartflows_Compatibility::get_instance();
|
288 |
+
|
289 |
+
if ( _is_wcf_landing_type() ) {
|
290 |
+
|
291 |
+
$next_step_id = wcf()->utils->get_next_step_id( $flow, $current_step );
|
292 |
+
$next_step_link = get_permalink( $next_step_id );
|
293 |
+
}
|
294 |
+
|
295 |
+
$localize = array(
|
296 |
+
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
297 |
+
'is_pb_preview' => $compatibility->is_page_builder_preview(),
|
298 |
+
'current_flow' => $flow,
|
299 |
+
'current_step' => $current_step,
|
300 |
+
'next_step' => $next_step_link,
|
301 |
+
);
|
302 |
+
|
303 |
+
wp_localize_script( 'jquery', 'cartflows', apply_filters( 'global_cartflows_js_localize', $localize ) );
|
304 |
+
|
305 |
+
wp_enqueue_style( 'wcf-frontend-global', CARTFLOWS_URL . 'assets/css/frontend.css', array(), CARTFLOWS_VER );
|
306 |
+
wp_style_add_data( 'wcf-frontend-global', 'rtl', 'replace' );
|
307 |
+
|
308 |
+
wp_enqueue_script(
|
309 |
+
'wcf-frontend-global',
|
310 |
+
CARTFLOWS_URL . 'assets/js/frontend.js',
|
311 |
+
array( 'jquery' ),
|
312 |
+
CARTFLOWS_VER,
|
313 |
+
true
|
314 |
+
);
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Prepare if class 'Cartflows_Frontend' exist.
|
320 |
+
* Kicking this off by calling 'get_instance()' method
|
321 |
+
*/
|
322 |
+
Cartflows_Frontend::get_instance();
|
|
|
|
|
|
classes/class-cartflows-importer.php
CHANGED
@@ -1,1038 +1,1038 @@
|
|
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 |
-
|
62 |
-
/**
|
63 |
-
* Clear Cache.
|
64 |
-
*
|
65 |
-
* @since 1.0.0
|
66 |
-
*/
|
67 |
-
public function clear_cache() {
|
68 |
-
// Clear 'Elementor' file cache.
|
69 |
-
if ( class_exists( '\Elementor\Plugin' ) ) {
|
70 |
-
Elementor\Plugin::$instance->files_manager->clear_cache();
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* JS Templates
|
76 |
-
*
|
77 |
-
* @since 1.0.0
|
78 |
-
*
|
79 |
-
* @return void
|
80 |
-
*/
|
81 |
-
function js_templates() {
|
82 |
-
|
83 |
-
// Loading Templates.
|
84 |
-
?>
|
85 |
-
<script type="text/template" id="tmpl-cartflows-step-loading">
|
86 |
-
<div class="template-message-block cartflows-step-loading">
|
87 |
-
<h2>
|
88 |
-
<span class="spinner"></span>
|
89 |
-
<?php _e( 'Loading Steps', 'cartflows' ); ?>
|
90 |
-
</h2>
|
91 |
-
<p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
|
92 |
-
</div>
|
93 |
-
</script>
|
94 |
-
|
95 |
-
<?php
|
96 |
-
// Search Templates.
|
97 |
-
?>
|
98 |
-
<script type="text/template" id="tmpl-cartflows-searching-templates">
|
99 |
-
<div class="template-message-block cartflows-searching-templates">
|
100 |
-
<h2>
|
101 |
-
<span class="spinner"></span>
|
102 |
-
<?php _e( 'Searching Template..', 'cartflows' ); ?>
|
103 |
-
</h2>
|
104 |
-
<p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
|
105 |
-
</div>
|
106 |
-
</script>
|
107 |
-
|
108 |
-
<?php
|
109 |
-
// CartFlows Importing Template.
|
110 |
-
?>
|
111 |
-
<script type="text/template" id="tmpl-cartflows-step-importing">
|
112 |
-
<div class="template-message-block cartflows-step-importing">
|
113 |
-
<h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
|
114 |
-
</div>
|
115 |
-
</script>
|
116 |
-
|
117 |
-
<?php
|
118 |
-
// CartFlows Imported.
|
119 |
-
?>
|
120 |
-
<script type="text/template" id="tmpl-cartflows-step-imported">
|
121 |
-
<div class="template-message-block cartflows-step-imported">
|
122 |
-
<h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
|
123 |
-
<p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
|
124 |
-
</script>
|
125 |
-
|
126 |
-
<?php
|
127 |
-
// No templates.
|
128 |
-
?>
|
129 |
-
<script type="text/template" id="tmpl-cartflows-no-steps">
|
130 |
-
<div class="cartflows-no-steps">
|
131 |
-
<div class="template-message-block">
|
132 |
-
<h2><?php _e( 'Steps not found!', 'cartflows' ); ?></h2>
|
133 |
-
<p class="description"><?php _e( 'We\'ll provide the ready made steps to import.', 'cartflows' ); ?></p>
|
134 |
-
</div>
|
135 |
-
</div>
|
136 |
-
</script>
|
137 |
-
|
138 |
-
<?php
|
139 |
-
// No templates.
|
140 |
-
?>
|
141 |
-
<script type="text/template" id="tmpl-cartflows-no-flows">
|
142 |
-
<div class="cartflows-no-flows">
|
143 |
-
<div class="template-message-block">
|
144 |
-
<h2><?php _e( 'Flows not found!', 'cartflows' ); ?></h2>
|
145 |
-
<p class="description"><?php _e( 'We\'ll provide the ready made flows to import.', 'cartflows' ); ?></p>
|
146 |
-
</div>
|
147 |
-
</div>
|
148 |
-
</script>
|
149 |
-
|
150 |
-
<?php
|
151 |
-
// Error handling.
|
152 |
-
?>
|
153 |
-
<script type="text/template" id="tmpl-templator-error">
|
154 |
-
<div class="notice notice-error"><p>{{ data }}</p></div>
|
155 |
-
</script>
|
156 |
-
|
157 |
-
<?php
|
158 |
-
// Redirect to Elementor.
|
159 |
-
?>
|
160 |
-
<script type="text/template" id="tmpl-templator-redirect-to-elementor">
|
161 |
-
<div class="template-message-block templator-redirect-to-elementor">
|
162 |
-
<h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
|
163 |
-
<p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
|
164 |
-
</script>
|
165 |
-
|
166 |
-
<?php
|
167 |
-
/**
|
168 |
-
* Responsive Buttons
|
169 |
-
*/
|
170 |
-
?>
|
171 |
-
<script type="text/template" id="tmpl-cartflows-responsive-view">
|
172 |
-
<span class="responsive-view">
|
173 |
-
<span class="actions">
|
174 |
-
<a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
|
175 |
-
<a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
|
176 |
-
<a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
|
177 |
-
</span>
|
178 |
-
</span>
|
179 |
-
</script>
|
180 |
-
|
181 |
-
<?php
|
182 |
-
/** Blank flow */
|
183 |
-
?>
|
184 |
-
<script type="text/template" id="tmpl-cartflows-create-blank-flow">
|
185 |
-
<div class="inner">
|
186 |
-
<div class="template">
|
187 |
-
<span class="thumbnail site-preview">
|
188 |
-
<div class="template-screenshot">
|
189 |
-
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
|
190 |
-
</div>
|
191 |
-
</span>
|
192 |
-
<div class="template-id-container">
|
193 |
-
<h3 class="template-name"> <?php _e( 'Canvas', 'cartflows' ); ?> </h3>
|
194 |
-
<div class="template-actions">
|
195 |
-
<a href="#" class="button button-primary cartflows-flow-import-blank"><?php _e( 'Create Flow', 'cartflows' ); ?></a>
|
196 |
-
</div>
|
197 |
-
</div>
|
198 |
-
</div>
|
199 |
-
</div>
|
200 |
-
</script>
|
201 |
-
|
202 |
-
<?php
|
203 |
-
// Templates data.
|
204 |
-
$installed_plugins = get_plugins();
|
205 |
-
|
206 |
-
$import_btn_title = __( 'Import', 'cartflows' );
|
207 |
-
|
208 |
-
$required_plugins = array(
|
209 |
-
'elementor' => array(
|
210 |
-
'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
|
211 |
-
'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
|
212 |
-
),
|
213 |
-
);
|
214 |
-
|
215 |
-
if ( 'yes' == $required_plugins['elementor']['install'] && 'no' == $required_plugins['elementor']['active'] ) {
|
216 |
-
$import_btn_title = __( 'Activate Elementor & Import', 'cartflows' );
|
217 |
-
} elseif ( 'no' == $required_plugins['elementor']['install'] ) {
|
218 |
-
$import_btn_title = __( 'Install Elementor & Import', 'cartflows' );
|
219 |
-
}
|
220 |
-
|
221 |
-
?>
|
222 |
-
<script type="text/template" id="tmpl-cartflows-flows-list">
|
223 |
-
|
224 |
-
<# if ( data.items.length ) { #>
|
225 |
-
<# for ( key in data.items ) { #>
|
226 |
-
<#
|
227 |
-
var flow_steps = [];
|
228 |
-
if( data.items[ key ].flow_steps ) {
|
229 |
-
flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
|
230 |
-
return value['id'];
|
231 |
-
});
|
232 |
-
}
|
233 |
-
#>
|
234 |
-
<div class="inner">
|
235 |
-
<div class="template">
|
236 |
-
<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 }}">
|
237 |
-
<div class="template-screenshot">
|
238 |
-
<# if( data.items[ key ].featured_image_url ) { #>
|
239 |
-
<img src="{{ data.items[ key ].featured_image_url }}" />
|
240 |
-
<# } else { #>
|
241 |
-
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
|
242 |
-
<# } #>
|
243 |
-
</div>
|
244 |
-
<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>
|
245 |
-
<# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
|
246 |
-
<span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
|
247 |
-
<# } #>
|
248 |
-
</span>
|
249 |
-
<div class="template-id-container">
|
250 |
-
<h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
|
251 |
-
<div class="template-actions">
|
252 |
-
|
253 |
-
<# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
|
254 |
-
<a data-flow-steps="{{ flow_steps }}" data-required="<?php echo htmlspecialchars( json_encode( $required_plugins ), ENT_QUOTES, 'UTF-8' ); ?>" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}"><?php echo $import_btn_title; ?></a>
|
255 |
-
<# } else if( CartFlowsImportVars._is_pro_active ) { #>
|
256 |
-
<a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
|
257 |
-
<# } else { #>
|
258 |
-
<a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
|
259 |
-
<# } #>
|
260 |
-
</div>
|
261 |
-
</div>
|
262 |
-
</div>
|
263 |
-
</div>
|
264 |
-
<# } #>
|
265 |
-
<# } #>
|
266 |
-
</script>
|
267 |
-
|
268 |
-
<?php
|
269 |
-
// Empty Step.
|
270 |
-
?>
|
271 |
-
<script type="text/template" id="tmpl-cartflows-create-blank-step">
|
272 |
-
<div class="inner">
|
273 |
-
<div class="template">
|
274 |
-
<span class="thumbnail site-preview cartflows-flow-preview">
|
275 |
-
<div class="template-screenshot">
|
276 |
-
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
|
277 |
-
</div>
|
278 |
-
<div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
|
279 |
-
</span>
|
280 |
-
<div class="template-id-container">
|
281 |
-
<h3 class="template-name"> Blank </h3>
|
282 |
-
<div class="template-actions">
|
283 |
-
<a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
|
284 |
-
</div>
|
285 |
-
</div>
|
286 |
-
</div>
|
287 |
-
</div>
|
288 |
-
</script>
|
289 |
-
|
290 |
-
<?php
|
291 |
-
// Templates data.
|
292 |
-
?>
|
293 |
-
<script type="text/template" id="tmpl-cartflows-steps-list">
|
294 |
-
<# if ( data.items.length ) { #>
|
295 |
-
<# for ( key in data.items ) { #>
|
296 |
-
<#
|
297 |
-
var flow_steps = [];
|
298 |
-
if( data.items[ key ].flow_steps ) {
|
299 |
-
flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
|
300 |
-
return value['id'];
|
301 |
-
});
|
302 |
-
}
|
303 |
-
#>
|
304 |
-
<div class="inner">
|
305 |
-
<div class="template">
|
306 |
-
<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 }}">
|
307 |
-
<div class="template-screenshot">
|
308 |
-
<# if( data.items[ key ].featured_image_url ) { #>
|
309 |
-
<img src="{{ data.items[ key ].featured_image_url }}" />
|
310 |
-
<# } else { #>
|
311 |
-
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
|
312 |
-
<# } #>
|
313 |
-
</div>
|
314 |
-
<div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
|
315 |
-
<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>
|
316 |
-
<# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
|
317 |
-
<span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
|
318 |
-
<# } #>
|
319 |
-
</span>
|
320 |
-
<div class="template-id-container">
|
321 |
-
<h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
|
322 |
-
<div class="template-actions">
|
323 |
-
<# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
|
324 |
-
<a data-required="<?php echo htmlspecialchars( json_encode( $required_plugins ), ENT_QUOTES, 'UTF-8' ); ?>" data-flow-steps="{{ flow_steps }}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}"><?php echo $import_btn_title; ?></a>
|
325 |
-
<# } else if( CartFlowsImportVars._is_pro_active ) { #>
|
326 |
-
<a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
|
327 |
-
<# } else { #>
|
328 |
-
<a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
|
329 |
-
<# } #>
|
330 |
-
</div>
|
331 |
-
</div>
|
332 |
-
</div>
|
333 |
-
</div>
|
334 |
-
<# } #>
|
335 |
-
<# } #>
|
336 |
-
</script>
|
337 |
-
|
338 |
-
<?php
|
339 |
-
/**
|
340 |
-
* TMPL - Filters
|
341 |
-
*/
|
342 |
-
?>
|
343 |
-
<script type="text/template" id="tmpl-cartflows-term-filters">
|
344 |
-
|
345 |
-
<# if ( data ) { #>
|
346 |
-
|
347 |
-
<ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
|
348 |
-
|
349 |
-
<# console.log( data.args.show_all ) #>
|
350 |
-
<# if ( data.args.show_all ) { #>
|
351 |
-
<li>
|
352 |
-
<a href="#" data-group="all"> All </a>
|
353 |
-
</li>
|
354 |
-
<# } #>
|
355 |
-
|
356 |
-
<# for ( key in data.items ) { #>
|
357 |
-
<li>
|
358 |
-
<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>
|
359 |
-
</li>
|
360 |
-
<# } #>
|
361 |
-
|
362 |
-
</ul>
|
363 |
-
<# } #>
|
364 |
-
</script>
|
365 |
-
|
366 |
-
<?php
|
367 |
-
// Step Type.
|
368 |
-
?>
|
369 |
-
<script type="text/template" id="tmpl-cartflows-step-types">
|
370 |
-
<ul class="wcf-tab nav-tabs">
|
371 |
-
<# if( data.items_count ) { #>
|
372 |
-
<# for( key in data.items ) { #>
|
373 |
-
<# console.log( data.items[ key ].id ) #>
|
374 |
-
<li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
|
375 |
-
<a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
|
376 |
-
</li>
|
377 |
-
<# } #>
|
378 |
-
<# } #>
|
379 |
-
</ul>
|
380 |
-
</script>
|
381 |
-
|
382 |
-
<?php
|
383 |
-
// Add to library button.
|
384 |
-
?>
|
385 |
-
<script type="text/template" id="tmpl-templator-add-to-library">
|
386 |
-
<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>
|
387 |
-
</script>
|
388 |
-
<?php
|
389 |
-
}
|
390 |
-
|
391 |
-
/**
|
392 |
-
* Enqueue scripts
|
393 |
-
*
|
394 |
-
* @since 1.0.0
|
395 |
-
*
|
396 |
-
* @hook admin_enqueue_scripts
|
397 |
-
* @param string $hook Current page hook.
|
398 |
-
*/
|
399 |
-
function scripts( $hook = '' ) {
|
400 |
-
|
401 |
-
if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
|
402 |
-
return;
|
403 |
-
}
|
404 |
-
|
405 |
-
wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
|
406 |
-
wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
|
407 |
-
wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
|
408 |
-
wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
|
409 |
-
|
410 |
-
$localize_vars = array(
|
411 |
-
'_is_pro_active' => _is_cartflows_pro(),
|
412 |
-
|
413 |
-
// Flow and its rest fields.
|
414 |
-
'flow' => CARTFLOWS_FLOW_POST_TYPE,
|
415 |
-
'flow_fields' => array(
|
416 |
-
'id',
|
417 |
-
'title',
|
418 |
-
'flow_type',
|
419 |
-
'flow_steps',
|
420 |
-
'licence_status',
|
421 |
-
'featured_image_url',
|
422 |
-
'featured_media', // @required for field `featured_image_url`.
|
423 |
-
),
|
424 |
-
|
425 |
-
// Flow type and rest fields.
|
426 |
-
'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
|
427 |
-
'flow_type_fields' => array(
|
428 |
-
'id',
|
429 |
-
'name',
|
430 |
-
'slug',
|
431 |
-
),
|
432 |
-
|
433 |
-
// Step and its rest fields.
|
434 |
-
'step' => CARTFLOWS_STEP_POST_TYPE,
|
435 |
-
'step_fields' => array(
|
436 |
-
'title',
|
437 |
-
'featured_image_url',
|
438 |
-
'featured_media', // @required for field `featured_image_url`.
|
439 |
-
'id',
|
440 |
-
'flow_type',
|
441 |
-
'licence_status',
|
442 |
-
),
|
443 |
-
|
444 |
-
// Step type and its rest fields.
|
445 |
-
'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
|
446 |
-
'step_type_fields' => array(
|
447 |
-
'id',
|
448 |
-
'name',
|
449 |
-
'slug',
|
450 |
-
),
|
451 |
-
|
452 |
-
'domain_url' => CARTFLOWS_DOMAIN_URL,
|
453 |
-
'server_url' => CARTFLOWS_TEMPLATES_URL,
|
454 |
-
'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
|
455 |
-
'site_url' => site_url(),
|
456 |
-
'admin_url' => admin_url(),
|
457 |
-
'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
|
458 |
-
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
459 |
-
'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
|
460 |
-
);
|
461 |
-
|
462 |
-
// Add thickbox.
|
463 |
-
add_thickbox();
|
464 |
-
|
465 |
-
wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
|
466 |
-
wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
|
467 |
-
}
|
468 |
-
|
469 |
-
/**
|
470 |
-
* Load Template
|
471 |
-
*
|
472 |
-
* @since 1.0.0
|
473 |
-
*
|
474 |
-
* @hook cartflows_load_steps
|
475 |
-
* @return void
|
476 |
-
*/
|
477 |
-
function load_templates() {
|
478 |
-
|
479 |
-
check_ajax_referer( 'cf-load-steps', 'security' );
|
480 |
-
|
481 |
-
$args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
|
482 |
-
$templates = CartFlows_API::get_instance()->get_templates( $args );
|
483 |
-
|
484 |
-
if ( $templates['templates_count'] ) {
|
485 |
-
wp_send_json_success( $templates );
|
486 |
-
} else {
|
487 |
-
wp_send_json_error( $templates );
|
488 |
-
}
|
489 |
-
wp_die();
|
490 |
-
}
|
491 |
-
|
492 |
-
/**
|
493 |
-
* Import.
|
494 |
-
*
|
495 |
-
* @since 1.0.0
|
496 |
-
*
|
497 |
-
* @hook wp_ajax_cartflows_import_flow_step
|
498 |
-
* @return void
|
499 |
-
*/
|
500 |
-
function import_flow() {
|
501 |
-
|
502 |
-
check_ajax_referer( 'cf-import-flow-step', 'security' );
|
503 |
-
|
504 |
-
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
505 |
-
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
|
506 |
-
|
507 |
-
wcf()->logger->import_log( '------------------------------------' );
|
508 |
-
wcf()->logger->import_log( 'STARTED! Importing FLOW' );
|
509 |
-
wcf()->logger->import_log( '------------------------------------' );
|
510 |
-
wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
|
511 |
-
|
512 |
-
$response = CartFlows_API::get_instance()->get_template( $template_id );
|
513 |
-
|
514 |
-
if ( false === $response['success'] ) {
|
515 |
-
wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
|
516 |
-
wp_send_json_error( $response );
|
517 |
-
}
|
518 |
-
|
519 |
-
wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
|
520 |
-
|
521 |
-
$new_step_id = wp_insert_post(
|
522 |
-
array(
|
523 |
-
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
524 |
-
'post_title' => $response['title'],
|
525 |
-
'post_content' => '',
|
526 |
-
'post_status' => 'publish',
|
527 |
-
)
|
528 |
-
);
|
529 |
-
|
530 |
-
if ( is_wp_error( $new_step_id ) ) {
|
531 |
-
wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
|
532 |
-
wp_send_json_error( $new_step_id );
|
533 |
-
}
|
534 |
-
|
535 |
-
wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
|
536 |
-
// insert post meta.
|
537 |
-
update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
|
538 |
-
wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
|
539 |
-
|
540 |
-
/**
|
541 |
-
* Import & Set type.
|
542 |
-
*/
|
543 |
-
$term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
|
544 |
-
$term_slug = '';
|
545 |
-
if ( $term ) {
|
546 |
-
|
547 |
-
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
548 |
-
$term_exist = term_exists( $term->name, $taxonomy );
|
549 |
-
|
550 |
-
if ( empty( $term_exist ) ) {
|
551 |
-
$terms = array(
|
552 |
-
array(
|
553 |
-
'name' => $term->name,
|
554 |
-
),
|
555 |
-
);
|
556 |
-
|
557 |
-
Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
|
558 |
-
wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
|
559 |
-
}
|
560 |
-
|
561 |
-
$current_term = term_exists( $term->name, $taxonomy );
|
562 |
-
|
563 |
-
// Set type object.
|
564 |
-
$data = get_term( $current_term['term_id'], $taxonomy );
|
565 |
-
$term_slug = $data->slug;
|
566 |
-
$term_name = $data->name;
|
567 |
-
wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
568 |
-
wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
|
569 |
-
|
570 |
-
// Set type.
|
571 |
-
update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
|
572 |
-
wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
|
573 |
-
}
|
574 |
-
|
575 |
-
// Set flow.
|
576 |
-
wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
577 |
-
wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
|
578 |
-
|
579 |
-
/**
|
580 |
-
* Update steps for the current flow.
|
581 |
-
*/
|
582 |
-
$flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
|
583 |
-
|
584 |
-
if ( ! is_array( $flow_steps ) ) {
|
585 |
-
$flow_steps = array();
|
586 |
-
}
|
587 |
-
|
588 |
-
$flow_steps[] = array(
|
589 |
-
'id' => $new_step_id,
|
590 |
-
'title' => $response['title'],
|
591 |
-
'type' => $term_slug,
|
592 |
-
);
|
593 |
-
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
594 |
-
wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
|
595 |
-
|
596 |
-
// Import Post Meta.
|
597 |
-
self::import_post_meta( $new_step_id, $response );
|
598 |
-
|
599 |
-
wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
|
600 |
-
wcf()->logger->import_log( '------------------------------------' );
|
601 |
-
wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
|
602 |
-
wcf()->logger->import_log( '------------------------------------' );
|
603 |
-
|
604 |
-
do_action( 'cartflows_import_complete' );
|
605 |
-
wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
|
606 |
-
|
607 |
-
// Batch Process.
|
608 |
-
do_action( 'cartflows_after_template_import', $new_step_id, $response );
|
609 |
-
|
610 |
-
/**
|
611 |
-
* End
|
612 |
-
*/
|
613 |
-
wp_send_json_success( $new_step_id );
|
614 |
-
}
|
615 |
-
|
616 |
-
/**
|
617 |
-
* Import Step.
|
618 |
-
*
|
619 |
-
* @since 1.0.0
|
620 |
-
* @hook wp_ajax_cartflows_step_import
|
621 |
-
*
|
622 |
-
* @return void
|
623 |
-
*/
|
624 |
-
function create_default_flow() {
|
625 |
-
|
626 |
-
check_ajax_referer( 'cf-default-flow', 'security' );
|
627 |
-
|
628 |
-
// Create post object.
|
629 |
-
$new_flow_post = array(
|
630 |
-
'post_content' => '',
|
631 |
-
'post_status' => 'publish',
|
632 |
-
'post_type' => CARTFLOWS_FLOW_POST_TYPE,
|
633 |
-
);
|
634 |
-
|
635 |
-
// Insert the post into the database.
|
636 |
-
$flow_id = wp_insert_post( $new_flow_post );
|
637 |
-
|
638 |
-
if ( is_wp_error( $flow_id ) ) {
|
639 |
-
wp_send_json_error( $flow_id->get_error_message() );
|
640 |
-
}
|
641 |
-
|
642 |
-
$flow_steps = array();
|
643 |
-
|
644 |
-
$steps_data = array(
|
645 |
-
'landing' => __( 'Landing Page', 'cartflows' ),
|
646 |
-
'checkout' => __( 'Checkout Page', 'cartflows' ),
|
647 |
-
'thankyou' => __( 'Thank You Page', 'cartflows' ),
|
648 |
-
);
|
649 |
-
|
650 |
-
foreach ( $steps_data as $slug => $title ) {
|
651 |
-
|
652 |
-
$post_content = '';
|
653 |
-
|
654 |
-
switch ( $slug ) {
|
655 |
-
case 'checkout':
|
656 |
-
$post_content = '';
|
657 |
-
break;
|
658 |
-
case 'thankyou':
|
659 |
-
$post_content = '';
|
660 |
-
break;
|
661 |
-
default:
|
662 |
-
$post_content = '';
|
663 |
-
break;
|
664 |
-
}
|
665 |
-
|
666 |
-
$step_id = wp_insert_post(
|
667 |
-
array(
|
668 |
-
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
669 |
-
'post_title' => $title,
|
670 |
-
'post_content' => $post_content,
|
671 |
-
'post_status' => 'publish',
|
672 |
-
)
|
673 |
-
);
|
674 |
-
|
675 |
-
if ( is_wp_error( $step_id ) ) {
|
676 |
-
wp_send_json_error( $step_id->get_error_message() );
|
677 |
-
}
|
678 |
-
|
679 |
-
if ( $step_id ) {
|
680 |
-
|
681 |
-
$flow_steps[] = array(
|
682 |
-
'id' => $step_id,
|
683 |
-
'title' => $title,
|
684 |
-
'type' => $slug,
|
685 |
-
);
|
686 |
-
|
687 |
-
// insert post meta.
|
688 |
-
update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
|
689 |
-
update_post_meta( $step_id, 'wcf-step-type', $slug );
|
690 |
-
|
691 |
-
wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
692 |
-
wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
693 |
-
}
|
694 |
-
}
|
695 |
-
|
696 |
-
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
697 |
-
|
698 |
-
wp_send_json_success( $flow_id );
|
699 |
-
}
|
700 |
-
|
701 |
-
/**
|
702 |
-
* Create Flow
|
703 |
-
*
|
704 |
-
* @return void
|
705 |
-
*/
|
706 |
-
function create_flow() {
|
707 |
-
|
708 |
-
check_ajax_referer( 'cf-create-flow', 'security' );
|
709 |
-
|
710 |
-
// Create post object.
|
711 |
-
$new_flow_post = array(
|
712 |
-
'post_content' => '',
|
713 |
-
'post_status' => 'publish',
|
714 |
-
'post_type' => CARTFLOWS_FLOW_POST_TYPE,
|
715 |
-
);
|
716 |
-
|
717 |
-
// Insert the post into the database.
|
718 |
-
$flow_id = wp_insert_post( $new_flow_post );
|
719 |
-
|
720 |
-
if ( is_wp_error( $flow_id ) ) {
|
721 |
-
wp_send_json_error( $flow_id->get_error_message() );
|
722 |
-
}
|
723 |
-
|
724 |
-
wp_send_json_success( $flow_id );
|
725 |
-
}
|
726 |
-
|
727 |
-
/**
|
728 |
-
* Create Step
|
729 |
-
*
|
730 |
-
* @return void
|
731 |
-
*/
|
732 |
-
function import_step() {
|
733 |
-
|
734 |
-
check_ajax_referer( 'cf-step-import', 'security' );
|
735 |
-
|
736 |
-
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
|
737 |
-
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
738 |
-
$step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
|
739 |
-
$step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
|
740 |
-
$step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
|
741 |
-
|
742 |
-
$cartflow_meta = Cartflows_Flow_Meta::get_instance();
|
743 |
-
|
744 |
-
$post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
|
745 |
-
|
746 |
-
wcf()->logger->import_log( '------------------------------------' );
|
747 |
-
wcf()->logger->import_log( 'STARTED! Importing STEP' );
|
748 |
-
wcf()->logger->import_log( '------------------------------------' );
|
749 |
-
|
750 |
-
if ( empty( $template_id ) || empty( $post_id ) ) {
|
751 |
-
/* translators: %s: template ID */
|
752 |
-
$data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
|
753 |
-
wcf()->logger->import_log( $data );
|
754 |
-
wp_send_json_error( $data );
|
755 |
-
}
|
756 |
-
|
757 |
-
wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
|
758 |
-
|
759 |
-
$response = CartFlows_API::get_instance()->get_template( $template_id );
|
760 |
-
|
761 |
-
wcf()->logger->import_log( json_encode( $response ) );
|
762 |
-
|
763 |
-
// Import Post Meta.
|
764 |
-
self::import_post_meta( $post_id, $response );
|
765 |
-
|
766 |
-
do_action( 'cartflows_import_complete' );
|
767 |
-
|
768 |
-
// Batch Process.
|
769 |
-
do_action( 'cartflows_after_template_import', $post_id, $response );
|
770 |
-
|
771 |
-
wcf()->logger->import_log( '------------------------------------' );
|
772 |
-
wcf()->logger->import_log( 'COMPLETE! Importing Step' );
|
773 |
-
wcf()->logger->import_log( '------------------------------------' );
|
774 |
-
|
775 |
-
wp_send_json_success( $post_id );
|
776 |
-
}
|
777 |
-
|
778 |
-
/**
|
779 |
-
* Import Step.
|
780 |
-
*
|
781 |
-
* @since 1.0.0
|
782 |
-
* @hook wp_ajax_cartflows_step_create_blank
|
783 |
-
*
|
784 |
-
* @return void
|
785 |
-
*/
|
786 |
-
function step_create_blank() {
|
787 |
-
|
788 |
-
check_ajax_referer( 'cf-step-create-blank', 'security' );
|
789 |
-
|
790 |
-
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
791 |
-
$step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
|
792 |
-
$step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
|
793 |
-
|
794 |
-
if ( empty( $flow_id ) || empty( $step_type ) ) {
|
795 |
-
/* translators: %s: flow ID */
|
796 |
-
$data = sprintf( __( 'Invalid flow id %1$s or step type %2$s.', 'cartflows' ), $flow_id, $step_type );
|
797 |
-
wcf()->logger->import_log( $data );
|
798 |
-
wp_send_json_error( $data );
|
799 |
-
}
|
800 |
-
|
801 |
-
wcf()->logger->import_log( '------------------------------------' );
|
802 |
-
wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
|
803 |
-
|
804 |
-
$step_type_title = str_replace( '-', ' ', $step_type );
|
805 |
-
$step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
|
806 |
-
|
807 |
-
$new_step_id = wp_insert_post(
|
808 |
-
array(
|
809 |
-
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
810 |
-
'post_title' => $step_title,
|
811 |
-
'post_content' => '',
|
812 |
-
'post_status' => 'publish',
|
813 |
-
)
|
814 |
-
);
|
815 |
-
|
816 |
-
// insert post meta.
|
817 |
-
update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
|
818 |
-
|
819 |
-
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
820 |
-
$term_exist = term_exists( $step_type_title, $taxonomy );
|
821 |
-
|
822 |
-
if ( empty( $term_exist ) ) {
|
823 |
-
$terms = array(
|
824 |
-
array(
|
825 |
-
'name' => $step_type_title,
|
826 |
-
),
|
827 |
-
);
|
828 |
-
|
829 |
-
Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
|
830 |
-
wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
|
831 |
-
}
|
832 |
-
|
833 |
-
$current_term = term_exists( $step_type_title, $taxonomy );
|
834 |
-
|
835 |
-
// Set type object.
|
836 |
-
$data = get_term( $current_term['term_id'], $taxonomy );
|
837 |
-
$step_slug = $data->slug;
|
838 |
-
wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
839 |
-
wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
|
840 |
-
|
841 |
-
// Set type.
|
842 |
-
update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
|
843 |
-
wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
|
844 |
-
|
845 |
-
// Set flow.
|
846 |
-
wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
847 |
-
wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
|
848 |
-
|
849 |
-
CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
|
850 |
-
|
851 |
-
wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
|
852 |
-
wcf()->logger->import_log( '------------------------------------' );
|
853 |
-
|
854 |
-
wp_send_json_success( $new_step_id );
|
855 |
-
}
|
856 |
-
|
857 |
-
/**
|
858 |
-
* Import Post Meta
|
859 |
-
*
|
860 |
-
* @since 1.0.0
|
861 |
-
*
|
862 |
-
* @param integer $post_id Post ID.
|
863 |
-
* @param array $response Post meta.
|
864 |
-
* @return void
|
865 |
-
*/
|
866 |
-
public static function import_post_meta( $post_id, $response ) {
|
867 |
-
|
868 |
-
$metadata = (array) $response['post_meta'];
|
869 |
-
|
870 |
-
foreach ( $metadata as $meta_key => $meta_value ) {
|
871 |
-
$meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
|
872 |
-
|
873 |
-
if ( $meta_value ) {
|
874 |
-
|
875 |
-
if ( is_serialized( $meta_value, true ) ) {
|
876 |
-
$raw_data = maybe_unserialize( stripslashes( $meta_value ) );
|
877 |
-
} elseif ( is_array( $meta_value ) ) {
|
878 |
-
$raw_data = json_decode( stripslashes( $meta_value ), true );
|
879 |
-
} else {
|
880 |
-
$raw_data = $meta_value;
|
881 |
-
}
|
882 |
-
|
883 |
-
if ( '_elementor_data' === $meta_key ) {
|
884 |
-
|
885 |
-
if ( is_array( $raw_data ) ) {
|
886 |
-
$raw_data = wp_slash( json_encode( $raw_data ) );
|
887 |
-
} else {
|
888 |
-
$raw_data = wp_slash( $raw_data );
|
889 |
-
}
|
890 |
-
wcf()->logger->import_log( $raw_data );
|
891 |
-
}
|
892 |
-
|
893 |
-
if ( is_array( $raw_data ) ) {
|
894 |
-
wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
|
895 |
-
} else {
|
896 |
-
wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
|
897 |
-
}
|
898 |
-
|
899 |
-
update_post_meta( $post_id, $meta_key, $raw_data );
|
900 |
-
}
|
901 |
-
}
|
902 |
-
}
|
903 |
-
|
904 |
-
/**
|
905 |
-
* Import Template for Elementor
|
906 |
-
*
|
907 |
-
* @since 1.0.0
|
908 |
-
*
|
909 |
-
* @param integer $post_id Post ID.
|
910 |
-
* @param array $response Post meta.
|
911 |
-
* @param array $page_build_data Page build data.
|
912 |
-
* @return void
|
913 |
-
*/
|
914 |
-
public static function import_template_elementor( $post_id, $response, $page_build_data ) {
|
915 |
-
if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
|
916 |
-
$data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
|
917 |
-
wcf()->logger->import_log( $data );
|
918 |
-
wp_send_json_error( $data );
|
919 |
-
}
|
920 |
-
|
921 |
-
require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
|
922 |
-
|
923 |
-
wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
|
924 |
-
|
925 |
-
$obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
|
926 |
-
$obj->import_single_template( $post_id );
|
927 |
-
|
928 |
-
wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
|
929 |
-
}
|
930 |
-
|
931 |
-
/**
|
932 |
-
* Supported post types
|
933 |
-
*
|
934 |
-
* @since 1.0.0
|
935 |
-
*
|
936 |
-
* @return array Supported post types.
|
937 |
-
*/
|
938 |
-
public static function supported_post_types() {
|
939 |
-
return apply_filters(
|
940 |
-
'cartflows_supported_post_types',
|
941 |
-
array(
|
942 |
-
CARTFLOWS_FLOW_POST_TYPE,
|
943 |
-
)
|
944 |
-
);
|
945 |
-
}
|
946 |
-
|
947 |
-
/**
|
948 |
-
* Check supported post type
|
949 |
-
*
|
950 |
-
* @since 1.0.0
|
951 |
-
*
|
952 |
-
* @param string $post_type Post type.
|
953 |
-
* @return boolean Supported post type status.
|
954 |
-
*/
|
955 |
-
public static function is_supported_post( $post_type = '' ) {
|
956 |
-
if ( in_array( $post_type, self::supported_post_types() ) ) {
|
957 |
-
return true;
|
958 |
-
}
|
959 |
-
|
960 |
-
return false;
|
961 |
-
}
|
962 |
-
|
963 |
-
/**
|
964 |
-
* Set steps to the flow
|
965 |
-
*
|
966 |
-
* @param integer $flow_id Flow ID.
|
967 |
-
* @param integer $new_step_id New step ID.
|
968 |
-
* @param string $step_title Flow Type.
|
969 |
-
* @param string $step_slug Flow Type.
|
970 |
-
*/
|
971 |
-
function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
|
972 |
-
// Update steps for the current flow.
|
973 |
-
$flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
|
974 |
-
|
975 |
-
if ( ! is_array( $flow_steps ) ) {
|
976 |
-
$flow_steps = array();
|
977 |
-
}
|
978 |
-
|
979 |
-
$flow_steps[] = array(
|
980 |
-
'id' => $new_step_id,
|
981 |
-
'title' => $step_title,
|
982 |
-
'type' => $step_slug,
|
983 |
-
);
|
984 |
-
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
985 |
-
wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
|
986 |
-
}
|
987 |
-
|
988 |
-
/**
|
989 |
-
* Localize variables in admin
|
990 |
-
*
|
991 |
-
* @param array $vars variables.
|
992 |
-
*/
|
993 |
-
function localize_vars( $vars ) {
|
994 |
-
|
995 |
-
$ajax_actions = array(
|
996 |
-
'cf_step_import',
|
997 |
-
'cf_load_steps',
|
998 |
-
'cf_create_flow',
|
999 |
-
'cf_default_flow',
|
1000 |
-
'cf_step_create_blank',
|
1001 |
-
'cf_import_flow_step',
|
1002 |
-
);
|
1003 |
-
|
1004 |
-
foreach ( $ajax_actions as $action ) {
|
1005 |
-
|
1006 |
-
$vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
|
1007 |
-
}
|
1008 |
-
|
1009 |
-
return $vars;
|
1010 |
-
}
|
1011 |
-
|
1012 |
-
/**
|
1013 |
-
* Ajax action to activate plugin
|
1014 |
-
*/
|
1015 |
-
public function activate_plugin() {
|
1016 |
-
|
1017 |
-
$plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( $_POST['plugin_slug'] ) : '';
|
1018 |
-
|
1019 |
-
if ( ! is_plugin_active( $plugin_slug ) ) {
|
1020 |
-
|
1021 |
-
$activate = activate_plugin( $plugin_slug, '', false, true );
|
1022 |
-
|
1023 |
-
if ( is_wp_error( $activate ) ) {
|
1024 |
-
wp_send_json_error();
|
1025 |
-
}
|
1026 |
-
}
|
1027 |
-
|
1028 |
-
wp_send_json_success();
|
1029 |
-
}
|
1030 |
-
|
1031 |
-
}
|
1032 |
-
|
1033 |
-
/**
|
1034 |
-
* Initialize class object with 'get_instance()' method
|
1035 |
-
*/
|
1036 |
-
CartFlows_Importer::get_instance();
|
1037 |
-
|
1038 |
-
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 |
+
|
62 |
+
/**
|
63 |
+
* Clear Cache.
|
64 |
+
*
|
65 |
+
* @since 1.0.0
|
66 |
+
*/
|
67 |
+
public function clear_cache() {
|
68 |
+
// Clear 'Elementor' file cache.
|
69 |
+
if ( class_exists( '\Elementor\Plugin' ) ) {
|
70 |
+
Elementor\Plugin::$instance->files_manager->clear_cache();
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* JS Templates
|
76 |
+
*
|
77 |
+
* @since 1.0.0
|
78 |
+
*
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
function js_templates() {
|
82 |
+
|
83 |
+
// Loading Templates.
|
84 |
+
?>
|
85 |
+
<script type="text/template" id="tmpl-cartflows-step-loading">
|
86 |
+
<div class="template-message-block cartflows-step-loading">
|
87 |
+
<h2>
|
88 |
+
<span class="spinner"></span>
|
89 |
+
<?php _e( 'Loading Steps', 'cartflows' ); ?>
|
90 |
+
</h2>
|
91 |
+
<p class="description"><?php _e( 'Getting steps from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
|
92 |
+
</div>
|
93 |
+
</script>
|
94 |
+
|
95 |
+
<?php
|
96 |
+
// Search Templates.
|
97 |
+
?>
|
98 |
+
<script type="text/template" id="tmpl-cartflows-searching-templates">
|
99 |
+
<div class="template-message-block cartflows-searching-templates">
|
100 |
+
<h2>
|
101 |
+
<span class="spinner"></span>
|
102 |
+
<?php _e( 'Searching Template..', 'cartflows' ); ?>
|
103 |
+
</h2>
|
104 |
+
<p class="description"><?php _e( 'Getting templates from the cloud. Please wait for the moment.', 'cartflows' ); ?></p>
|
105 |
+
</div>
|
106 |
+
</script>
|
107 |
+
|
108 |
+
<?php
|
109 |
+
// CartFlows Importing Template.
|
110 |
+
?>
|
111 |
+
<script type="text/template" id="tmpl-cartflows-step-importing">
|
112 |
+
<div class="template-message-block cartflows-step-importing">
|
113 |
+
<h2><span class="spinner"></span> <?php _e( 'Importing..', 'cartflows' ); ?></h2>
|
114 |
+
</div>
|
115 |
+
</script>
|
116 |
+
|
117 |
+
<?php
|
118 |
+
// CartFlows Imported.
|
119 |
+
?>
|
120 |
+
<script type="text/template" id="tmpl-cartflows-step-imported">
|
121 |
+
<div class="template-message-block cartflows-step-imported">
|
122 |
+
<h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
|
123 |
+
<p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span></p></div>
|
124 |
+
</script>
|
125 |
+
|
126 |
+
<?php
|
127 |
+
// No templates.
|
128 |
+
?>
|
129 |
+
<script type="text/template" id="tmpl-cartflows-no-steps">
|
130 |
+
<div class="cartflows-no-steps">
|
131 |
+
<div class="template-message-block">
|
132 |
+
<h2><?php _e( 'Steps not found!', 'cartflows' ); ?></h2>
|
133 |
+
<p class="description"><?php _e( 'We\'ll provide the ready made steps to import.', 'cartflows' ); ?></p>
|
134 |
+
</div>
|
135 |
+
</div>
|
136 |
+
</script>
|
137 |
+
|
138 |
+
<?php
|
139 |
+
// No templates.
|
140 |
+
?>
|
141 |
+
<script type="text/template" id="tmpl-cartflows-no-flows">
|
142 |
+
<div class="cartflows-no-flows">
|
143 |
+
<div class="template-message-block">
|
144 |
+
<h2><?php _e( 'Flows not found!', 'cartflows' ); ?></h2>
|
145 |
+
<p class="description"><?php _e( 'We\'ll provide the ready made flows to import.', 'cartflows' ); ?></p>
|
146 |
+
</div>
|
147 |
+
</div>
|
148 |
+
</script>
|
149 |
+
|
150 |
+
<?php
|
151 |
+
// Error handling.
|
152 |
+
?>
|
153 |
+
<script type="text/template" id="tmpl-templator-error">
|
154 |
+
<div class="notice notice-error"><p>{{ data }}</p></div>
|
155 |
+
</script>
|
156 |
+
|
157 |
+
<?php
|
158 |
+
// Redirect to Elementor.
|
159 |
+
?>
|
160 |
+
<script type="text/template" id="tmpl-templator-redirect-to-elementor">
|
161 |
+
<div class="template-message-block templator-redirect-to-elementor">
|
162 |
+
<h2><span class="dashicons dashicons-yes"></span> <?php _e( 'Imported', 'cartflows' ); ?></h2>
|
163 |
+
<p class="description"><?php _e( 'Thanks for patience', 'cartflows' ); ?> <span class="dashicons dashicons-smiley"></span><br/><br/><?php _e( 'Redirecting to the Elementor edit window.', 'cartflows' ); ?> </p></div>
|
164 |
+
</script>
|
165 |
+
|
166 |
+
<?php
|
167 |
+
/**
|
168 |
+
* Responsive Buttons
|
169 |
+
*/
|
170 |
+
?>
|
171 |
+
<script type="text/template" id="tmpl-cartflows-responsive-view">
|
172 |
+
<span class="responsive-view">
|
173 |
+
<span class="actions">
|
174 |
+
<a class="desktop" href="#"><span data-view="desktop " class="active dashicons dashicons-desktop"></span></a>
|
175 |
+
<a class="tablet" href="#"><span data-view="tablet" class="dashicons dashicons-tablet"></span></a>
|
176 |
+
<a class="mobile" href="#"><span data-view="mobile" class="dashicons dashicons-smartphone"></span></a>
|
177 |
+
</span>
|
178 |
+
</span>
|
179 |
+
</script>
|
180 |
+
|
181 |
+
<?php
|
182 |
+
/** Blank flow */
|
183 |
+
?>
|
184 |
+
<script type="text/template" id="tmpl-cartflows-create-blank-flow">
|
185 |
+
<div class="inner">
|
186 |
+
<div class="template">
|
187 |
+
<span class="thumbnail site-preview">
|
188 |
+
<div class="template-screenshot">
|
189 |
+
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
|
190 |
+
</div>
|
191 |
+
</span>
|
192 |
+
<div class="template-id-container">
|
193 |
+
<h3 class="template-name"> <?php _e( 'Canvas', 'cartflows' ); ?> </h3>
|
194 |
+
<div class="template-actions">
|
195 |
+
<a href="#" class="button button-primary cartflows-flow-import-blank"><?php _e( 'Create Flow', 'cartflows' ); ?></a>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
</div>
|
200 |
+
</script>
|
201 |
+
|
202 |
+
<?php
|
203 |
+
// Templates data.
|
204 |
+
$installed_plugins = get_plugins();
|
205 |
+
|
206 |
+
$import_btn_title = __( 'Import', 'cartflows' );
|
207 |
+
|
208 |
+
$required_plugins = array(
|
209 |
+
'elementor' => array(
|
210 |
+
'active' => is_plugin_active( 'elementor/elementor.php' ) ? 'yes' : 'no',
|
211 |
+
'install' => isset( $installed_plugins['elementor/elementor.php'] ) ? 'yes' : 'no',
|
212 |
+
),
|
213 |
+
);
|
214 |
+
|
215 |
+
if ( 'yes' == $required_plugins['elementor']['install'] && 'no' == $required_plugins['elementor']['active'] ) {
|
216 |
+
$import_btn_title = __( 'Activate Elementor & Import', 'cartflows' );
|
217 |
+
} elseif ( 'no' == $required_plugins['elementor']['install'] ) {
|
218 |
+
$import_btn_title = __( 'Install Elementor & Import', 'cartflows' );
|
219 |
+
}
|
220 |
+
|
221 |
+
?>
|
222 |
+
<script type="text/template" id="tmpl-cartflows-flows-list">
|
223 |
+
|
224 |
+
<# if ( data.items.length ) { #>
|
225 |
+
<# for ( key in data.items ) { #>
|
226 |
+
<#
|
227 |
+
var flow_steps = [];
|
228 |
+
if( data.items[ key ].flow_steps ) {
|
229 |
+
flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
|
230 |
+
return value['id'];
|
231 |
+
});
|
232 |
+
}
|
233 |
+
#>
|
234 |
+
<div class="inner">
|
235 |
+
<div class="template">
|
236 |
+
<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 }}">
|
237 |
+
<div class="template-screenshot">
|
238 |
+
<# if( data.items[ key ].featured_image_url ) { #>
|
239 |
+
<img src="{{ data.items[ key ].featured_image_url }}" />
|
240 |
+
<# } else { #>
|
241 |
+
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
|
242 |
+
<# } #>
|
243 |
+
</div>
|
244 |
+
<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>
|
245 |
+
<# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
|
246 |
+
<span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
|
247 |
+
<# } #>
|
248 |
+
</span>
|
249 |
+
<div class="template-id-container">
|
250 |
+
<h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
|
251 |
+
<div class="template-actions">
|
252 |
+
|
253 |
+
<# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
|
254 |
+
<a data-flow-steps="{{ flow_steps }}" data-required="<?php echo htmlspecialchars( json_encode( $required_plugins ), ENT_QUOTES, 'UTF-8' ); ?>" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}"><?php echo $import_btn_title; ?></a>
|
255 |
+
<# } else if( CartFlowsImportVars._is_pro_active ) { #>
|
256 |
+
<a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
|
257 |
+
<# } else { #>
|
258 |
+
<a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
|
259 |
+
<# } #>
|
260 |
+
</div>
|
261 |
+
</div>
|
262 |
+
</div>
|
263 |
+
</div>
|
264 |
+
<# } #>
|
265 |
+
<# } #>
|
266 |
+
</script>
|
267 |
+
|
268 |
+
<?php
|
269 |
+
// Empty Step.
|
270 |
+
?>
|
271 |
+
<script type="text/template" id="tmpl-cartflows-create-blank-step">
|
272 |
+
<div class="inner">
|
273 |
+
<div class="template">
|
274 |
+
<span class="thumbnail site-preview cartflows-flow-preview">
|
275 |
+
<div class="template-screenshot">
|
276 |
+
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/start-scratch.jpg" />
|
277 |
+
</div>
|
278 |
+
<div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
|
279 |
+
</span>
|
280 |
+
<div class="template-id-container">
|
281 |
+
<h3 class="template-name"> Blank </h3>
|
282 |
+
<div class="template-actions">
|
283 |
+
<a href="#" class="button button-primary cartflows-step-import-blank"><?php _e( 'Create', 'cartflows' ); ?></a>
|
284 |
+
</div>
|
285 |
+
</div>
|
286 |
+
</div>
|
287 |
+
</div>
|
288 |
+
</script>
|
289 |
+
|
290 |
+
<?php
|
291 |
+
// Templates data.
|
292 |
+
?>
|
293 |
+
<script type="text/template" id="tmpl-cartflows-steps-list">
|
294 |
+
<# if ( data.items.length ) { #>
|
295 |
+
<# for ( key in data.items ) { #>
|
296 |
+
<#
|
297 |
+
var flow_steps = [];
|
298 |
+
if( data.items[ key ].flow_steps ) {
|
299 |
+
flow_steps = data.items[ key ].flow_steps.map(function(value,index) {
|
300 |
+
return value['id'];
|
301 |
+
});
|
302 |
+
}
|
303 |
+
#>
|
304 |
+
<div class="inner">
|
305 |
+
<div class="template">
|
306 |
+
<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 }}">
|
307 |
+
<div class="template-screenshot">
|
308 |
+
<# if( data.items[ key ].featured_image_url ) { #>
|
309 |
+
<img src="{{ data.items[ key ].featured_image_url }}" />
|
310 |
+
<# } else { #>
|
311 |
+
<img src="<?php echo esc_attr( CARTFLOWS_URL ); ?>assets/images/400x400.jpg" />
|
312 |
+
<# } #>
|
313 |
+
</div>
|
314 |
+
<div id="wcf_create_notice" class=""><a href="https://cartflows.com/" target="_blank"></a></div>
|
315 |
+
<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>
|
316 |
+
<# if( data.items[ key ].flow_type && 'pro' === data.items[ key ].flow_type.slug ) { #>
|
317 |
+
<span class="wcf-flow-type pro"><?php _e( 'Pro', 'cartflows' ); ?></span>
|
318 |
+
<# } #>
|
319 |
+
</span>
|
320 |
+
<div class="template-id-container">
|
321 |
+
<h3 class="template-name"> {{{ data.items[ key ].title.rendered }}} </h3>
|
322 |
+
<div class="template-actions">
|
323 |
+
<# if( data.items[ key ].licence_status && 'valid' === data.items[ key ].licence_status ) { #>
|
324 |
+
<a data-required="<?php echo htmlspecialchars( json_encode( $required_plugins ), ENT_QUOTES, 'UTF-8' ); ?>" data-flow-steps="{{ flow_steps }}" href="#" class="button button-primary cartflows-step-import" data-template-id="{{ data.items[ key ].id }}"><?php echo $import_btn_title; ?></a>
|
325 |
+
<# } else if( CartFlowsImportVars._is_pro_active ) { #>
|
326 |
+
<a target="_blank" href="<?php echo esc_url( admin_url( 'plugins.php?cartflows-license-popup' ) ); ?>" class="button button-primary"><?php _e( 'Activate License', 'cartflows' ); ?></a>
|
327 |
+
<# } else { #>
|
328 |
+
<a target="_blank" href="<?php echo esc_url( CARTFLOWS_DOMAIN_URL ); ?>" class="button button-primary"><?php _e( 'Get Pro', 'cartflows' ); ?></a>
|
329 |
+
<# } #>
|
330 |
+
</div>
|
331 |
+
</div>
|
332 |
+
</div>
|
333 |
+
</div>
|
334 |
+
<# } #>
|
335 |
+
<# } #>
|
336 |
+
</script>
|
337 |
+
|
338 |
+
<?php
|
339 |
+
/**
|
340 |
+
* TMPL - Filters
|
341 |
+
*/
|
342 |
+
?>
|
343 |
+
<script type="text/template" id="tmpl-cartflows-term-filters">
|
344 |
+
|
345 |
+
<# if ( data ) { #>
|
346 |
+
|
347 |
+
<ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
|
348 |
+
|
349 |
+
<# console.log( data.args.show_all ) #>
|
350 |
+
<# if ( data.args.show_all ) { #>
|
351 |
+
<li>
|
352 |
+
<a href="#" data-group="all"> All </a>
|
353 |
+
</li>
|
354 |
+
<# } #>
|
355 |
+
|
356 |
+
<# for ( key in data.items ) { #>
|
357 |
+
<li>
|
358 |
+
<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>
|
359 |
+
</li>
|
360 |
+
<# } #>
|
361 |
+
|
362 |
+
</ul>
|
363 |
+
<# } #>
|
364 |
+
</script>
|
365 |
+
|
366 |
+
<?php
|
367 |
+
// Step Type.
|
368 |
+
?>
|
369 |
+
<script type="text/template" id="tmpl-cartflows-step-types">
|
370 |
+
<ul class="wcf-tab nav-tabs">
|
371 |
+
<# if( data.items_count ) { #>
|
372 |
+
<# for( key in data.items ) { #>
|
373 |
+
<# console.log( data.items[ key ].id ) #>
|
374 |
+
<li data-slug="{{data.items[ key ].slug}}" data-title="{{ data.items[ key ].name }}">
|
375 |
+
<a href="#{{{ data.items[ key ].slug }}}">{{{ data.items[ key ].name }}}</a>
|
376 |
+
</li>
|
377 |
+
<# } #>
|
378 |
+
<# } #>
|
379 |
+
</ul>
|
380 |
+
</script>
|
381 |
+
|
382 |
+
<?php
|
383 |
+
// Add to library button.
|
384 |
+
?>
|
385 |
+
<script type="text/template" id="tmpl-templator-add-to-library">
|
386 |
+
<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>
|
387 |
+
</script>
|
388 |
+
<?php
|
389 |
+
}
|
390 |
+
|
391 |
+
/**
|
392 |
+
* Enqueue scripts
|
393 |
+
*
|
394 |
+
* @since 1.0.0
|
395 |
+
*
|
396 |
+
* @hook admin_enqueue_scripts
|
397 |
+
* @param string $hook Current page hook.
|
398 |
+
*/
|
399 |
+
function scripts( $hook = '' ) {
|
400 |
+
|
401 |
+
if ( ! self::is_supported_post( get_current_screen()->post_type ) ) {
|
402 |
+
return;
|
403 |
+
}
|
404 |
+
|
405 |
+
wp_enqueue_script( 'cartflows-rest-api', CARTFLOWS_URL . 'assets/js/rest-api.js', array( 'jquery' ), CARTFLOWS_VER, true );
|
406 |
+
wp_enqueue_style( 'cartflows-import', CARTFLOWS_URL . 'assets/css/import.css', null, CARTFLOWS_VER, 'all' );
|
407 |
+
wp_style_add_data( 'cartflows-import', 'rtl', 'replace' );
|
408 |
+
wp_enqueue_script( 'cartflows-import', CARTFLOWS_URL . 'assets/js/import.js', array( 'jquery', 'wp-util', 'cartflows-rest-api', 'updates' ), CARTFLOWS_VER, true );
|
409 |
+
|
410 |
+
$localize_vars = array(
|
411 |
+
'_is_pro_active' => _is_cartflows_pro(),
|
412 |
+
|
413 |
+
// Flow and its rest fields.
|
414 |
+
'flow' => CARTFLOWS_FLOW_POST_TYPE,
|
415 |
+
'flow_fields' => array(
|
416 |
+
'id',
|
417 |
+
'title',
|
418 |
+
'flow_type',
|
419 |
+
'flow_steps',
|
420 |
+
'licence_status',
|
421 |
+
'featured_image_url',
|
422 |
+
'featured_media', // @required for field `featured_image_url`.
|
423 |
+
),
|
424 |
+
|
425 |
+
// Flow type and rest fields.
|
426 |
+
'flow_type' => CARTFLOWS_TAXONOMY_FLOW_CATEGORY,
|
427 |
+
'flow_type_fields' => array(
|
428 |
+
'id',
|
429 |
+
'name',
|
430 |
+
'slug',
|
431 |
+
),
|
432 |
+
|
433 |
+
// Step and its rest fields.
|
434 |
+
'step' => CARTFLOWS_STEP_POST_TYPE,
|
435 |
+
'step_fields' => array(
|
436 |
+
'title',
|
437 |
+
'featured_image_url',
|
438 |
+
'featured_media', // @required for field `featured_image_url`.
|
439 |
+
'id',
|
440 |
+
'flow_type',
|
441 |
+
'licence_status',
|
442 |
+
),
|
443 |
+
|
444 |
+
// Step type and its rest fields.
|
445 |
+
'step_type' => CARTFLOWS_TAXONOMY_STEP_TYPE,
|
446 |
+
'step_type_fields' => array(
|
447 |
+
'id',
|
448 |
+
'name',
|
449 |
+
'slug',
|
450 |
+
),
|
451 |
+
|
452 |
+
'domain_url' => CARTFLOWS_DOMAIN_URL,
|
453 |
+
'server_url' => CARTFLOWS_TEMPLATES_URL,
|
454 |
+
'server_rest_url' => CARTFLOWS_TEMPLATES_URL . 'wp-json/wp/v2/',
|
455 |
+
'site_url' => site_url(),
|
456 |
+
'admin_url' => admin_url(),
|
457 |
+
'licence_args' => CartFlows_API::get_instance()->get_licence_args(),
|
458 |
+
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
459 |
+
'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
|
460 |
+
);
|
461 |
+
|
462 |
+
// Add thickbox.
|
463 |
+
add_thickbox();
|
464 |
+
|
465 |
+
wp_localize_script( 'cartflows-import', 'CartFlowsImportVars', $localize_vars );
|
466 |
+
wp_localize_script( 'cartflows-rest-api', 'CartFlowsImportVars', $localize_vars );
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Load Template
|
471 |
+
*
|
472 |
+
* @since 1.0.0
|
473 |
+
*
|
474 |
+
* @hook cartflows_load_steps
|
475 |
+
* @return void
|
476 |
+
*/
|
477 |
+
function load_templates() {
|
478 |
+
|
479 |
+
check_ajax_referer( 'cf-load-steps', 'security' );
|
480 |
+
|
481 |
+
$args = ( isset( $_POST['args'] ) ) ? array_map( 'sanitize_text_field', $_POST['args'] ) : array();
|
482 |
+
$templates = CartFlows_API::get_instance()->get_templates( $args );
|
483 |
+
|
484 |
+
if ( $templates['templates_count'] ) {
|
485 |
+
wp_send_json_success( $templates );
|
486 |
+
} else {
|
487 |
+
wp_send_json_error( $templates );
|
488 |
+
}
|
489 |
+
wp_die();
|
490 |
+
}
|
491 |
+
|
492 |
+
/**
|
493 |
+
* Import.
|
494 |
+
*
|
495 |
+
* @since 1.0.0
|
496 |
+
*
|
497 |
+
* @hook wp_ajax_cartflows_import_flow_step
|
498 |
+
* @return void
|
499 |
+
*/
|
500 |
+
function import_flow() {
|
501 |
+
|
502 |
+
check_ajax_referer( 'cf-import-flow-step', 'security' );
|
503 |
+
|
504 |
+
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
505 |
+
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
|
506 |
+
|
507 |
+
wcf()->logger->import_log( '------------------------------------' );
|
508 |
+
wcf()->logger->import_log( 'STARTED! Importing FLOW' );
|
509 |
+
wcf()->logger->import_log( '------------------------------------' );
|
510 |
+
wcf()->logger->import_log( '(✓) Creating new step from remote step [' . $template_id . '] for FLOW ' . get_the_title( $flow_id ) . ' [' . $flow_id . ']' );
|
511 |
+
|
512 |
+
$response = CartFlows_API::get_instance()->get_template( $template_id );
|
513 |
+
|
514 |
+
if ( false === $response['success'] ) {
|
515 |
+
wcf()->logger->import_log( '(✕) Failed to fetch remote data.' );
|
516 |
+
wp_send_json_error( $response );
|
517 |
+
}
|
518 |
+
|
519 |
+
wcf()->logger->import_log( '(✓) Successfully getting remote step response ' . json_encode( $response ) );
|
520 |
+
|
521 |
+
$new_step_id = wp_insert_post(
|
522 |
+
array(
|
523 |
+
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
524 |
+
'post_title' => $response['title'],
|
525 |
+
'post_content' => '',
|
526 |
+
'post_status' => 'publish',
|
527 |
+
)
|
528 |
+
);
|
529 |
+
|
530 |
+
if ( is_wp_error( $new_step_id ) ) {
|
531 |
+
wcf()->logger->import_log( '(✕) Failed to create new step for flow ' . $flow_id );
|
532 |
+
wp_send_json_error( $new_step_id );
|
533 |
+
}
|
534 |
+
|
535 |
+
wcf()->logger->import_log( '(✓) Created new step ' . '"' . $response['title'] . '" id ' . $new_step_id );
|
536 |
+
// insert post meta.
|
537 |
+
update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
|
538 |
+
wcf()->logger->import_log( '(✓) Added flow ID ' . $flow_id . ' in post meta key wcf-flow-id.' );
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Import & Set type.
|
542 |
+
*/
|
543 |
+
$term = isset( $response['data']['step_type'] ) ? $response['data']['step_type'] : '';
|
544 |
+
$term_slug = '';
|
545 |
+
if ( $term ) {
|
546 |
+
|
547 |
+
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
548 |
+
$term_exist = term_exists( $term->name, $taxonomy );
|
549 |
+
|
550 |
+
if ( empty( $term_exist ) ) {
|
551 |
+
$terms = array(
|
552 |
+
array(
|
553 |
+
'name' => $term->name,
|
554 |
+
),
|
555 |
+
);
|
556 |
+
|
557 |
+
Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
|
558 |
+
wcf()->logger->import_log( '(✓) Created new term ' . $term->name );
|
559 |
+
}
|
560 |
+
|
561 |
+
$current_term = term_exists( $term->name, $taxonomy );
|
562 |
+
|
563 |
+
// Set type object.
|
564 |
+
$data = get_term( $current_term['term_id'], $taxonomy );
|
565 |
+
$term_slug = $data->slug;
|
566 |
+
$term_name = $data->name;
|
567 |
+
wp_set_object_terms( $new_step_id, $term_slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
568 |
+
wcf()->logger->import_log( '(✓) Assigned existing term ' . $term_name . ' to the template ' . $new_step_id );
|
569 |
+
|
570 |
+
// Set type.
|
571 |
+
update_post_meta( $new_step_id, 'wcf-step-type', $term_slug );
|
572 |
+
wcf()->logger->import_log( '(✓) Updated term ' . $term_name . ' to the post meta wcf-step-type.' );
|
573 |
+
}
|
574 |
+
|
575 |
+
// Set flow.
|
576 |
+
wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
577 |
+
wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
|
578 |
+
|
579 |
+
/**
|
580 |
+
* Update steps for the current flow.
|
581 |
+
*/
|
582 |
+
$flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
|
583 |
+
|
584 |
+
if ( ! is_array( $flow_steps ) ) {
|
585 |
+
$flow_steps = array();
|
586 |
+
}
|
587 |
+
|
588 |
+
$flow_steps[] = array(
|
589 |
+
'id' => $new_step_id,
|
590 |
+
'title' => $response['title'],
|
591 |
+
'type' => $term_slug,
|
592 |
+
);
|
593 |
+
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
594 |
+
wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
|
595 |
+
|
596 |
+
// Import Post Meta.
|
597 |
+
self::import_post_meta( $new_step_id, $response );
|
598 |
+
|
599 |
+
wcf()->logger->import_log( '(✓) Importing step "' . get_the_title( $new_step_id ) . '" [' . $new_step_id . '] for FLOW "' . get_the_title( $flow_id ) . '" [' . $flow_id . ']' );
|
600 |
+
wcf()->logger->import_log( '------------------------------------' );
|
601 |
+
wcf()->logger->import_log( 'COMPLETE! Importing FLOW' );
|
602 |
+
wcf()->logger->import_log( '------------------------------------' );
|
603 |
+
|
604 |
+
do_action( 'cartflows_import_complete' );
|
605 |
+
wcf()->logger->import_log( '(✓) BATCH STARTED for step ' . $new_step_id . ' for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
|
606 |
+
|
607 |
+
// Batch Process.
|
608 |
+
do_action( 'cartflows_after_template_import', $new_step_id, $response );
|
609 |
+
|
610 |
+
/**
|
611 |
+
* End
|
612 |
+
*/
|
613 |
+
wp_send_json_success( $new_step_id );
|
614 |
+
}
|
615 |
+
|
616 |
+
/**
|
617 |
+
* Import Step.
|
618 |
+
*
|
619 |
+
* @since 1.0.0
|
620 |
+
* @hook wp_ajax_cartflows_step_import
|
621 |
+
*
|
622 |
+
* @return void
|
623 |
+
*/
|
624 |
+
function create_default_flow() {
|
625 |
+
|
626 |
+
check_ajax_referer( 'cf-default-flow', 'security' );
|
627 |
+
|
628 |
+
// Create post object.
|
629 |
+
$new_flow_post = array(
|
630 |
+
'post_content' => '',
|
631 |
+
'post_status' => 'publish',
|
632 |
+
'post_type' => CARTFLOWS_FLOW_POST_TYPE,
|
633 |
+
);
|
634 |
+
|
635 |
+
// Insert the post into the database.
|
636 |
+
$flow_id = wp_insert_post( $new_flow_post );
|
637 |
+
|
638 |
+
if ( is_wp_error( $flow_id ) ) {
|
639 |
+
wp_send_json_error( $flow_id->get_error_message() );
|
640 |
+
}
|
641 |
+
|
642 |
+
$flow_steps = array();
|
643 |
+
|
644 |
+
$steps_data = array(
|
645 |
+
'landing' => __( 'Landing Page', 'cartflows' ),
|
646 |
+
'checkout' => __( 'Checkout Page', 'cartflows' ),
|
647 |
+
'thankyou' => __( 'Thank You Page', 'cartflows' ),
|
648 |
+
);
|
649 |
+
|
650 |
+
foreach ( $steps_data as $slug => $title ) {
|
651 |
+
|
652 |
+
$post_content = '';
|
653 |
+
|
654 |
+
switch ( $slug ) {
|
655 |
+
case 'checkout':
|
656 |
+
$post_content = '';
|
657 |
+
break;
|
658 |
+
case 'thankyou':
|
659 |
+
$post_content = '';
|
660 |
+
break;
|
661 |
+
default:
|
662 |
+
$post_content = '';
|
663 |
+
break;
|
664 |
+
}
|
665 |
+
|
666 |
+
$step_id = wp_insert_post(
|
667 |
+
array(
|
668 |
+
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
669 |
+
'post_title' => $title,
|
670 |
+
'post_content' => $post_content,
|
671 |
+
'post_status' => 'publish',
|
672 |
+
)
|
673 |
+
);
|
674 |
+
|
675 |
+
if ( is_wp_error( $step_id ) ) {
|
676 |
+
wp_send_json_error( $step_id->get_error_message() );
|
677 |
+
}
|
678 |
+
|
679 |
+
if ( $step_id ) {
|
680 |
+
|
681 |
+
$flow_steps[] = array(
|
682 |
+
'id' => $step_id,
|
683 |
+
'title' => $title,
|
684 |
+
'type' => $slug,
|
685 |
+
);
|
686 |
+
|
687 |
+
// insert post meta.
|
688 |
+
update_post_meta( $step_id, 'wcf-flow-id', $flow_id );
|
689 |
+
update_post_meta( $step_id, 'wcf-step-type', $slug );
|
690 |
+
|
691 |
+
wp_set_object_terms( $step_id, $slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
692 |
+
wp_set_object_terms( $step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
693 |
+
}
|
694 |
+
}
|
695 |
+
|
696 |
+
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
697 |
+
|
698 |
+
wp_send_json_success( $flow_id );
|
699 |
+
}
|
700 |
+
|
701 |
+
/**
|
702 |
+
* Create Flow
|
703 |
+
*
|
704 |
+
* @return void
|
705 |
+
*/
|
706 |
+
function create_flow() {
|
707 |
+
|
708 |
+
check_ajax_referer( 'cf-create-flow', 'security' );
|
709 |
+
|
710 |
+
// Create post object.
|
711 |
+
$new_flow_post = array(
|
712 |
+
'post_content' => '',
|
713 |
+
'post_status' => 'publish',
|
714 |
+
'post_type' => CARTFLOWS_FLOW_POST_TYPE,
|
715 |
+
);
|
716 |
+
|
717 |
+
// Insert the post into the database.
|
718 |
+
$flow_id = wp_insert_post( $new_flow_post );
|
719 |
+
|
720 |
+
if ( is_wp_error( $flow_id ) ) {
|
721 |
+
wp_send_json_error( $flow_id->get_error_message() );
|
722 |
+
}
|
723 |
+
|
724 |
+
wp_send_json_success( $flow_id );
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Create Step
|
729 |
+
*
|
730 |
+
* @return void
|
731 |
+
*/
|
732 |
+
function import_step() {
|
733 |
+
|
734 |
+
check_ajax_referer( 'cf-step-import', 'security' );
|
735 |
+
|
736 |
+
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : '';
|
737 |
+
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
738 |
+
$step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
|
739 |
+
$step_type = isset( $_POST['step_type'] ) ? sanitize_title( $_POST['step_type'] ) : '';
|
740 |
+
$step_custom_title = isset( $_POST['step_custom_title'] ) ? sanitize_title( $_POST['step_custom_title'] ) : $step_title;
|
741 |
+
|
742 |
+
$cartflow_meta = Cartflows_Flow_Meta::get_instance();
|
743 |
+
|
744 |
+
$post_id = $cartflow_meta->create_step( $flow_id, $step_type, $step_custom_title );
|
745 |
+
|
746 |
+
wcf()->logger->import_log( '------------------------------------' );
|
747 |
+
wcf()->logger->import_log( 'STARTED! Importing STEP' );
|
748 |
+
wcf()->logger->import_log( '------------------------------------' );
|
749 |
+
|
750 |
+
if ( empty( $template_id ) || empty( $post_id ) ) {
|
751 |
+
/* translators: %s: template ID */
|
752 |
+
$data = sprintf( __( 'Invalid template id %1$s or post id %2$s.', 'cartflows' ), $template_id, $post_id );
|
753 |
+
wcf()->logger->import_log( $data );
|
754 |
+
wp_send_json_error( $data );
|
755 |
+
}
|
756 |
+
|
757 |
+
wcf()->logger->import_log( 'Remote Step ' . $template_id . ' for local flow "' . get_the_title( $post_id ) . '" [' . $post_id . ']' );
|
758 |
+
|
759 |
+
$response = CartFlows_API::get_instance()->get_template( $template_id );
|
760 |
+
|
761 |
+
wcf()->logger->import_log( json_encode( $response ) );
|
762 |
+
|
763 |
+
// Import Post Meta.
|
764 |
+
self::import_post_meta( $post_id, $response );
|
765 |
+
|
766 |
+
do_action( 'cartflows_import_complete' );
|
767 |
+
|
768 |
+
// Batch Process.
|
769 |
+
do_action( 'cartflows_after_template_import', $post_id, $response );
|
770 |
+
|
771 |
+
wcf()->logger->import_log( '------------------------------------' );
|
772 |
+
wcf()->logger->import_log( 'COMPLETE! Importing Step' );
|
773 |
+
wcf()->logger->import_log( '------------------------------------' );
|
774 |
+
|
775 |
+
wp_send_json_success( $post_id );
|
776 |
+
}
|
777 |
+
|
778 |
+
/**
|
779 |
+
* Import Step.
|
780 |
+
*
|
781 |
+
* @since 1.0.0
|
782 |
+
* @hook wp_ajax_cartflows_step_create_blank
|
783 |
+
*
|
784 |
+
* @return void
|
785 |
+
*/
|
786 |
+
function step_create_blank() {
|
787 |
+
|
788 |
+
check_ajax_referer( 'cf-step-create-blank', 'security' );
|
789 |
+
|
790 |
+
$flow_id = isset( $_POST['flow_id'] ) ? intval( $_POST['flow_id'] ) : '';
|
791 |
+
$step_type = isset( $_POST['step_type'] ) ? sanitize_text_field( $_POST['step_type'] ) : '';
|
792 |
+
$step_title = isset( $_POST['step_title'] ) ? sanitize_text_field( $_POST['step_title'] ) : '';
|
793 |
+
|
794 |
+
if ( empty( $flow_id ) || empty( $step_type ) ) {
|
795 |
+
/* translators: %s: flow ID */
|
796 |
+
$data = sprintf( __( 'Invalid flow id %1$s or step type %2$s.', 'cartflows' ), $flow_id, $step_type );
|
797 |
+
wcf()->logger->import_log( $data );
|
798 |
+
wp_send_json_error( $data );
|
799 |
+
}
|
800 |
+
|
801 |
+
wcf()->logger->import_log( '------------------------------------' );
|
802 |
+
wcf()->logger->import_log( 'STARTED! Creating Blank STEP for Flow ' . $flow_id );
|
803 |
+
|
804 |
+
$step_type_title = str_replace( '-', ' ', $step_type );
|
805 |
+
$step_type_slug = strtolower( str_replace( '-', ' ', $step_type ) );
|
806 |
+
|
807 |
+
$new_step_id = wp_insert_post(
|
808 |
+
array(
|
809 |
+
'post_type' => CARTFLOWS_STEP_POST_TYPE,
|
810 |
+
'post_title' => $step_title,
|
811 |
+
'post_content' => '',
|
812 |
+
'post_status' => 'publish',
|
813 |
+
)
|
814 |
+
);
|
815 |
+
|
816 |
+
// insert post meta.
|
817 |
+
update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id );
|
818 |
+
|
819 |
+
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
820 |
+
$term_exist = term_exists( $step_type_title, $taxonomy );
|
821 |
+
|
822 |
+
if ( empty( $term_exist ) ) {
|
823 |
+
$terms = array(
|
824 |
+
array(
|
825 |
+
'name' => $step_type_title,
|
826 |
+
),
|
827 |
+
);
|
828 |
+
|
829 |
+
Cartflows_Step_Post_Type::get_instance()->add_terms( $taxonomy, $terms );
|
830 |
+
wcf()->logger->import_log( '(✓) Created new term ' . $step_type_title );
|
831 |
+
}
|
832 |
+
|
833 |
+
$current_term = term_exists( $step_type_title, $taxonomy );
|
834 |
+
|
835 |
+
// Set type object.
|
836 |
+
$data = get_term( $current_term['term_id'], $taxonomy );
|
837 |
+
$step_slug = $data->slug;
|
838 |
+
wp_set_object_terms( $new_step_id, $data->slug, CARTFLOWS_TAXONOMY_STEP_TYPE );
|
839 |
+
wcf()->logger->import_log( '(✓) Assigned existing term ' . $step_type_title . ' to the template ' . $new_step_id );
|
840 |
+
|
841 |
+
// Set type.
|
842 |
+
update_post_meta( $new_step_id, 'wcf-step-type', $data->slug );
|
843 |
+
wcf()->logger->import_log( '(✓) Updated term ' . $data->name . ' to the post meta wcf-step-type.' );
|
844 |
+
|
845 |
+
// Set flow.
|
846 |
+
wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW );
|
847 |
+
wcf()->logger->import_log( '(✓) Assigned flow step flow-' . $flow_id );
|
848 |
+
|
849 |
+
CartFlows_Importer::get_instance()->set_step_to_flow( $flow_id, $new_step_id, $step_type_title, $step_slug );
|
850 |
+
|
851 |
+
wcf()->logger->import_log( 'COMPLETE! Creating Blank STEP for Flow ' . $flow_id );
|
852 |
+
wcf()->logger->import_log( '------------------------------------' );
|
853 |
+
|
854 |
+
wp_send_json_success( $new_step_id );
|
855 |
+
}
|
856 |
+
|
857 |
+
/**
|
858 |
+
* Import Post Meta
|
859 |
+
*
|
860 |
+
* @since 1.0.0
|
861 |
+
*
|
862 |
+
* @param integer $post_id Post ID.
|
863 |
+
* @param array $response Post meta.
|
864 |
+
* @return void
|
865 |
+
*/
|
866 |
+
public static function import_post_meta( $post_id, $response ) {
|
867 |
+
|
868 |
+
$metadata = (array) $response['post_meta'];
|
869 |
+
|
870 |
+
foreach ( $metadata as $meta_key => $meta_value ) {
|
871 |
+
$meta_value = isset( $meta_value[0] ) ? $meta_value[0] : '';
|
872 |
+
|
873 |
+
if ( $meta_value ) {
|
874 |
+
|
875 |
+
if ( is_serialized( $meta_value, true ) ) {
|
876 |
+
$raw_data = maybe_unserialize( stripslashes( $meta_value ) );
|
877 |
+
} elseif ( is_array( $meta_value ) ) {
|
878 |
+
$raw_data = json_decode( stripslashes( $meta_value ), true );
|
879 |
+
} else {
|
880 |
+
$raw_data = $meta_value;
|
881 |
+
}
|
882 |
+
|
883 |
+
if ( '_elementor_data' === $meta_key ) {
|
884 |
+
|
885 |
+
if ( is_array( $raw_data ) ) {
|
886 |
+
$raw_data = wp_slash( json_encode( $raw_data ) );
|
887 |
+
} else {
|
888 |
+
$raw_data = wp_slash( $raw_data );
|
889 |
+
}
|
890 |
+
wcf()->logger->import_log( $raw_data );
|
891 |
+
}
|
892 |
+
|
893 |
+
if ( is_array( $raw_data ) ) {
|
894 |
+
wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . json_encode( $raw_data ) );
|
895 |
+
} else {
|
896 |
+
wcf()->logger->import_log( '(✓) Added post meta ' . $meta_key . ' | ' . $raw_data );
|
897 |
+
}
|
898 |
+
|
899 |
+
update_post_meta( $post_id, $meta_key, $raw_data );
|
900 |
+
}
|
901 |
+
}
|
902 |
+
}
|
903 |
+
|
904 |
+
/**
|
905 |
+
* Import Template for Elementor
|
906 |
+
*
|
907 |
+
* @since 1.0.0
|
908 |
+
*
|
909 |
+
* @param integer $post_id Post ID.
|
910 |
+
* @param array $response Post meta.
|
911 |
+
* @param array $page_build_data Page build data.
|
912 |
+
* @return void
|
913 |
+
*/
|
914 |
+
public static function import_template_elementor( $post_id, $response, $page_build_data ) {
|
915 |
+
if ( ! is_plugin_active( 'elementor/elementor.php' ) ) {
|
916 |
+
$data = __( 'Elementor is not activated. Please activate plugin Elementor Page Builder to import the step.', 'cartflows' );
|
917 |
+
wcf()->logger->import_log( $data );
|
918 |
+
wp_send_json_error( $data );
|
919 |
+
}
|
920 |
+
|
921 |
+
require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
|
922 |
+
|
923 |
+
wcf()->logger->import_log( '# Started "importing page builder data" for step ' . $post_id );
|
924 |
+
|
925 |
+
$obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor();
|
926 |
+
$obj->import_single_template( $post_id );
|
927 |
+
|
928 |
+
wcf()->logger->import_log( '# Complete "importing page builder data" for step ' . $post_id );
|
929 |
+
}
|
930 |
+
|
931 |
+
/**
|
932 |
+
* Supported post types
|
933 |
+
*
|
934 |
+
* @since 1.0.0
|
935 |
+
*
|
936 |
+
* @return array Supported post types.
|
937 |
+
*/
|
938 |
+
public static function supported_post_types() {
|
939 |
+
return apply_filters(
|
940 |
+
'cartflows_supported_post_types',
|
941 |
+
array(
|
942 |
+
CARTFLOWS_FLOW_POST_TYPE,
|
943 |
+
)
|
944 |
+
);
|
945 |
+
}
|
946 |
+
|
947 |
+
/**
|
948 |
+
* Check supported post type
|
949 |
+
*
|
950 |
+
* @since 1.0.0
|
951 |
+
*
|
952 |
+
* @param string $post_type Post type.
|
953 |
+
* @return boolean Supported post type status.
|
954 |
+
*/
|
955 |
+
public static function is_supported_post( $post_type = '' ) {
|
956 |
+
if ( in_array( $post_type, self::supported_post_types() ) ) {
|
957 |
+
return true;
|
958 |
+
}
|
959 |
+
|
960 |
+
return false;
|
961 |
+
}
|
962 |
+
|
963 |
+
/**
|
964 |
+
* Set steps to the flow
|
965 |
+
*
|
966 |
+
* @param integer $flow_id Flow ID.
|
967 |
+
* @param integer $new_step_id New step ID.
|
968 |
+
* @param string $step_title Flow Type.
|
969 |
+
* @param string $step_slug Flow Type.
|
970 |
+
*/
|
971 |
+
function set_step_to_flow( $flow_id, $new_step_id, $step_title, $step_slug ) {
|
972 |
+
// Update steps for the current flow.
|
973 |
+
$flow_steps = get_post_meta( $flow_id, 'wcf-steps', true );
|
974 |
+
|
975 |
+
if ( ! is_array( $flow_steps ) ) {
|
976 |
+
$flow_steps = array();
|
977 |
+
}
|
978 |
+
|
979 |
+
$flow_steps[] = array(
|
980 |
+
'id' => $new_step_id,
|
981 |
+
'title' => $step_title,
|
982 |
+
'type' => $step_slug,
|
983 |
+
);
|
984 |
+
update_post_meta( $flow_id, 'wcf-steps', $flow_steps );
|
985 |
+
wcf()->logger->import_log( '(✓) Updated flow steps post meta key \'wcf-steps\' ' . json_encode( $flow_steps ) );
|
986 |
+
}
|
987 |
+
|
988 |
+
/**
|
989 |
+
* Localize variables in admin
|
990 |
+
*
|
991 |
+
* @param array $vars variables.
|
992 |
+
*/
|
993 |
+
function localize_vars( $vars ) {
|
994 |
+
|
995 |
+
$ajax_actions = array(
|
996 |
+
'cf_step_import',
|
997 |
+
'cf_load_steps',
|
998 |
+
'cf_create_flow',
|
999 |
+
'cf_default_flow',
|
1000 |
+
'cf_step_create_blank',
|
1001 |
+
'cf_import_flow_step',
|
1002 |
+
);
|
1003 |
+
|
1004 |
+
foreach ( $ajax_actions as $action ) {
|
1005 |
+
|
1006 |
+
$vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
return $vars;
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
/**
|
1013 |
+
* Ajax action to activate plugin
|
1014 |
+
*/
|
1015 |
+
public function activate_plugin() {
|
1016 |
+
|
1017 |
+
$plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( $_POST['plugin_slug'] ) : '';
|
1018 |
+
|
1019 |
+
if ( ! is_plugin_active( $plugin_slug ) ) {
|
1020 |
+
|
1021 |
+
$activate = activate_plugin( $plugin_slug, '', false, true );
|
1022 |
+
|
1023 |
+
if ( is_wp_error( $activate ) ) {
|
1024 |
+
wp_send_json_error();
|
1025 |
+
}
|
1026 |
+
}
|
1027 |
+
|
1028 |
+
wp_send_json_success();
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
}
|
1032 |
+
|
1033 |
+
/**
|
1034 |
+
* Initialize class object with 'get_instance()' method
|
1035 |
+
*/
|
1036 |
+
CartFlows_Importer::get_instance();
|
1037 |
+
|
1038 |
+
endif;
|
classes/class-cartflows-loader.php
CHANGED
@@ -1,416 +1,416 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* CartFlows Loader.
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
if ( ! class_exists( 'Cartflows_Loader' ) ) {
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Class Cartflows_Loader.
|
12 |
-
*/
|
13 |
-
final class Cartflows_Loader {
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Member Variable
|
17 |
-
*
|
18 |
-
* @var instance
|
19 |
-
*/
|
20 |
-
private static $instance = null;
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Member Variable
|
24 |
-
*
|
25 |
-
* @var utils
|
26 |
-
*/
|
27 |
-
public $utils = null;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Member Variable
|
31 |
-
*
|
32 |
-
* @var logger
|
33 |
-
*/
|
34 |
-
public $logger = null;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Member Variable
|
38 |
-
*
|
39 |
-
* @var session
|
40 |
-
*/
|
41 |
-
public $session = null;
|
42 |
-
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Member Variable
|
46 |
-
*
|
47 |
-
* @var options
|
48 |
-
*/
|
49 |
-
public $options = null;
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Member Variable
|
53 |
-
*
|
54 |
-
* @var meta
|
55 |
-
*/
|
56 |
-
public $meta = null;
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Member Variable
|
60 |
-
*
|
61 |
-
* @var flow
|
62 |
-
*/
|
63 |
-
public $flow = null;
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Initiator
|
67 |
-
*/
|
68 |
-
public static function get_instance() {
|
69 |
-
|
70 |
-
if ( is_null( self::$instance ) ) {
|
71 |
-
|
72 |
-
self::$instance = new self;
|
73 |
-
|
74 |
-
/**
|
75 |
-
* CartFlows loaded.
|
76 |
-
*
|
77 |
-
* Fires when Cartflows was fully loaded and instantiated.
|
78 |
-
*
|
79 |
-
* @since 1.0.0
|
80 |
-
*/
|
81 |
-
do_action( 'cartflows_loaded' );
|
82 |
-
}
|
83 |
-
|
84 |
-
return self::$instance;
|
85 |
-
}
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Constructor
|
89 |
-
*/
|
90 |
-
public function __construct() {
|
91 |
-
|
92 |
-
$this->define_constants();
|
93 |
-
|
94 |
-
// Activation hook.
|
95 |
-
register_activation_hook( CARTFLOWS_FILE, array( $this, 'activation_reset' ) );
|
96 |
-
|
97 |
-
// deActivation hook.
|
98 |
-
register_deactivation_hook( CARTFLOWS_FILE, array( $this, 'deactivation_reset' ) );
|
99 |
-
|
100 |
-
add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 99 );
|
101 |
-
|
102 |
-
add_action( 'plugins_loaded', array( $this, 'load_cf_textdomain' ) );
|
103 |
-
|
104 |
-
// Update compatibility.
|
105 |
-
require_once CARTFLOWS_DIR . 'classes/class-cartflows-update.php';
|
106 |
-
}
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Defines all constants
|
110 |
-
*
|
111 |
-
* @since 1.0.0
|
112 |
-
*/
|
113 |
-
public function define_constants() {
|
114 |
-
|
115 |
-
define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
|
116 |
-
define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
|
117 |
-
define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
|
118 |
-
define( 'CARTFLOWS_VER', '1.1.0' );
|
119 |
-
define( 'CARTFLOWS_SLUG', 'cartflows' );
|
120 |
-
define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
|
121 |
-
|
122 |
-
define( 'CARTFLOWS_FLOW_POST_TYPE', 'cartflows_flow' );
|
123 |
-
define( 'CARTFLOWS_STEP_POST_TYPE', 'cartflows_step' );
|
124 |
-
|
125 |
-
if ( ! defined( 'CARTFLOWS_SERVER_URL' ) ) {
|
126 |
-
define( 'CARTFLOWS_SERVER_URL', 'https://my.cartflows.com/' );
|
127 |
-
}
|
128 |
-
define( 'CARTFLOWS_DOMAIN_URL', 'https://cartflows.com/' );
|
129 |
-
define( 'CARTFLOWS_TEMPLATES_URL', 'https://templates.cartflows.com/' );
|
130 |
-
define( 'CARTFLOWS_TAXONOMY_STEP_TYPE', 'cartflows_step_type' );
|
131 |
-
define( 'CARTFLOWS_TAXONOMY_STEP_FLOW', 'cartflows_step_flow' );
|
132 |
-
|
133 |
-
if ( ! defined( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER' ) ) {
|
134 |
-
define( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER', 'cartflows_step_page_builder' );
|
135 |
-
}
|
136 |
-
if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY' ) ) {
|
137 |
-
define( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY', 'cartflows_flow_category' );
|
138 |
-
}
|
139 |
-
}
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Loads plugin files.
|
143 |
-
*
|
144 |
-
* @since 1.0.0
|
145 |
-
*
|
146 |
-
* @return void
|
147 |
-
*/
|
148 |
-
function load_plugin() {
|
149 |
-
|
150 |
-
if ( ! function_exists( 'WC' ) ) {
|
151 |
-
add_action( 'admin_notices', array( $this, 'fails_to_load' ) );
|
152 |
-
return;
|
153 |
-
}
|
154 |
-
|
155 |
-
$this->load_helper_files_components();
|
156 |
-
$this->load_core_files();
|
157 |
-
$this->load_core_components();
|
158 |
-
|
159 |
-
/**
|
160 |
-
* CartFlows Init.
|
161 |
-
*
|
162 |
-
* Fires when Cartflows is instantiated.
|
163 |
-
*
|
164 |
-
* @since 1.0.0
|
165 |
-
*/
|
166 |
-
do_action( 'cartflows_init' );
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Load Helper Files and Components.
|
171 |
-
*
|
172 |
-
* @since 1.0.0
|
173 |
-
*
|
174 |
-
* @return void
|
175 |
-
*/
|
176 |
-
function load_helper_files_components() {
|
177 |
-
|
178 |
-
/* Public Utils */
|
179 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-utils.php';
|
180 |
-
|
181 |
-
/* Public Session */
|
182 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-session.php';
|
183 |
-
|
184 |
-
/* Public Global namespace functions */
|
185 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-functions.php';
|
186 |
-
|
187 |
-
/* Admin Helper */
|
188 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-helper.php';
|
189 |
-
|
190 |
-
/* Meta Default Values */
|
191 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-default-meta.php';
|
192 |
-
|
193 |
-
$this->utils = Cartflows_Utils::get_instance();
|
194 |
-
$this->session = Cartflows_Session::get_instance();
|
195 |
-
$this->options = Cartflows_Default_Meta::get_instance();
|
196 |
-
|
197 |
-
}
|
198 |
-
|
199 |
-
/**
|
200 |
-
* Load Core Files.
|
201 |
-
*
|
202 |
-
* @since 1.0.0
|
203 |
-
*
|
204 |
-
* @return void
|
205 |
-
*/
|
206 |
-
function load_core_files() {
|
207 |
-
|
208 |
-
/* Page builder compatibilty class */
|
209 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-compatibility.php';
|
210 |
-
|
211 |
-
/* Admin Meta Fields*/
|
212 |
-
include_once CARTFLOWS_DIR . 'classes/fields/typography/class-cartflows-font-families.php';
|
213 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta-fields.php';
|
214 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta.php';
|
215 |
-
|
216 |
-
/* Cloning */
|
217 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-cloning.php';
|
218 |
-
|
219 |
-
/* Admin Settings */
|
220 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin.php';
|
221 |
-
|
222 |
-
/* Core Modules */
|
223 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-logger.php';
|
224 |
-
|
225 |
-
/* Frontend Global */
|
226 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-frontend.php';
|
227 |
-
require_once CARTFLOWS_DIR . 'classes/class-cartflows-flow-frontend.php';
|
228 |
-
|
229 |
-
/* Modules */
|
230 |
-
include_once CARTFLOWS_DIR . 'modules/flow/class-cartflows-flow.php';
|
231 |
-
include_once CARTFLOWS_DIR . 'modules/landing/class-cartflows-landing.php';
|
232 |
-
include_once CARTFLOWS_DIR . 'modules/checkout/class-cartflows-checkout.php';
|
233 |
-
include_once CARTFLOWS_DIR . 'modules/thankyou/class-cartflows-thankyou.php';
|
234 |
-
|
235 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-api.php';
|
236 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer-core.php';
|
237 |
-
|
238 |
-
include_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-batch-process.php';
|
239 |
-
include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer.php';
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Load Core Components.
|
244 |
-
*
|
245 |
-
* @since 1.0.0
|
246 |
-
*
|
247 |
-
* @return void
|
248 |
-
*/
|
249 |
-
function load_core_components() {
|
250 |
-
|
251 |
-
$this->meta = Cartflows_Meta_Fields::get_instance();
|
252 |
-
$this->logger = Cartflows_Logger::get_instance();
|
253 |
-
$this->flow = Cartflows_Flow_Frontend::get_instance();
|
254 |
-
}
|
255 |
-
|
256 |
-
/**
|
257 |
-
* Load CartFlows Pro Text Domain.
|
258 |
-
* This will load the translation textdomain depending on the file priorities.
|
259 |
-
* 1. Global Languages /wp-content/languages/cartflows/ folder
|
260 |
-
* 2. Local dorectory /wp-content/plugins/cartflows/languages/ folder
|
261 |
-
*
|
262 |
-
* @since 1.0.3
|
263 |
-
* @return void
|
264 |
-
*/
|
265 |
-
public function load_cf_textdomain() {
|
266 |
-
|
267 |
-
// Default languages directory for CartFlows Pro.
|
268 |
-
$lang_dir = CARTFLOWS_DIR . 'languages/';
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Filters the languages directory path to use for CartFlows Pro.
|
272 |
-
*
|
273 |
-
* @param string $lang_dir The languages directory path.
|
274 |
-
*/
|
275 |
-
$lang_dir = apply_filters( 'cartflows_languages_directory', $lang_dir );
|
276 |
-
|
277 |
-
// Traditional WordPress plugin locale filter.
|
278 |
-
global $wp_version;
|
279 |
-
|
280 |
-
$get_locale = get_locale();
|
281 |
-
|
282 |
-
if ( $wp_version >= 4.7 ) {
|
283 |
-
$get_locale = get_user_locale();
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Language Locale for CartFlows Pro
|
288 |
-
*
|
289 |
-
* @var $get_locale The locale to use.
|
290 |
-
* Uses get_user_locale()` in WordPress 4.7 or greater,
|
291 |
-
* otherwise uses `get_locale()`.
|
292 |
-
*/
|
293 |
-
$locale = apply_filters( 'plugin_locale', $get_locale, 'cartflows' );
|
294 |
-
$mofile = sprintf( '%1$s-%2$s.mo', 'cartflows', $locale );
|
295 |
-
|
296 |
-
// Setup paths to current locale file.
|
297 |
-
$mofile_local = $lang_dir . $mofile;
|
298 |
-
$mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
|
299 |
-
|
300 |
-
if ( file_exists( $mofile_global ) ) {
|
301 |
-
// Look in global /wp-content/languages/cartflows/ folder.
|
302 |
-
load_textdomain( 'cartflows', $mofile_global );
|
303 |
-
} elseif ( file_exists( $mofile_local ) ) {
|
304 |
-
// Look in local /wp-content/plugins/cartflows/languages/ folder.
|
305 |
-
load_textdomain( 'cartflows', $mofile_local );
|
306 |
-
} else {
|
307 |
-
// Load the default language files.
|
308 |
-
load_plugin_textdomain( 'cartflows', false, $lang_dir );
|
309 |
-
}
|
310 |
-
}
|
311 |
-
|
312 |
-
/**
|
313 |
-
* Fires admin notice when Elementor is not installed and activated.
|
314 |
-
*
|
315 |
-
* @since 1.0.0
|
316 |
-
*
|
317 |
-
* @return void
|
318 |
-
*/
|
319 |
-
public function fails_to_load() {
|
320 |
-
|
321 |
-
$screen = get_current_screen();
|
322 |
-
|
323 |
-
if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
|
324 |
-
return;
|
325 |
-
}
|
326 |
-
|
327 |
-
$class = 'notice notice-error';
|
328 |
-
/* translators: %s: html tags */
|
329 |
-
$message = sprintf( __( 'The %1$sCartFlows%2$s plugin requires %1$sWooCommerce%2$s plugin installed & activated.', 'cartflows' ), '<strong>', '</strong>' );
|
330 |
-
|
331 |
-
$plugin = 'woocommerce/woocommerce.php';
|
332 |
-
|
333 |
-
if ( _is_woo_installed() ) {
|
334 |
-
if ( ! current_user_can( 'activate_plugins' ) ) {
|
335 |
-
return;
|
336 |
-
}
|
337 |
-
|
338 |
-
$action_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin );
|
339 |
-
$button_label = __( 'Activate WooCommerce', 'cartflows' );
|
340 |
-
|
341 |
-
} else {
|
342 |
-
if ( ! current_user_can( 'install_plugins' ) ) {
|
343 |
-
return;
|
344 |
-
}
|
345 |
-
|
346 |
-
$action_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
|
347 |
-
$button_label = __( 'Install WooCommerce', 'cartflows' );
|
348 |
-
}
|
349 |
-
|
350 |
-
$button = '<p><a href="' . $action_url . '" class="button-primary">' . $button_label . '</a></p><p></p>';
|
351 |
-
|
352 |
-
printf( '<div class="%1$s"><p>%2$s</p>%3$s</div>', esc_attr( $class ), $message, $button );
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Activation Reset
|
357 |
-
*/
|
358 |
-
function activation_reset() {
|
359 |
-
|
360 |
-
include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-flow-post-type.php';
|
361 |
-
include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-step-post-type.php';
|
362 |
-
|
363 |
-
Cartflows_Flow_Post_Type::get_instance()->flow_post_type();
|
364 |
-
Cartflows_Step_Post_Type::get_instance()->step_post_type();
|
365 |
-
flush_rewrite_rules();
|
366 |
-
}
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Deactivation Reset
|
370 |
-
*/
|
371 |
-
function deactivation_reset() {
|
372 |
-
}
|
373 |
-
|
374 |
-
/**
|
375 |
-
* Logger Class Instance
|
376 |
-
*/
|
377 |
-
function logger() {
|
378 |
-
return Cartflows_Logger::get_instance();
|
379 |
-
}
|
380 |
-
|
381 |
-
|
382 |
-
}
|
383 |
-
|
384 |
-
/**
|
385 |
-
* Prepare if class 'Cartflows_Loader' exist.
|
386 |
-
* Kicking this off by calling 'get_instance()' method
|
387 |
-
*/
|
388 |
-
Cartflows_Loader::get_instance();
|
389 |
-
}
|
390 |
-
|
391 |
-
/**
|
392 |
-
* Get global class.
|
393 |
-
*
|
394 |
-
* @return object
|
395 |
-
*/
|
396 |
-
function wcf() {
|
397 |
-
return Cartflows_Loader::get_instance();
|
398 |
-
}
|
399 |
-
|
400 |
-
if ( ! function_exists( '_is_woo_installed' ) ) {
|
401 |
-
|
402 |
-
/**
|
403 |
-
* Is woocommerce plugin installed.
|
404 |
-
*
|
405 |
-
* @since 1.0.0
|
406 |
-
*
|
407 |
-
* @access public
|
408 |
-
*/
|
409 |
-
function _is_woo_installed() {
|
410 |
-
|
411 |
-
$path = 'woocommerce/woocommerce.php';
|
412 |
-
$plugins = get_plugins();
|
413 |
-
|
414 |
-
return isset( $plugins[ $path ] );
|
415 |
-
}
|
416 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CartFlows Loader.
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'Cartflows_Loader' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Class Cartflows_Loader.
|
12 |
+
*/
|
13 |
+
final class Cartflows_Loader {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Member Variable
|
17 |
+
*
|
18 |
+
* @var instance
|
19 |
+
*/
|
20 |
+
private static $instance = null;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Member Variable
|
24 |
+
*
|
25 |
+
* @var utils
|
26 |
+
*/
|
27 |
+
public $utils = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Member Variable
|
31 |
+
*
|
32 |
+
* @var logger
|
33 |
+
*/
|
34 |
+
public $logger = null;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Member Variable
|
38 |
+
*
|
39 |
+
* @var session
|
40 |
+
*/
|
41 |
+
public $session = null;
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Member Variable
|
46 |
+
*
|
47 |
+
* @var options
|
48 |
+
*/
|
49 |
+
public $options = null;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Member Variable
|
53 |
+
*
|
54 |
+
* @var meta
|
55 |
+
*/
|
56 |
+
public $meta = null;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Member Variable
|
60 |
+
*
|
61 |
+
* @var flow
|
62 |
+
*/
|
63 |
+
public $flow = null;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Initiator
|
67 |
+
*/
|
68 |
+
public static function get_instance() {
|
69 |
+
|
70 |
+
if ( is_null( self::$instance ) ) {
|
71 |
+
|
72 |
+
self::$instance = new self;
|
73 |
+
|
74 |
+
/**
|
75 |
+
* CartFlows loaded.
|
76 |
+
*
|
77 |
+
* Fires when Cartflows was fully loaded and instantiated.
|
78 |
+
*
|
79 |
+
* @since 1.0.0
|
80 |
+
*/
|
81 |
+
do_action( 'cartflows_loaded' );
|
82 |
+
}
|
83 |
+
|
84 |
+
return self::$instance;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Constructor
|
89 |
+
*/
|
90 |
+
public function __construct() {
|
91 |
+
|
92 |
+
$this->define_constants();
|
93 |
+
|
94 |
+
// Activation hook.
|
95 |
+
register_activation_hook( CARTFLOWS_FILE, array( $this, 'activation_reset' ) );
|
96 |
+
|
97 |
+
// deActivation hook.
|
98 |
+
register_deactivation_hook( CARTFLOWS_FILE, array( $this, 'deactivation_reset' ) );
|
99 |
+
|
100 |
+
add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 99 );
|
101 |
+
|
102 |
+
add_action( 'plugins_loaded', array( $this, 'load_cf_textdomain' ) );
|
103 |
+
|
104 |
+
// Update compatibility.
|
105 |
+
require_once CARTFLOWS_DIR . 'classes/class-cartflows-update.php';
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Defines all constants
|
110 |
+
*
|
111 |
+
* @since 1.0.0
|
112 |
+
*/
|
113 |
+
public function define_constants() {
|
114 |
+
|
115 |
+
define( 'CARTFLOWS_BASE', plugin_basename( CARTFLOWS_FILE ) );
|
116 |
+
define( 'CARTFLOWS_DIR', plugin_dir_path( CARTFLOWS_FILE ) );
|
117 |
+
define( 'CARTFLOWS_URL', plugins_url( '/', CARTFLOWS_FILE ) );
|
118 |
+
define( 'CARTFLOWS_VER', '1.1.0.1' );
|
119 |
+
define( 'CARTFLOWS_SLUG', 'cartflows' );
|
120 |
+
define( 'CARTFLOWS_SETTINGS', 'cartflows_settings' );
|
121 |
+
|
122 |
+
define( 'CARTFLOWS_FLOW_POST_TYPE', 'cartflows_flow' );
|
123 |
+
define( 'CARTFLOWS_STEP_POST_TYPE', 'cartflows_step' );
|
124 |
+
|
125 |
+
if ( ! defined( 'CARTFLOWS_SERVER_URL' ) ) {
|
126 |
+
define( 'CARTFLOWS_SERVER_URL', 'https://my.cartflows.com/' );
|
127 |
+
}
|
128 |
+
define( 'CARTFLOWS_DOMAIN_URL', 'https://cartflows.com/' );
|
129 |
+
define( 'CARTFLOWS_TEMPLATES_URL', 'https://templates.cartflows.com/' );
|
130 |
+
define( 'CARTFLOWS_TAXONOMY_STEP_TYPE', 'cartflows_step_type' );
|
131 |
+
define( 'CARTFLOWS_TAXONOMY_STEP_FLOW', 'cartflows_step_flow' );
|
132 |
+
|
133 |
+
if ( ! defined( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER' ) ) {
|
134 |
+
define( 'CARTFLOWS_TAXONOMY_STEP_PAGE_BUILDER', 'cartflows_step_page_builder' );
|
135 |
+
}
|
136 |
+
if ( ! defined( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY' ) ) {
|
137 |
+
define( 'CARTFLOWS_TAXONOMY_FLOW_CATEGORY', 'cartflows_flow_category' );
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Loads plugin files.
|
143 |
+
*
|
144 |
+
* @since 1.0.0
|
145 |
+
*
|
146 |
+
* @return void
|
147 |
+
*/
|
148 |
+
function load_plugin() {
|
149 |
+
|
150 |
+
if ( ! function_exists( 'WC' ) ) {
|
151 |
+
add_action( 'admin_notices', array( $this, 'fails_to_load' ) );
|
152 |
+
return;
|
153 |
+
}
|
154 |
+
|
155 |
+
$this->load_helper_files_components();
|
156 |
+
$this->load_core_files();
|
157 |
+
$this->load_core_components();
|
158 |
+
|
159 |
+
/**
|
160 |
+
* CartFlows Init.
|
161 |
+
*
|
162 |
+
* Fires when Cartflows is instantiated.
|
163 |
+
*
|
164 |
+
* @since 1.0.0
|
165 |
+
*/
|
166 |
+
do_action( 'cartflows_init' );
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Load Helper Files and Components.
|
171 |
+
*
|
172 |
+
* @since 1.0.0
|
173 |
+
*
|
174 |
+
* @return void
|
175 |
+
*/
|
176 |
+
function load_helper_files_components() {
|
177 |
+
|
178 |
+
/* Public Utils */
|
179 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-utils.php';
|
180 |
+
|
181 |
+
/* Public Session */
|
182 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-session.php';
|
183 |
+
|
184 |
+
/* Public Global namespace functions */
|
185 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-functions.php';
|
186 |
+
|
187 |
+
/* Admin Helper */
|
188 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-helper.php';
|
189 |
+
|
190 |
+
/* Meta Default Values */
|
191 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-default-meta.php';
|
192 |
+
|
193 |
+
$this->utils = Cartflows_Utils::get_instance();
|
194 |
+
$this->session = Cartflows_Session::get_instance();
|
195 |
+
$this->options = Cartflows_Default_Meta::get_instance();
|
196 |
+
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Load Core Files.
|
201 |
+
*
|
202 |
+
* @since 1.0.0
|
203 |
+
*
|
204 |
+
* @return void
|
205 |
+
*/
|
206 |
+
function load_core_files() {
|
207 |
+
|
208 |
+
/* Page builder compatibilty class */
|
209 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-compatibility.php';
|
210 |
+
|
211 |
+
/* Admin Meta Fields*/
|
212 |
+
include_once CARTFLOWS_DIR . 'classes/fields/typography/class-cartflows-font-families.php';
|
213 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta-fields.php';
|
214 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-meta.php';
|
215 |
+
|
216 |
+
/* Cloning */
|
217 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-cloning.php';
|
218 |
+
|
219 |
+
/* Admin Settings */
|
220 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-admin.php';
|
221 |
+
|
222 |
+
/* Core Modules */
|
223 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-logger.php';
|
224 |
+
|
225 |
+
/* Frontend Global */
|
226 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-frontend.php';
|
227 |
+
require_once CARTFLOWS_DIR . 'classes/class-cartflows-flow-frontend.php';
|
228 |
+
|
229 |
+
/* Modules */
|
230 |
+
include_once CARTFLOWS_DIR . 'modules/flow/class-cartflows-flow.php';
|
231 |
+
include_once CARTFLOWS_DIR . 'modules/landing/class-cartflows-landing.php';
|
232 |
+
include_once CARTFLOWS_DIR . 'modules/checkout/class-cartflows-checkout.php';
|
233 |
+
include_once CARTFLOWS_DIR . 'modules/thankyou/class-cartflows-thankyou.php';
|
234 |
+
|
235 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-api.php';
|
236 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer-core.php';
|
237 |
+
|
238 |
+
include_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-batch-process.php';
|
239 |
+
include_once CARTFLOWS_DIR . 'classes/class-cartflows-importer.php';
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Load Core Components.
|
244 |
+
*
|
245 |
+
* @since 1.0.0
|
246 |
+
*
|
247 |
+
* @return void
|
248 |
+
*/
|
249 |
+
function load_core_components() {
|
250 |
+
|
251 |
+
$this->meta = Cartflows_Meta_Fields::get_instance();
|
252 |
+
$this->logger = Cartflows_Logger::get_instance();
|
253 |
+
$this->flow = Cartflows_Flow_Frontend::get_instance();
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Load CartFlows Pro Text Domain.
|
258 |
+
* This will load the translation textdomain depending on the file priorities.
|
259 |
+
* 1. Global Languages /wp-content/languages/cartflows/ folder
|
260 |
+
* 2. Local dorectory /wp-content/plugins/cartflows/languages/ folder
|
261 |
+
*
|
262 |
+
* @since 1.0.3
|
263 |
+
* @return void
|
264 |
+
*/
|
265 |
+
public function load_cf_textdomain() {
|
266 |
+
|
267 |
+
// Default languages directory for CartFlows Pro.
|
268 |
+
$lang_dir = CARTFLOWS_DIR . 'languages/';
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Filters the languages directory path to use for CartFlows Pro.
|
272 |
+
*
|
273 |
+
* @param string $lang_dir The languages directory path.
|
274 |
+
*/
|
275 |
+
$lang_dir = apply_filters( 'cartflows_languages_directory', $lang_dir );
|
276 |
+
|
277 |
+
// Traditional WordPress plugin locale filter.
|
278 |
+
global $wp_version;
|
279 |
+
|
280 |
+
$get_locale = get_locale();
|
281 |
+
|
282 |
+
if ( $wp_version >= 4.7 ) {
|
283 |
+
$get_locale = get_user_locale();
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Language Locale for CartFlows Pro
|
288 |
+
*
|
289 |
+
* @var $get_locale The locale to use.
|
290 |
+
* Uses get_user_locale()` in WordPress 4.7 or greater,
|
291 |
+
* otherwise uses `get_locale()`.
|
292 |
+
*/
|
293 |
+
$locale = apply_filters( 'plugin_locale', $get_locale, 'cartflows' );
|
294 |
+
$mofile = sprintf( '%1$s-%2$s.mo', 'cartflows', $locale );
|
295 |
+
|
296 |
+
// Setup paths to current locale file.
|
297 |
+
$mofile_local = $lang_dir . $mofile;
|
298 |
+
$mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
|
299 |
+
|
300 |
+
if ( file_exists( $mofile_global ) ) {
|
301 |
+
// Look in global /wp-content/languages/cartflows/ folder.
|
302 |
+
load_textdomain( 'cartflows', $mofile_global );
|
303 |
+
} elseif ( file_exists( $mofile_local ) ) {
|
304 |
+
// Look in local /wp-content/plugins/cartflows/languages/ folder.
|
305 |
+
load_textdomain( 'cartflows', $mofile_local );
|
306 |
+
} else {
|
307 |
+
// Load the default language files.
|
308 |
+
load_plugin_textdomain( 'cartflows', false, $lang_dir );
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Fires admin notice when Elementor is not installed and activated.
|
314 |
+
*
|
315 |
+
* @since 1.0.0
|
316 |
+
*
|
317 |
+
* @return void
|
318 |
+
*/
|
319 |
+
public function fails_to_load() {
|
320 |
+
|
321 |
+
$screen = get_current_screen();
|
322 |
+
|
323 |
+
if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
|
324 |
+
return;
|
325 |
+
}
|
326 |
+
|
327 |
+
$class = 'notice notice-error';
|
328 |
+
/* translators: %s: html tags */
|
329 |
+
$message = sprintf( __( 'The %1$sCartFlows%2$s plugin requires %1$sWooCommerce%2$s plugin installed & activated.', 'cartflows' ), '<strong>', '</strong>' );
|
330 |
+
|
331 |
+
$plugin = 'woocommerce/woocommerce.php';
|
332 |
+
|
333 |
+
if ( _is_woo_installed() ) {
|
334 |
+
if ( ! current_user_can( 'activate_plugins' ) ) {
|
335 |
+
return;
|
336 |
+
}
|
337 |
+
|
338 |
+
$action_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin );
|
339 |
+
$button_label = __( 'Activate WooCommerce', 'cartflows' );
|
340 |
+
|
341 |
+
} else {
|
342 |
+
if ( ! current_user_can( 'install_plugins' ) ) {
|
343 |
+
return;
|
344 |
+
}
|
345 |
+
|
346 |
+
$action_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
|
347 |
+
$button_label = __( 'Install WooCommerce', 'cartflows' );
|
348 |
+
}
|
349 |
+
|
350 |
+
$button = '<p><a href="' . $action_url . '" class="button-primary">' . $button_label . '</a></p><p></p>';
|
351 |
+
|
352 |
+
printf( '<div class="%1$s"><p>%2$s</p>%3$s</div>', esc_attr( $class ), $message, $button );
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Activation Reset
|
357 |
+
*/
|
358 |
+
function activation_reset() {
|
359 |
+
|
360 |
+
include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-flow-post-type.php';
|
361 |
+
include_once CARTFLOWS_DIR . 'modules/flow/classes/class-cartflows-step-post-type.php';
|
362 |
+
|
363 |
+
Cartflows_Flow_Post_Type::get_instance()->flow_post_type();
|
364 |
+
Cartflows_Step_Post_Type::get_instance()->step_post_type();
|
365 |
+
flush_rewrite_rules();
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Deactivation Reset
|
370 |
+
*/
|
371 |
+
function deactivation_reset() {
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Logger Class Instance
|
376 |
+
*/
|
377 |
+
function logger() {
|
378 |
+
return Cartflows_Logger::get_instance();
|
379 |
+
}
|
380 |
+
|
381 |
+
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Prepare if class 'Cartflows_Loader' exist.
|
386 |
+
* Kicking this off by calling 'get_instance()' method
|
387 |
+
*/
|
388 |
+
Cartflows_Loader::get_instance();
|
389 |
+
}
|
390 |
+
|
391 |
+
/**
|
392 |
+
* Get global class.
|
393 |
+
*
|
394 |
+
* @return object
|
395 |
+
*/
|
396 |
+
function wcf() {
|
397 |
+
return Cartflows_Loader::get_instance();
|
398 |
+
}
|
399 |
+
|
400 |
+
if ( ! function_exists( '_is_woo_installed' ) ) {
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Is woocommerce plugin installed.
|
404 |
+
*
|
405 |
+
* @since 1.0.0
|
406 |
+
*
|
407 |
+
* @access public
|
408 |
+
*/
|
409 |
+
function _is_woo_installed() {
|
410 |
+
|
411 |
+
$path = 'woocommerce/woocommerce.php';
|
412 |
+
$plugins = get_plugins();
|
413 |
+
|
414 |
+
return isset( $plugins[ $path ] );
|
415 |
+
}
|
416 |
+
}
|
classes/class-cartflows-meta-fields.php
CHANGED
@@ -1,962 +1,962 @@
|
|
1 |
-
<?php
|
2 |
-
// @codingStandardsIgnoreStart
|
3 |
-
/**
|
4 |
-
* Meta Fields.
|
5 |
-
*
|
6 |
-
* @package CartFlows
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Class Cartflows_Meta_Fields.
|
11 |
-
*/
|
12 |
-
class Cartflows_Meta_Fields {
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Instance
|
16 |
-
*
|
17 |
-
* @var $instance
|
18 |
-
*/
|
19 |
-
private static $instance;
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Initiator
|
23 |
-
*/
|
24 |
-
public static function get_instance() {
|
25 |
-
if ( ! isset( self::$instance ) ) {
|
26 |
-
self::$instance = new self;
|
27 |
-
}
|
28 |
-
|
29 |
-
return self::$instance;
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Constructor
|
34 |
-
*/
|
35 |
-
public function __construct() {
|
36 |
-
|
37 |
-
/* Add Scripts */
|
38 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'admin_meta_scripts' ), 20 );
|
39 |
-
|
40 |
-
add_action( 'wp_ajax_wcf_json_search_coupons', array( $this, 'json_search_coupons' ) );
|
41 |
-
|
42 |
-
add_action( 'wp_ajax_wcf_add_checkout_custom_field', array( $this, 'add_checkout_custom_field' ) );
|
43 |
-
add_action( 'wp_ajax_wcf_delete_checkout_custom_field', array( $this, 'delete_checkout_custom_field' ) );
|
44 |
-
|
45 |
-
add_action( 'wp_ajax_wcf_json_search_pages', array( $this, 'json_search_pages' ) );
|
46 |
-
|
47 |
-
add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
|
48 |
-
}
|
49 |
-
|
50 |
-
public function admin_meta_scripts() {
|
51 |
-
|
52 |
-
global $pagenow;
|
53 |
-
global $post;
|
54 |
-
|
55 |
-
$screen = get_current_screen();
|
56 |
-
|
57 |
-
if (
|
58 |
-
( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) &&
|
59 |
-
wcf()->utils->is_step_post_type( $screen->post_type )
|
60 |
-
) {
|
61 |
-
|
62 |
-
wp_enqueue_style( 'woocommerce_admin_styles' );
|
63 |
-
|
64 |
-
wp_enqueue_script( 'select2' );
|
65 |
-
wp_enqueue_script( 'wc-enhanced-select' );
|
66 |
-
|
67 |
-
wp_enqueue_script(
|
68 |
-
'wcf-admin-meta',
|
69 |
-
CARTFLOWS_URL . 'admin/meta-assets/js/admin-edit.js',
|
70 |
-
array( 'jquery', 'select2', 'wp-color-picker' ),
|
71 |
-
CARTFLOWS_VER,
|
72 |
-
true
|
73 |
-
);
|
74 |
-
|
75 |
-
wp_enqueue_style( 'wcf-admin-meta', CARTFLOWS_URL . 'admin/meta-assets/css/admin-edit.css', array( 'wp-color-picker' ), CARTFLOWS_VER );
|
76 |
-
wp_style_add_data( 'wcf-admin-meta', 'rtl', 'replace' );
|
77 |
-
|
78 |
-
$localize = array(
|
79 |
-
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
80 |
-
'google_fonts' => CartFlows_Font_Families::get_google_fonts(),
|
81 |
-
'system_fonts' => CartFlows_Font_Families::get_system_fonts(),
|
82 |
-
'font_weights' => array(
|
83 |
-
'100' => __( 'Thin 100', 'cartflows' ),
|
84 |
-
'200' => __( 'Extra-Light 200', 'cartflows' ),
|
85 |
-
'300' => __( 'Light 300', 'cartflows' ),
|
86 |
-
'400' => __( 'Normal 400', 'cartflows' ),
|
87 |
-
'500' => __( 'Medium 500', 'cartflows' ),
|
88 |
-
'600' => __( 'Semi-Bold 600', 'cartflows' ),
|
89 |
-
'700' => __( 'Bold 700', 'cartflows' ),
|
90 |
-
'800' => __( 'Extra-Bold 800', 'cartflows' ),
|
91 |
-
'900' => __( 'Ultra-Bold 900', 'cartflows' ),
|
92 |
-
)
|
93 |
-
);
|
94 |
-
|
95 |
-
wp_localize_script( 'jquery', 'wcf', apply_filters( 'wcf_js_localize', $localize ) );
|
96 |
-
|
97 |
-
do_action( 'cartflows_admin_meta_scripts' );
|
98 |
-
}
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Function to search coupons
|
103 |
-
*/
|
104 |
-
public function json_search_coupons() {
|
105 |
-
|
106 |
-
check_admin_referer( 'wcf-json-search-coupons', 'security' );
|
107 |
-
|
108 |
-
global $wpdb;
|
109 |
-
|
110 |
-
$term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
|
111 |
-
|
112 |
-
if ( empty( $term ) ) {
|
113 |
-
die();
|
114 |
-
}
|
115 |
-
|
116 |
-
$posts = wp_cache_get( 'wcf_search_coupons', 'wcf_funnel_Cart' );
|
117 |
-
|
118 |
-
if ( false === $posts ) {
|
119 |
-
$posts = $wpdb->get_results( // phpcs:ignore
|
120 |
-
$wpdb->prepare(
|
121 |
-
"SELECT *
|
122 |
-
FROM {$wpdb->prefix}posts
|
123 |
-
WHERE post_type = %s
|
124 |
-
AND post_title LIKE %s
|
125 |
-
AND post_status = %s",
|
126 |
-
'shop_coupon',
|
127 |
-
$wpdb->esc_like( $term ) . '%',
|
128 |
-
'publish'
|
129 |
-
)
|
130 |
-
);
|
131 |
-
wp_cache_set( 'wcf_search_coupons', $posts, 'wcf_funnel_Cart' );
|
132 |
-
}
|
133 |
-
|
134 |
-
$coupons_found = array();
|
135 |
-
$all_discount_types = wc_get_coupon_types();
|
136 |
-
|
137 |
-
if ( $posts ) {
|
138 |
-
foreach ( $posts as $post ) {
|
139 |
-
|
140 |
-
$discount_type = get_post_meta( $post->ID, 'discount_type', true );
|
141 |
-
|
142 |
-
if ( ! empty( $all_discount_types[ $discount_type ] ) ) {
|
143 |
-
$coupons_found[ get_the_title( $post->ID ) ] = get_the_title( $post->ID ) . ' (Type: ' . $all_discount_types[ $discount_type ] . ')';
|
144 |
-
}
|
145 |
-
}
|
146 |
-
}
|
147 |
-
|
148 |
-
wp_send_json( $coupons_found );
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* [add_checkout_custom_field description]
|
153 |
-
*
|
154 |
-
* @hook wcf_add_checkout_custom_field
|
155 |
-
*/
|
156 |
-
public function add_checkout_custom_field() {
|
157 |
-
|
158 |
-
check_ajax_referer( 'wcf-add-checkout-custom-field', 'security' );
|
159 |
-
|
160 |
-
$post_id = intval( $_POST['post_id'] );
|
161 |
-
$add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
|
162 |
-
$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
|
163 |
-
$options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
|
164 |
-
$label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
|
165 |
-
$name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
|
166 |
-
|
167 |
-
if ( '' !== $name ) {
|
168 |
-
|
169 |
-
$fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
|
170 |
-
$field_keys = array_keys($fields);
|
171 |
-
|
172 |
-
$name = $add_to . '_' . sanitize_key( $name );
|
173 |
-
if( in_array($name, $field_keys) ) {
|
174 |
-
$name = $name . '_' . rand( 0000, 9999 );
|
175 |
-
}
|
176 |
-
|
177 |
-
$field_data = array(
|
178 |
-
'type' => $type,
|
179 |
-
'label' => $label,
|
180 |
-
'placeholder' => '',
|
181 |
-
'class' => array( 'form-row-wide' ),
|
182 |
-
'label_class' => array(),
|
183 |
-
'required' => true,
|
184 |
-
'custom' => true,
|
185 |
-
);
|
186 |
-
|
187 |
-
if ( 'select' === $type ) {
|
188 |
-
|
189 |
-
$options = explode( ',', $options );
|
190 |
-
$field_data['options'] = array();
|
191 |
-
|
192 |
-
if ( is_array( $options ) && ! empty( $options ) ) {
|
193 |
-
|
194 |
-
foreach ( $options as $key => $value ) {
|
195 |
-
|
196 |
-
$field_data['options'][ $value ] = $value;
|
197 |
-
}
|
198 |
-
}
|
199 |
-
}
|
200 |
-
|
201 |
-
Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
|
202 |
-
|
203 |
-
$key = sanitize_key( $name );
|
204 |
-
$name = 'wcf-' . $key;
|
205 |
-
|
206 |
-
$field_args = array(
|
207 |
-
'label' => $label,
|
208 |
-
'name' => $name,
|
209 |
-
'value' => 'yes',
|
210 |
-
'after' => 'Enable',
|
211 |
-
);
|
212 |
-
|
213 |
-
$field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> | ';
|
214 |
-
$field_args['after_html'] .= '<a class="wcf-cpf-action-remove">' . __( 'Remove', 'cartflows' ) . '</a>';
|
215 |
-
$field_args['after_html'] .= '</span>';
|
216 |
-
|
217 |
-
$field_markup = wcf()->meta->get_checkbox_field( $field_args );
|
218 |
-
|
219 |
-
if( 'billing' === $add_to ) {
|
220 |
-
$add_to_class = 'wcf-cb-fields';
|
221 |
-
} else if( 'shipping' === $add_to ) {
|
222 |
-
$add_to_class = 'wcf-sb-fields';
|
223 |
-
}
|
224 |
-
|
225 |
-
$data = array(
|
226 |
-
'field_data' => $field_data,
|
227 |
-
'field_args' => $field_args,
|
228 |
-
'add_to_class' => $add_to_class,
|
229 |
-
'markup' => $field_markup,
|
230 |
-
);
|
231 |
-
|
232 |
-
wp_send_json( $data );
|
233 |
-
}
|
234 |
-
|
235 |
-
wp_send_json( false );
|
236 |
-
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* [delete_checkout_custom_field description]
|
241 |
-
*
|
242 |
-
* @hook wcf_delete_checkout_custom_field
|
243 |
-
* @return [type] [description]
|
244 |
-
*/
|
245 |
-
public function delete_checkout_custom_field() {
|
246 |
-
|
247 |
-
check_ajax_referer( 'wcf-delete-checkout-custom-field', 'security' );
|
248 |
-
|
249 |
-
$post_id = intval( $_POST['post_id'] );
|
250 |
-
$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
|
251 |
-
$key = sanitize_text_field( wp_unslash( $_POST['key'] ) );
|
252 |
-
|
253 |
-
if ( '' !== $key ) {
|
254 |
-
|
255 |
-
Cartflows_Helper::delete_checkout_field( $type, $key, $post_id );
|
256 |
-
|
257 |
-
wp_send_json( true );
|
258 |
-
|
259 |
-
}
|
260 |
-
|
261 |
-
wp_send_json( false );
|
262 |
-
|
263 |
-
}
|
264 |
-
|
265 |
-
/**
|
266 |
-
* Function to search coupons
|
267 |
-
*/
|
268 |
-
public function json_search_pages() {
|
269 |
-
|
270 |
-
check_ajax_referer( 'wcf-json-search-pages', 'security' );
|
271 |
-
|
272 |
-
$term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
|
273 |
-
|
274 |
-
if ( empty( $term ) ) {
|
275 |
-
die( 'not found' );
|
276 |
-
}
|
277 |
-
|
278 |
-
$search_string = $term;
|
279 |
-
$data = array();
|
280 |
-
$result = array();
|
281 |
-
|
282 |
-
add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
|
283 |
-
|
284 |
-
$query = new WP_Query(
|
285 |
-
array(
|
286 |
-
's' => $search_string,
|
287 |
-
'post_type' => 'page',
|
288 |
-
'posts_per_page' => - 1,
|
289 |
-
)
|
290 |
-
);
|
291 |
-
|
292 |
-
if ( $query->have_posts() ) {
|
293 |
-
while ( $query->have_posts() ) {
|
294 |
-
$query->the_post();
|
295 |
-
$title = get_the_title();
|
296 |
-
$title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
|
297 |
-
$id = get_the_id();
|
298 |
-
$data[] = array(
|
299 |
-
'id' => $id,
|
300 |
-
'text' => $title,
|
301 |
-
);
|
302 |
-
}
|
303 |
-
}
|
304 |
-
|
305 |
-
if ( is_array( $data ) && ! empty( $data ) ) {
|
306 |
-
$result[] = array(
|
307 |
-
'text' => '',
|
308 |
-
'children' => $data,
|
309 |
-
);
|
310 |
-
}
|
311 |
-
|
312 |
-
wp_reset_postdata();
|
313 |
-
|
314 |
-
// return the result in json.
|
315 |
-
wp_send_json( $result );
|
316 |
-
}
|
317 |
-
|
318 |
-
public function search_only_titles( $search, $wp_query ) {
|
319 |
-
if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
|
320 |
-
global $wpdb;
|
321 |
-
|
322 |
-
$q = $wp_query->query_vars;
|
323 |
-
$n = ! empty( $q['exact'] ) ? '' : '%';
|
324 |
-
|
325 |
-
$search = array();
|
326 |
-
|
327 |
-
foreach ( (array) $q['search_terms'] as $term ) {
|
328 |
-
$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
|
329 |
-
}
|
330 |
-
|
331 |
-
if ( ! is_user_logged_in() ) {
|
332 |
-
$search[] = "$wpdb->posts.post_password = ''";
|
333 |
-
}
|
334 |
-
|
335 |
-
$search = ' AND ' . implode( ' AND ', $search );
|
336 |
-
}
|
337 |
-
|
338 |
-
return $search;
|
339 |
-
}
|
340 |
-
|
341 |
-
function get_field( $field_data, $field_content ) {
|
342 |
-
|
343 |
-
$label = isset( $field_data['label'] ) ? $field_data['label'] : '';
|
344 |
-
$help = isset( $field_data['help'] ) ? $field_data['help'] : '';
|
345 |
-
$after_html = isset( $field_data['after_html'] ) ? $field_data['after_html'] : '';
|
346 |
-
|
347 |
-
$name_class = 'field-' . $field_data['name'];
|
348 |
-
|
349 |
-
$field_html = '<div class="wcf-field-row ' . $name_class . '">';
|
350 |
-
|
351 |
-
if( ! empty( $label ) || ! empty( $help ) ) {
|
352 |
-
$field_html .= '<div class="wcf-field-row-heading">';
|
353 |
-
if( ! empty( $label ) ) {
|
354 |
-
$field_html .= '<label>' . esc_html( $label ) . '</label>';
|
355 |
-
}
|
356 |
-
if ( ! empty( $help ) ) {
|
357 |
-
$field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help">';
|
358 |
-
// $field_html .= '<span class="wcf-tooltip" data-tooltip= "'. esc_attr( $help ) .'"></span>';
|
359 |
-
$field_html .= '</i>';
|
360 |
-
$field_html .= '<span class="wcf-tooltip-text">';
|
361 |
-
$field_html .= $help;
|
362 |
-
$field_html .= '</span>';
|
363 |
-
}
|
364 |
-
$field_html .= '</div>';
|
365 |
-
}
|
366 |
-
|
367 |
-
$field_html .= '<div class="wcf-field-row-content">';
|
368 |
-
$field_html .= $field_content;
|
369 |
-
|
370 |
-
if ( ! empty( $after_html ) ) {
|
371 |
-
$field_html .= $after_html;
|
372 |
-
}
|
373 |
-
|
374 |
-
$field_html .= '</div>';
|
375 |
-
$field_html .= '</div>';
|
376 |
-
|
377 |
-
return $field_html;
|
378 |
-
}
|
379 |
-
|
380 |
-
function get_text_field( $field_data ) {
|
381 |
-
|
382 |
-
$value = $field_data['value'];
|
383 |
-
|
384 |
-
$attr = '';
|
385 |
-
|
386 |
-
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
387 |
-
|
388 |
-
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
389 |
-
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
390 |
-
}
|
391 |
-
}
|
392 |
-
|
393 |
-
$field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
394 |
-
|
395 |
-
return $this->get_field( $field_data, $field_content );
|
396 |
-
}
|
397 |
-
|
398 |
-
function get_shortcode_field( $field_data ) {
|
399 |
-
|
400 |
-
$attr = '';
|
401 |
-
|
402 |
-
$attr_fields = array(
|
403 |
-
'readonly' => 'readonly',
|
404 |
-
'onfocus' => 'this.select()',
|
405 |
-
'onmouseup' => 'return false',
|
406 |
-
);
|
407 |
-
|
408 |
-
if ( $attr_fields && is_array( $attr_fields ) ) {
|
409 |
-
|
410 |
-
foreach ( $attr_fields as $attr_key => $attr_value ) {
|
411 |
-
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
412 |
-
}
|
413 |
-
}
|
414 |
-
|
415 |
-
$field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $field_data['content'] . '" ' . $attr . '>';
|
416 |
-
|
417 |
-
return $this->get_field( $field_data, $field_content );
|
418 |
-
}
|
419 |
-
|
420 |
-
function get_display_field( $field_data ) {
|
421 |
-
|
422 |
-
$field_content = $field_data['content'];
|
423 |
-
|
424 |
-
return $this->get_field( $field_data, $field_content );
|
425 |
-
}
|
426 |
-
|
427 |
-
function get_number_field( $field_data ) {
|
428 |
-
|
429 |
-
$value = $field_data['value'];
|
430 |
-
|
431 |
-
$attr = '';
|
432 |
-
|
433 |
-
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
434 |
-
|
435 |
-
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
436 |
-
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
437 |
-
}
|
438 |
-
}
|
439 |
-
|
440 |
-
$field_content = '<input type="number" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
441 |
-
|
442 |
-
return $this->get_field( $field_data, $field_content );
|
443 |
-
}
|
444 |
-
|
445 |
-
function get_hidden_field( $field_data ) {
|
446 |
-
|
447 |
-
$value = $field_data['value'];
|
448 |
-
|
449 |
-
$attr = '';
|
450 |
-
|
451 |
-
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
452 |
-
|
453 |
-
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
454 |
-
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
455 |
-
}
|
456 |
-
}
|
457 |
-
|
458 |
-
$field_content = '<input type="hidden" id="' . $field_data['name'] . '" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
459 |
-
|
460 |
-
return $this->get_field( $field_data, $field_content );
|
461 |
-
}
|
462 |
-
|
463 |
-
function get_area_field( $field_data ) {
|
464 |
-
|
465 |
-
$value = $field_data['value'];
|
466 |
-
|
467 |
-
$field_content = '<textarea name="' . $field_data['name'] . '" rows="10" cols="50">';
|
468 |
-
$field_content .= $value;
|
469 |
-
$field_content .= '</textarea>';
|
470 |
-
|
471 |
-
return $this->get_field( $field_data, $field_content );
|
472 |
-
}
|
473 |
-
|
474 |
-
function get_checkbox_field( $field_data ) {
|
475 |
-
|
476 |
-
$value = $field_data['value'];
|
477 |
-
|
478 |
-
$field_content = '';
|
479 |
-
if ( isset( $field_data['before'] ) ) {
|
480 |
-
$field_content .= '<span>' . $field_data['before'] . '</span>';
|
481 |
-
}
|
482 |
-
$field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
|
483 |
-
$field_content .= '<input type="checkbox" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
|
484 |
-
|
485 |
-
if ( isset( $field_data['after'] ) ) {
|
486 |
-
$field_content .= '<span>' . $field_data['after'] . '</span>';
|
487 |
-
}
|
488 |
-
|
489 |
-
return $this->get_field( $field_data, $field_content );
|
490 |
-
}
|
491 |
-
|
492 |
-
function get_font_family_field( $field_data ) {
|
493 |
-
|
494 |
-
$value = $field_data['value'];
|
495 |
-
|
496 |
-
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
497 |
-
|
498 |
-
$field_content = '<select class="wcf-field-font-family" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
|
499 |
-
|
500 |
-
$field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
|
501 |
-
|
502 |
-
$field_content .= '<optgroup label="Other System Fonts">';
|
503 |
-
foreach ( CartFlows_Font_Families::get_system_fonts() as $name => $variants ) {
|
504 |
-
$field_content .= '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $value, false ) . '>' . esc_attr( $name ) . '</option>';
|
505 |
-
}
|
506 |
-
$field_content .= '</optgroup>';
|
507 |
-
$field_content .= '<optgroup label="Google">';
|
508 |
-
foreach ( CartFlows_Font_Families::get_google_fonts() as $name => $single_font ) {
|
509 |
-
$variants = wcf_get_prop( $single_font, '0' );
|
510 |
-
$category = wcf_get_prop( $single_font, '1' );
|
511 |
-
$font_value = '\'' . esc_attr( $name ) . '\', ' . esc_attr( $category );
|
512 |
-
$field_content .= '<option value="' . esc_attr( $font_value ) . '" ' . selected( $font_value, $value, false ) . '>' . esc_attr( $name ) . '</option>';
|
513 |
-
}
|
514 |
-
$field_content .= '</optgroup>';
|
515 |
-
|
516 |
-
$field_content .= '</select>';
|
517 |
-
|
518 |
-
return $this->get_field( $field_data, $field_content );
|
519 |
-
}
|
520 |
-
|
521 |
-
function get_font_weight_field( $field_data ) {
|
522 |
-
|
523 |
-
$value = $field_data['value'];
|
524 |
-
|
525 |
-
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
526 |
-
|
527 |
-
$field_content = '<select data-selected="'.esc_attr( $value ).'" class="wcf-field-font-weight" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
|
528 |
-
|
529 |
-
$field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
|
530 |
-
|
531 |
-
$field_content .= '</select>';
|
532 |
-
|
533 |
-
return $this->get_field( $field_data, $field_content );
|
534 |
-
}
|
535 |
-
|
536 |
-
function get_select_field( $field_data ) {
|
537 |
-
|
538 |
-
$value = $field_data['value'];
|
539 |
-
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
540 |
-
|
541 |
-
$field_content = '<select name="' . $field_data['name'] . '">';
|
542 |
-
|
543 |
-
|
544 |
-
if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
|
545 |
-
|
546 |
-
foreach ( $field_data['options'] as $data_key => $data_value ) {
|
547 |
-
|
548 |
-
$disabled = '';
|
549 |
-
|
550 |
-
if ( array_key_exists( $data_key, $pro_options ) ) {
|
551 |
-
$disabled = 'disabled ';
|
552 |
-
$data_value = $pro_options[ $data_key ];
|
553 |
-
}
|
554 |
-
|
555 |
-
$field_content .= '<option value="' . $data_key . '" ' . selected( $value, $data_key, false ) . ' ' . $disabled .'>' . $data_value . '</option>';
|
556 |
-
}
|
557 |
-
}
|
558 |
-
|
559 |
-
$field_content .= '</select>';
|
560 |
-
|
561 |
-
if ( isset( $field_data['after'] ) ) {
|
562 |
-
$field_content .= '<span>' . $field_data['after'] . '</span>';
|
563 |
-
}
|
564 |
-
|
565 |
-
return $this->get_field( $field_data, $field_content );
|
566 |
-
}
|
567 |
-
|
568 |
-
function get_color_picker_field( $field_data ) {
|
569 |
-
|
570 |
-
$value = $field_data['value'];
|
571 |
-
|
572 |
-
$field_content = '<input class="wcf-color-picker" type="text" name="' . $field_data['name'] . '" value="' . $value . '">';
|
573 |
-
|
574 |
-
return $this->get_field( $field_data, $field_content );
|
575 |
-
}
|
576 |
-
|
577 |
-
function get_product_selection_field( $field_data ) {
|
578 |
-
|
579 |
-
$value = $field_data['value'];
|
580 |
-
|
581 |
-
$multiple = '';
|
582 |
-
|
583 |
-
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
584 |
-
$multiple = ' multiple="multiple"';
|
585 |
-
}
|
586 |
-
|
587 |
-
$allow_clear = '';
|
588 |
-
|
589 |
-
if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
|
590 |
-
$allow_clear = ' data-allow_clear="allow_clear"';
|
591 |
-
}
|
592 |
-
|
593 |
-
$field_content = '<select
|
594 |
-
name="' . $field_data['name'] . '[]"
|
595 |
-
class="wcf-product-search" ' . $multiple . $allow_clear . '
|
596 |
-
data-placeholder="' . __( 'Search for a product…', 'cartflows' ) . '"
|
597 |
-
data-action="woocommerce_json_search_products_and_variations">';
|
598 |
-
|
599 |
-
if ( is_array( $value ) && ! empty( $value ) ) {
|
600 |
-
|
601 |
-
foreach ( $value as $data_key => $product_id ) {
|
602 |
-
|
603 |
-
$product = wc_get_product( $product_id );
|
604 |
-
|
605 |
-
// posts.
|
606 |
-
if ( ! empty( $product ) ) {
|
607 |
-
$post_title = $product->get_name() . ' (#' . $product_id . ')';
|
608 |
-
|
609 |
-
$field_content .= '<option value="' . $product_id . '" selected="selected" >' . $post_title . '</option>';
|
610 |
-
}
|
611 |
-
}
|
612 |
-
}
|
613 |
-
$field_content .= '</select>';
|
614 |
-
|
615 |
-
return $this->get_field( $field_data, $field_content );
|
616 |
-
}
|
617 |
-
|
618 |
-
function get_coupon_selection_field( $field_data ) {
|
619 |
-
|
620 |
-
$value = $field_data['value'];
|
621 |
-
|
622 |
-
$multiple = '';
|
623 |
-
|
624 |
-
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
625 |
-
$multiple = ' multiple="multiple"';
|
626 |
-
}
|
627 |
-
|
628 |
-
$allow_clear = '';
|
629 |
-
|
630 |
-
if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
|
631 |
-
$allow_clear = ' data-allow_clear="allow_clear"';
|
632 |
-
}
|
633 |
-
|
634 |
-
$field_content = '<select
|
635 |
-
name="' . $field_data['name'] . '[]"
|
636 |
-
class="wc-coupon-search wcf-coupon-search" ' . $multiple . $allow_clear . '
|
637 |
-
data-placeholder="' . __( 'Search for a coupon…', 'cartflows' ) . '"
|
638 |
-
data-action="wcf_json_search_coupons">';
|
639 |
-
|
640 |
-
if ( is_array( $value ) && ! empty( $value ) ) {
|
641 |
-
|
642 |
-
$all_discount_types = wc_get_coupon_types();
|
643 |
-
|
644 |
-
foreach ( $value as $coupon_title ) {
|
645 |
-
|
646 |
-
$coupon = new WC_Coupon( $coupon_title );
|
647 |
-
|
648 |
-
$discount_type = $coupon->get_discount_type();
|
649 |
-
|
650 |
-
if ( isset( $discount_type ) && $discount_type ) {
|
651 |
-
$discount_type = ' ( Type: ' . $all_discount_types[ $discount_type ] . ' )';
|
652 |
-
}
|
653 |
-
|
654 |
-
$field_content .= '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>';
|
655 |
-
}
|
656 |
-
}
|
657 |
-
|
658 |
-
$field_content .= '</select>';
|
659 |
-
|
660 |
-
return $this->get_field( $field_data, $field_content );
|
661 |
-
}
|
662 |
-
|
663 |
-
function get_page_selection_field( $field_data ) {
|
664 |
-
|
665 |
-
$value = $field_data['value'];
|
666 |
-
|
667 |
-
$multiple = '';
|
668 |
-
|
669 |
-
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
670 |
-
$multiple = 'multiple="multiple"';
|
671 |
-
}
|
672 |
-
|
673 |
-
$field_content = '<select
|
674 |
-
name="' . $field_data['name'] . '[]"
|
675 |
-
class="wcf-search-pages" ' . $multiple . '"
|
676 |
-
data-action="wcf_json_search_pages">';
|
677 |
-
|
678 |
-
if ( is_array( $value ) && ! empty( $value ) ) {
|
679 |
-
|
680 |
-
foreach ( $value as $data_key => $data_value ) {
|
681 |
-
|
682 |
-
$field_content .= '<option value="' . $data_value . '">' . get_the_title( $data_value ) . '</option>';
|
683 |
-
}
|
684 |
-
}
|
685 |
-
|
686 |
-
$field_content .= '</select>';
|
687 |
-
|
688 |
-
return $this->get_field( $field_data, $field_content );
|
689 |
-
}
|
690 |
-
|
691 |
-
function get_section( $field_data ) {
|
692 |
-
$field_html = '<div class="wcf-field-row wcf-field-section">';
|
693 |
-
$field_html .= '<div class="wcf-field-section-heading" colspan="2">';
|
694 |
-
$field_html .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
|
695 |
-
|
696 |
-
if ( isset( $field_data['help'] ) ) {
|
697 |
-
$field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help" title="' . esc_attr( $field_data['help'] ) . '"></i>';
|
698 |
-
}
|
699 |
-
$field_html .= '</div>';
|
700 |
-
$field_html .= '</div>';
|
701 |
-
return $field_html;
|
702 |
-
}
|
703 |
-
|
704 |
-
function get_description_field( $field_data ) {
|
705 |
-
|
706 |
-
$field_html = '<div class="wcf-field-row wcf-field-desc ' . $field_data['name'] . '">';
|
707 |
-
$field_html .= '<div class="wcf-field-desc-content">';
|
708 |
-
$field_html .= $field_data['content'];
|
709 |
-
$field_html .= '</div>';
|
710 |
-
$field_html .= '</div>';
|
711 |
-
|
712 |
-
return $field_html;
|
713 |
-
}
|
714 |
-
|
715 |
-
function get_checkout_field_repeater( $field_data ) {
|
716 |
-
|
717 |
-
$value = array();
|
718 |
-
|
719 |
-
$value[0] = array(
|
720 |
-
'add_to' => '',
|
721 |
-
'type' => '',
|
722 |
-
'label' => '',
|
723 |
-
'name' => '',
|
724 |
-
);
|
725 |
-
|
726 |
-
$field_content = '';
|
727 |
-
|
728 |
-
$field_content .= '<div class="wcf-field-row">';
|
729 |
-
// $field_content .= '<div class="wcf-field-row-heading">';
|
730 |
-
// $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
|
731 |
-
// $field_content .= '</div>';
|
732 |
-
$field_content .= '<div class="wcf-field-row-content">';
|
733 |
-
$field_content .= '<div class="wcf-cpf-wrap">';
|
734 |
-
|
735 |
-
foreach ( $value as $p_key => $p_data ) {
|
736 |
-
$field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
|
737 |
-
$field_content .= '<div class="wcf-cpf-row-header">';
|
738 |
-
$field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
|
739 |
-
$field_content .= '</div>';
|
740 |
-
|
741 |
-
$field_content .= '<div class="wcf-cpf-row-standard-fields">';
|
742 |
-
|
743 |
-
/* Add To */
|
744 |
-
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
|
745 |
-
$field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
|
746 |
-
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
747 |
-
$field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
|
748 |
-
$field_content .= '<option value="billing">Billing</option>';
|
749 |
-
$field_content .= '<option value="shipping">Shipping</option>';
|
750 |
-
$field_content .= '</select>';
|
751 |
-
$field_content .= '</span>';
|
752 |
-
$field_content .= '</div>';
|
753 |
-
|
754 |
-
/* Type */
|
755 |
-
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
|
756 |
-
$field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
|
757 |
-
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
758 |
-
$field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
|
759 |
-
$field_content .= '<option value="text">Text</option>';
|
760 |
-
$field_content .= '<option value="textarea">Textarea</option>';
|
761 |
-
$field_content .= '<option value="select">Select</option>';
|
762 |
-
$field_content .= '<option value="checkbox">Checkbox</option>';
|
763 |
-
$field_content .= '</select>';
|
764 |
-
$field_content .= '</span>';
|
765 |
-
$field_content .= '</div>';
|
766 |
-
|
767 |
-
/* Textarea */
|
768 |
-
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
|
769 |
-
$field_content .= '<span class="wcf-cpf-row-setting-label">Options *</span>';
|
770 |
-
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
771 |
-
$field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
|
772 |
-
$field_content .= '</span>';
|
773 |
-
$field_content .= '</div>';
|
774 |
-
|
775 |
-
/* Label */
|
776 |
-
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
|
777 |
-
$field_content .= '<span class="wcf-cpf-row-setting-label">Label *</span>';
|
778 |
-
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
779 |
-
$field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
|
780 |
-
$field_content .= '</span>';
|
781 |
-
$field_content .= '</div>';
|
782 |
-
|
783 |
-
/* Name */
|
784 |
-
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-name">';
|
785 |
-
$field_content .= '<span class="wcf-cpf-row-setting-label">Name *</span>';
|
786 |
-
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
787 |
-
$field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][name]" class="wcf-cpf-name">';
|
788 |
-
$field_content .= '</span>';
|
789 |
-
$field_content .= '</div>';
|
790 |
-
|
791 |
-
$field_content .= '</div>';
|
792 |
-
$field_content .= '</div>';
|
793 |
-
}
|
794 |
-
|
795 |
-
/* Add New Custom Field */
|
796 |
-
$field_content .= '<div class="wcf-cpf-add-row">';
|
797 |
-
$field_content .= '<div class="wcf-cpf-add-wrap">';
|
798 |
-
$field_content .= '<button class="button button-secondary wcf-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
|
799 |
-
$field_content .= '</div>';
|
800 |
-
$field_content .= '</div>';
|
801 |
-
/* End Add new custom field */
|
802 |
-
|
803 |
-
$field_content .= '</div>';
|
804 |
-
$field_content .= '</div>';
|
805 |
-
$field_content .= '</div>';
|
806 |
-
|
807 |
-
return $field_content;
|
808 |
-
}
|
809 |
-
|
810 |
-
function get_product_selection_repeater( $field_data ) {
|
811 |
-
|
812 |
-
$value = $field_data['value'];
|
813 |
-
|
814 |
-
if ( ! is_array( $value ) ) {
|
815 |
-
|
816 |
-
$value[0] = array(
|
817 |
-
'product' => '',
|
818 |
-
);
|
819 |
-
} else {
|
820 |
-
|
821 |
-
if ( ! isset( $value[0] ) ) {
|
822 |
-
|
823 |
-
$value[0] = array(
|
824 |
-
'product' => '',
|
825 |
-
);
|
826 |
-
}
|
827 |
-
}
|
828 |
-
|
829 |
-
$field_html = '';
|
830 |
-
|
831 |
-
$field_html .= '<script type="text/html" id="tmpl-wcf-product-repeater">';
|
832 |
-
$field_html .= $this->generate_product_repeater_html( '{{id}}' );
|
833 |
-
$field_html .= '</script>';
|
834 |
-
|
835 |
-
$field_html .= '<div class="wcf-field-row">';
|
836 |
-
$field_html .= '<div class="wcf-field-row-content">';
|
837 |
-
$field_html .= '<div class="wcf-repeatables-wrap">';
|
838 |
-
|
839 |
-
if ( is_array( $value ) ) {
|
840 |
-
|
841 |
-
foreach ( $value as $p_key => $p_data ) {
|
842 |
-
|
843 |
-
$selected_options = '';
|
844 |
-
|
845 |
-
if ( isset( $p_data['product'] ) ) {
|
846 |
-
|
847 |
-
$product = wc_get_product( $p_data['product'] );
|
848 |
-
|
849 |
-
// posts.
|
850 |
-
if ( ! empty( $product ) ) {
|
851 |
-
$post_title = $product->get_name() . ' (#' . $p_data['product'] . ')';
|
852 |
-
|
853 |
-
$selected_options = '<option value="' . $p_data['product'] . '" selected="selected" >' . $post_title . '</option>';
|
854 |
-
}
|
855 |
-
}
|
856 |
-
|
857 |
-
$field_html .= $this->generate_product_repeater_html( $p_key, $selected_options );
|
858 |
-
}
|
859 |
-
}
|
860 |
-
|
861 |
-
$field_html .= '<div class="wcf-add-repeatable-row">';
|
862 |
-
$field_html .= '<div class="submit wcf-add-repeatable-wrap">';
|
863 |
-
$field_html .= '<button class="button-primary wcf-add-repeatable" data-name="wcf-checkout-products">Add New Product</button>';
|
864 |
-
$field_html .= '</div>';
|
865 |
-
$field_html .= '</div>';
|
866 |
-
$field_html .= '</div>';
|
867 |
-
$field_html .= '</div>';
|
868 |
-
$field_html .= '</div>';
|
869 |
-
|
870 |
-
$field_html .= '<div class="wcf-field-row wcf-repeat-notice">';
|
871 |
-
$field_html .= '<p><i>The selected products will be automatically added in the cart for this checkout.</i></p>';
|
872 |
-
$field_html .= '</div>';
|
873 |
-
|
874 |
-
return $field_html;
|
875 |
-
}
|
876 |
-
|
877 |
-
function generate_product_repeater_html( $id, $options = '' ) {
|
878 |
-
|
879 |
-
$field_html = '<div class="wcf-repeatable-row" data-key="' . $id . '">';
|
880 |
-
|
881 |
-
$field_html .= '<div class="wcf-repeatable-row-standard-fields">';
|
882 |
-
|
883 |
-
/* Product Name */
|
884 |
-
$field_html .= '<div class="wcf-repeatable-fields wcf-sel-product">';
|
885 |
-
$field_html .= '<span class="wcf-repeatable-row-setting-field">';
|
886 |
-
$field_html .= '<select
|
887 |
-
name="wcf-checkout-products[' . $id . '][product]"
|
888 |
-
class="wcf-product-search"
|
889 |
-
data-allow_clear="allow_clear"
|
890 |
-
data-placeholder="' . __( 'Search for a product…', 'cartflows' ) . '"
|
891 |
-
data-action="woocommerce_json_search_products_and_variations">';
|
892 |
-
$field_html .= $options;
|
893 |
-
$field_html .= '</select>';
|
894 |
-
$field_html .= '</span>';
|
895 |
-
$field_html .= '<span class="wcf-repeatable-row-actions">';
|
896 |
-
$field_html .= '<a class="wcf-remove-row wcf-repeatable-remove button" data-type="product">';
|
897 |
-
$field_html .= '<span class="dashicons dashicons-trash"></span>';
|
898 |
-
$field_html .= '<span class="wcf-repeatable-remove-button">'. __( 'Remove', 'cartflows' ).'</span>';
|
899 |
-
$field_html .= '</a>';
|
900 |
-
$field_html .= '</span>';
|
901 |
-
$field_html .= '</div>';
|
902 |
-
$field_html .= '</div>';
|
903 |
-
$field_html .= '</div>';
|
904 |
-
|
905 |
-
return $field_html;
|
906 |
-
}
|
907 |
-
|
908 |
-
function get_image_field( $field_data ) {
|
909 |
-
|
910 |
-
$value = $field_data['value'];
|
911 |
-
|
912 |
-
$attr = '';
|
913 |
-
|
914 |
-
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
915 |
-
|
916 |
-
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
917 |
-
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
918 |
-
}
|
919 |
-
}
|
920 |
-
|
921 |
-
$display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
|
922 |
-
|
923 |
-
$field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
|
924 |
-
if( isset( $value ) ){
|
925 |
-
$field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
|
926 |
-
}
|
927 |
-
$field_content .= '</div>';
|
928 |
-
// $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
|
929 |
-
$field_content .= '<input type="hidden" id="wcf-image-value" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
|
930 |
-
|
931 |
-
$field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
|
932 |
-
|
933 |
-
$display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
|
934 |
-
|
935 |
-
$field_content .= '<button type="button" class="wcf-remove-image button-secondary" style="'.$display_remove_button.'">Remove Image</button>';
|
936 |
-
|
937 |
-
return $this->get_field( $field_data, $field_content );
|
938 |
-
}
|
939 |
-
|
940 |
-
/**
|
941 |
-
* Localize variables in admin
|
942 |
-
*
|
943 |
-
* @param array $vars variables.
|
944 |
-
*/
|
945 |
-
function localize_vars( $vars ) {
|
946 |
-
|
947 |
-
$ajax_actions = array(
|
948 |
-
'wcf_add_checkout_custom_field',
|
949 |
-
'wcf_delete_checkout_custom_field',
|
950 |
-
'wcf_json_search_pages',
|
951 |
-
'wcf_json_search_coupons'
|
952 |
-
);
|
953 |
-
|
954 |
-
foreach ( $ajax_actions as $action ) {
|
955 |
-
|
956 |
-
$vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
|
957 |
-
}
|
958 |
-
|
959 |
-
return $vars;
|
960 |
-
}
|
961 |
-
}
|
962 |
-
// @codingStandardsIgnoreEnd
|
1 |
+
<?php
|
2 |
+
// @codingStandardsIgnoreStart
|
3 |
+
/**
|
4 |
+
* Meta Fields.
|
5 |
+
*
|
6 |
+
* @package CartFlows
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class Cartflows_Meta_Fields.
|
11 |
+
*/
|
12 |
+
class Cartflows_Meta_Fields {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Instance
|
16 |
+
*
|
17 |
+
* @var $instance
|
18 |
+
*/
|
19 |
+
private static $instance;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Initiator
|
23 |
+
*/
|
24 |
+
public static function get_instance() {
|
25 |
+
if ( ! isset( self::$instance ) ) {
|
26 |
+
self::$instance = new self;
|
27 |
+
}
|
28 |
+
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Constructor
|
34 |
+
*/
|
35 |
+
public function __construct() {
|
36 |
+
|
37 |
+
/* Add Scripts */
|
38 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_meta_scripts' ), 20 );
|
39 |
+
|
40 |
+
add_action( 'wp_ajax_wcf_json_search_coupons', array( $this, 'json_search_coupons' ) );
|
41 |
+
|
42 |
+
add_action( 'wp_ajax_wcf_add_checkout_custom_field', array( $this, 'add_checkout_custom_field' ) );
|
43 |
+
add_action( 'wp_ajax_wcf_delete_checkout_custom_field', array( $this, 'delete_checkout_custom_field' ) );
|
44 |
+
|
45 |
+
add_action( 'wp_ajax_wcf_json_search_pages', array( $this, 'json_search_pages' ) );
|
46 |
+
|
47 |
+
add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
|
48 |
+
}
|
49 |
+
|
50 |
+
public function admin_meta_scripts() {
|
51 |
+
|
52 |
+
global $pagenow;
|
53 |
+
global $post;
|
54 |
+
|
55 |
+
$screen = get_current_screen();
|
56 |
+
|
57 |
+
if (
|
58 |
+
( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) &&
|
59 |
+
wcf()->utils->is_step_post_type( $screen->post_type )
|
60 |
+
) {
|
61 |
+
|
62 |
+
wp_enqueue_style( 'woocommerce_admin_styles' );
|
63 |
+
|
64 |
+
wp_enqueue_script( 'select2' );
|
65 |
+
wp_enqueue_script( 'wc-enhanced-select' );
|
66 |
+
|
67 |
+
wp_enqueue_script(
|
68 |
+
'wcf-admin-meta',
|
69 |
+
CARTFLOWS_URL . 'admin/meta-assets/js/admin-edit.js',
|
70 |
+
array( 'jquery', 'select2', 'wp-color-picker' ),
|
71 |
+
CARTFLOWS_VER,
|
72 |
+
true
|
73 |
+
);
|
74 |
+
|
75 |
+
wp_enqueue_style( 'wcf-admin-meta', CARTFLOWS_URL . 'admin/meta-assets/css/admin-edit.css', array( 'wp-color-picker' ), CARTFLOWS_VER );
|
76 |
+
wp_style_add_data( 'wcf-admin-meta', 'rtl', 'replace' );
|
77 |
+
|
78 |
+
$localize = array(
|
79 |
+
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
80 |
+
'google_fonts' => CartFlows_Font_Families::get_google_fonts(),
|
81 |
+
'system_fonts' => CartFlows_Font_Families::get_system_fonts(),
|
82 |
+
'font_weights' => array(
|
83 |
+
'100' => __( 'Thin 100', 'cartflows' ),
|
84 |
+
'200' => __( 'Extra-Light 200', 'cartflows' ),
|
85 |
+
'300' => __( 'Light 300', 'cartflows' ),
|
86 |
+
'400' => __( 'Normal 400', 'cartflows' ),
|
87 |
+
'500' => __( 'Medium 500', 'cartflows' ),
|
88 |
+
'600' => __( 'Semi-Bold 600', 'cartflows' ),
|
89 |
+
'700' => __( 'Bold 700', 'cartflows' ),
|
90 |
+
'800' => __( 'Extra-Bold 800', 'cartflows' ),
|
91 |
+
'900' => __( 'Ultra-Bold 900', 'cartflows' ),
|
92 |
+
)
|
93 |
+
);
|
94 |
+
|
95 |
+
wp_localize_script( 'jquery', 'wcf', apply_filters( 'wcf_js_localize', $localize ) );
|
96 |
+
|
97 |
+
do_action( 'cartflows_admin_meta_scripts' );
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Function to search coupons
|
103 |
+
*/
|
104 |
+
public function json_search_coupons() {
|
105 |
+
|
106 |
+
check_admin_referer( 'wcf-json-search-coupons', 'security' );
|
107 |
+
|
108 |
+
global $wpdb;
|
109 |
+
|
110 |
+
$term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
|
111 |
+
|
112 |
+
if ( empty( $term ) ) {
|
113 |
+
die();
|
114 |
+
}
|
115 |
+
|
116 |
+
$posts = wp_cache_get( 'wcf_search_coupons', 'wcf_funnel_Cart' );
|
117 |
+
|
118 |
+
if ( false === $posts ) {
|
119 |
+
$posts = $wpdb->get_results( // phpcs:ignore
|
120 |
+
$wpdb->prepare(
|
121 |
+
"SELECT *
|
122 |
+
FROM {$wpdb->prefix}posts
|
123 |
+
WHERE post_type = %s
|
124 |
+
AND post_title LIKE %s
|
125 |
+
AND post_status = %s",
|
126 |
+
'shop_coupon',
|
127 |
+
$wpdb->esc_like( $term ) . '%',
|
128 |
+
'publish'
|
129 |
+
)
|
130 |
+
);
|
131 |
+
wp_cache_set( 'wcf_search_coupons', $posts, 'wcf_funnel_Cart' );
|
132 |
+
}
|
133 |
+
|
134 |
+
$coupons_found = array();
|
135 |
+
$all_discount_types = wc_get_coupon_types();
|
136 |
+
|
137 |
+
if ( $posts ) {
|
138 |
+
foreach ( $posts as $post ) {
|
139 |
+
|
140 |
+
$discount_type = get_post_meta( $post->ID, 'discount_type', true );
|
141 |
+
|
142 |
+
if ( ! empty( $all_discount_types[ $discount_type ] ) ) {
|
143 |
+
$coupons_found[ get_the_title( $post->ID ) ] = get_the_title( $post->ID ) . ' (Type: ' . $all_discount_types[ $discount_type ] . ')';
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
wp_send_json( $coupons_found );
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* [add_checkout_custom_field description]
|
153 |
+
*
|
154 |
+
* @hook wcf_add_checkout_custom_field
|
155 |
+
*/
|
156 |
+
public function add_checkout_custom_field() {
|
157 |
+
|
158 |
+
check_ajax_referer( 'wcf-add-checkout-custom-field', 'security' );
|
159 |
+
|
160 |
+
$post_id = intval( $_POST['post_id'] );
|
161 |
+
$add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
|
162 |
+
$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
|
163 |
+
$options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
|
164 |
+
$label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
|
165 |
+
$name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
|
166 |
+
|
167 |
+
if ( '' !== $name ) {
|
168 |
+
|
169 |
+
$fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
|
170 |
+
$field_keys = array_keys($fields);
|
171 |
+
|
172 |
+
$name = $add_to . '_' . sanitize_key( $name );
|
173 |
+
if( in_array($name, $field_keys) ) {
|
174 |
+
$name = $name . '_' . rand( 0000, 9999 );
|
175 |
+
}
|
176 |
+
|
177 |
+
$field_data = array(
|
178 |
+
'type' => $type,
|
179 |
+
'label' => $label,
|
180 |
+
'placeholder' => '',
|
181 |
+
'class' => array( 'form-row-wide' ),
|
182 |
+
'label_class' => array(),
|
183 |
+
'required' => true,
|
184 |
+
'custom' => true,
|
185 |
+
);
|
186 |
+
|
187 |
+
if ( 'select' === $type ) {
|
188 |
+
|
189 |
+
$options = explode( ',', $options );
|
190 |
+
$field_data['options'] = array();
|
191 |
+
|
192 |
+
if ( is_array( $options ) && ! empty( $options ) ) {
|
193 |
+
|
194 |
+
foreach ( $options as $key => $value ) {
|
195 |
+
|
196 |
+
$field_data['options'][ $value ] = $value;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
|
202 |
+
|
203 |
+
$key = sanitize_key( $name );
|
204 |
+
$name = 'wcf-' . $key;
|
205 |
+
|
206 |
+
$field_args = array(
|
207 |
+
'label' => $label,
|
208 |
+
'name' => $name,
|
209 |
+
'value' => 'yes',
|
210 |
+
'after' => 'Enable',
|
211 |
+
);
|
212 |
+
|
213 |
+
$field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> | ';
|
214 |
+
$field_args['after_html'] .= '<a class="wcf-cpf-action-remove">' . __( 'Remove', 'cartflows' ) . '</a>';
|
215 |
+
$field_args['after_html'] .= '</span>';
|
216 |
+
|
217 |
+
$field_markup = wcf()->meta->get_checkbox_field( $field_args );
|
218 |
+
|
219 |
+
if( 'billing' === $add_to ) {
|
220 |
+
$add_to_class = 'wcf-cb-fields';
|
221 |
+
} else if( 'shipping' === $add_to ) {
|
222 |
+
$add_to_class = 'wcf-sb-fields';
|
223 |
+
}
|
224 |
+
|
225 |
+
$data = array(
|
226 |
+
'field_data' => $field_data,
|
227 |
+
'field_args' => $field_args,
|
228 |
+
'add_to_class' => $add_to_class,
|
229 |
+
'markup' => $field_markup,
|
230 |
+
);
|
231 |
+
|
232 |
+
wp_send_json( $data );
|
233 |
+
}
|
234 |
+
|
235 |
+
wp_send_json( false );
|
236 |
+
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* [delete_checkout_custom_field description]
|
241 |
+
*
|
242 |
+
* @hook wcf_delete_checkout_custom_field
|
243 |
+
* @return [type] [description]
|
244 |
+
*/
|
245 |
+
public function delete_checkout_custom_field() {
|
246 |
+
|
247 |
+
check_ajax_referer( 'wcf-delete-checkout-custom-field', 'security' );
|
248 |
+
|
249 |
+
$post_id = intval( $_POST['post_id'] );
|
250 |
+
$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
|
251 |
+
$key = sanitize_text_field( wp_unslash( $_POST['key'] ) );
|
252 |
+
|
253 |
+
if ( '' !== $key ) {
|
254 |
+
|
255 |
+
Cartflows_Helper::delete_checkout_field( $type, $key, $post_id );
|
256 |
+
|
257 |
+
wp_send_json( true );
|
258 |
+
|
259 |
+
}
|
260 |
+
|
261 |
+
wp_send_json( false );
|
262 |
+
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Function to search coupons
|
267 |
+
*/
|
268 |
+
public function json_search_pages() {
|
269 |
+
|
270 |
+
check_ajax_referer( 'wcf-json-search-pages', 'security' );
|
271 |
+
|
272 |
+
$term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
|
273 |
+
|
274 |
+
if ( empty( $term ) ) {
|
275 |
+
die( 'not found' );
|
276 |
+
}
|
277 |
+
|
278 |
+
$search_string = $term;
|
279 |
+
$data = array();
|
280 |
+
$result = array();
|
281 |
+
|
282 |
+
add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
|
283 |
+
|
284 |
+
$query = new WP_Query(
|
285 |
+
array(
|
286 |
+
's' => $search_string,
|
287 |
+
'post_type' => 'page',
|
288 |
+
'posts_per_page' => - 1,
|
289 |
+
)
|
290 |
+
);
|
291 |
+
|
292 |
+
if ( $query->have_posts() ) {
|
293 |
+
while ( $query->have_posts() ) {
|
294 |
+
$query->the_post();
|
295 |
+
$title = get_the_title();
|
296 |
+
$title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
|
297 |
+
$id = get_the_id();
|
298 |
+
$data[] = array(
|
299 |
+
'id' => $id,
|
300 |
+
'text' => $title,
|
301 |
+
);
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
if ( is_array( $data ) && ! empty( $data ) ) {
|
306 |
+
$result[] = array(
|
307 |
+
'text' => '',
|
308 |
+
'children' => $data,
|
309 |
+
);
|
310 |
+
}
|
311 |
+
|
312 |
+
wp_reset_postdata();
|
313 |
+
|
314 |
+
// return the result in json.
|
315 |
+
wp_send_json( $result );
|
316 |
+
}
|
317 |
+
|
318 |
+
public function search_only_titles( $search, $wp_query ) {
|
319 |
+
if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
|
320 |
+
global $wpdb;
|
321 |
+
|
322 |
+
$q = $wp_query->query_vars;
|
323 |
+
$n = ! empty( $q['exact'] ) ? '' : '%';
|
324 |
+
|
325 |
+
$search = array();
|
326 |
+
|
327 |
+
foreach ( (array) $q['search_terms'] as $term ) {
|
328 |
+
$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
|
329 |
+
}
|
330 |
+
|
331 |
+
if ( ! is_user_logged_in() ) {
|
332 |
+
$search[] = "$wpdb->posts.post_password = ''";
|
333 |
+
}
|
334 |
+
|
335 |
+
$search = ' AND ' . implode( ' AND ', $search );
|
336 |
+
}
|
337 |
+
|
338 |
+
return $search;
|
339 |
+
}
|
340 |
+
|
341 |
+
function get_field( $field_data, $field_content ) {
|
342 |
+
|
343 |
+
$label = isset( $field_data['label'] ) ? $field_data['label'] : '';
|
344 |
+
$help = isset( $field_data['help'] ) ? $field_data['help'] : '';
|
345 |
+
$after_html = isset( $field_data['after_html'] ) ? $field_data['after_html'] : '';
|
346 |
+
|
347 |
+
$name_class = 'field-' . $field_data['name'];
|
348 |
+
|
349 |
+
$field_html = '<div class="wcf-field-row ' . $name_class . '">';
|
350 |
+
|
351 |
+
if( ! empty( $label ) || ! empty( $help ) ) {
|
352 |
+
$field_html .= '<div class="wcf-field-row-heading">';
|
353 |
+
if( ! empty( $label ) ) {
|
354 |
+
$field_html .= '<label>' . esc_html( $label ) . '</label>';
|
355 |
+
}
|
356 |
+
if ( ! empty( $help ) ) {
|
357 |
+
$field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help">';
|
358 |
+
// $field_html .= '<span class="wcf-tooltip" data-tooltip= "'. esc_attr( $help ) .'"></span>';
|
359 |
+
$field_html .= '</i>';
|
360 |
+
$field_html .= '<span class="wcf-tooltip-text">';
|
361 |
+
$field_html .= $help;
|
362 |
+
$field_html .= '</span>';
|
363 |
+
}
|
364 |
+
$field_html .= '</div>';
|
365 |
+
}
|
366 |
+
|
367 |
+
$field_html .= '<div class="wcf-field-row-content">';
|
368 |
+
$field_html .= $field_content;
|
369 |
+
|
370 |
+
if ( ! empty( $after_html ) ) {
|
371 |
+
$field_html .= $after_html;
|
372 |
+
}
|
373 |
+
|
374 |
+
$field_html .= '</div>';
|
375 |
+
$field_html .= '</div>';
|
376 |
+
|
377 |
+
return $field_html;
|
378 |
+
}
|
379 |
+
|
380 |
+
function get_text_field( $field_data ) {
|
381 |
+
|
382 |
+
$value = $field_data['value'];
|
383 |
+
|
384 |
+
$attr = '';
|
385 |
+
|
386 |
+
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
387 |
+
|
388 |
+
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
389 |
+
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
$field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
394 |
+
|
395 |
+
return $this->get_field( $field_data, $field_content );
|
396 |
+
}
|
397 |
+
|
398 |
+
function get_shortcode_field( $field_data ) {
|
399 |
+
|
400 |
+
$attr = '';
|
401 |
+
|
402 |
+
$attr_fields = array(
|
403 |
+
'readonly' => 'readonly',
|
404 |
+
'onfocus' => 'this.select()',
|
405 |
+
'onmouseup' => 'return false',
|
406 |
+
);
|
407 |
+
|
408 |
+
if ( $attr_fields && is_array( $attr_fields ) ) {
|
409 |
+
|
410 |
+
foreach ( $attr_fields as $attr_key => $attr_value ) {
|
411 |
+
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
412 |
+
}
|
413 |
+
}
|
414 |
+
|
415 |
+
$field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $field_data['content'] . '" ' . $attr . '>';
|
416 |
+
|
417 |
+
return $this->get_field( $field_data, $field_content );
|
418 |
+
}
|
419 |
+
|
420 |
+
function get_display_field( $field_data ) {
|
421 |
+
|
422 |
+
$field_content = $field_data['content'];
|
423 |
+
|
424 |
+
return $this->get_field( $field_data, $field_content );
|
425 |
+
}
|
426 |
+
|
427 |
+
function get_number_field( $field_data ) {
|
428 |
+
|
429 |
+
$value = $field_data['value'];
|
430 |
+
|
431 |
+
$attr = '';
|
432 |
+
|
433 |
+
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
434 |
+
|
435 |
+
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
436 |
+
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
$field_content = '<input type="number" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
441 |
+
|
442 |
+
return $this->get_field( $field_data, $field_content );
|
443 |
+
}
|
444 |
+
|
445 |
+
function get_hidden_field( $field_data ) {
|
446 |
+
|
447 |
+
$value = $field_data['value'];
|
448 |
+
|
449 |
+
$attr = '';
|
450 |
+
|
451 |
+
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
452 |
+
|
453 |
+
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
454 |
+
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
455 |
+
}
|
456 |
+
}
|
457 |
+
|
458 |
+
$field_content = '<input type="hidden" id="' . $field_data['name'] . '" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
|
459 |
+
|
460 |
+
return $this->get_field( $field_data, $field_content );
|
461 |
+
}
|
462 |
+
|
463 |
+
function get_area_field( $field_data ) {
|
464 |
+
|
465 |
+
$value = $field_data['value'];
|
466 |
+
|
467 |
+
$field_content = '<textarea name="' . $field_data['name'] . '" rows="10" cols="50">';
|
468 |
+
$field_content .= $value;
|
469 |
+
$field_content .= '</textarea>';
|
470 |
+
|
471 |
+
return $this->get_field( $field_data, $field_content );
|
472 |
+
}
|
473 |
+
|
474 |
+
function get_checkbox_field( $field_data ) {
|
475 |
+
|
476 |
+
$value = $field_data['value'];
|
477 |
+
|
478 |
+
$field_content = '';
|
479 |
+
if ( isset( $field_data['before'] ) ) {
|
480 |
+
$field_content .= '<span>' . $field_data['before'] . '</span>';
|
481 |
+
}
|
482 |
+
$field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
|
483 |
+
$field_content .= '<input type="checkbox" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
|
484 |
+
|
485 |
+
if ( isset( $field_data['after'] ) ) {
|
486 |
+
$field_content .= '<span>' . $field_data['after'] . '</span>';
|
487 |
+
}
|
488 |
+
|
489 |
+
return $this->get_field( $field_data, $field_content );
|
490 |
+
}
|
491 |
+
|
492 |
+
function get_font_family_field( $field_data ) {
|
493 |
+
|
494 |
+
$value = $field_data['value'];
|
495 |
+
|
496 |
+
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
497 |
+
|
498 |
+
$field_content = '<select class="wcf-field-font-family" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
|
499 |
+
|
500 |
+
$field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
|
501 |
+
|
502 |
+
$field_content .= '<optgroup label="Other System Fonts">';
|
503 |
+
foreach ( CartFlows_Font_Families::get_system_fonts() as $name => $variants ) {
|
504 |
+
$field_content .= '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $value, false ) . '>' . esc_attr( $name ) . '</option>';
|
505 |
+
}
|
506 |
+
$field_content .= '</optgroup>';
|
507 |
+
$field_content .= '<optgroup label="Google">';
|
508 |
+
foreach ( CartFlows_Font_Families::get_google_fonts() as $name => $single_font ) {
|
509 |
+
$variants = wcf_get_prop( $single_font, '0' );
|
510 |
+
$category = wcf_get_prop( $single_font, '1' );
|
511 |
+
$font_value = '\'' . esc_attr( $name ) . '\', ' . esc_attr( $category );
|
512 |
+
$field_content .= '<option value="' . esc_attr( $font_value ) . '" ' . selected( $font_value, $value, false ) . '>' . esc_attr( $name ) . '</option>';
|
513 |
+
}
|
514 |
+
$field_content .= '</optgroup>';
|
515 |
+
|
516 |
+
$field_content .= '</select>';
|
517 |
+
|
518 |
+
return $this->get_field( $field_data, $field_content );
|
519 |
+
}
|
520 |
+
|
521 |
+
function get_font_weight_field( $field_data ) {
|
522 |
+
|
523 |
+
$value = $field_data['value'];
|
524 |
+
|
525 |
+
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
526 |
+
|
527 |
+
$field_content = '<select data-selected="'.esc_attr( $value ).'" class="wcf-field-font-weight" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
|
528 |
+
|
529 |
+
$field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
|
530 |
+
|
531 |
+
$field_content .= '</select>';
|
532 |
+
|
533 |
+
return $this->get_field( $field_data, $field_content );
|
534 |
+
}
|
535 |
+
|
536 |
+
function get_select_field( $field_data ) {
|
537 |
+
|
538 |
+
$value = $field_data['value'];
|
539 |
+
$pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
|
540 |
+
|
541 |
+
$field_content = '<select name="' . $field_data['name'] . '">';
|
542 |
+
|
543 |
+
|
544 |
+
if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
|
545 |
+
|
546 |
+
foreach ( $field_data['options'] as $data_key => $data_value ) {
|
547 |
+
|
548 |
+
$disabled = '';
|
549 |
+
|
550 |
+
if ( array_key_exists( $data_key, $pro_options ) ) {
|
551 |
+
$disabled = 'disabled ';
|
552 |
+
$data_value = $pro_options[ $data_key ];
|
553 |
+
}
|
554 |
+
|
555 |
+
$field_content .= '<option value="' . $data_key . '" ' . selected( $value, $data_key, false ) . ' ' . $disabled .'>' . $data_value . '</option>';
|
556 |
+
}
|
557 |
+
}
|
558 |
+
|
559 |
+
$field_content .= '</select>';
|
560 |
+
|
561 |
+
if ( isset( $field_data['after'] ) ) {
|
562 |
+
$field_content .= '<span>' . $field_data['after'] . '</span>';
|
563 |
+
}
|
564 |
+
|
565 |
+
return $this->get_field( $field_data, $field_content );
|
566 |
+
}
|
567 |
+
|
568 |
+
function get_color_picker_field( $field_data ) {
|
569 |
+
|
570 |
+
$value = $field_data['value'];
|
571 |
+
|
572 |
+
$field_content = '<input class="wcf-color-picker" type="text" name="' . $field_data['name'] . '" value="' . $value . '">';
|
573 |
+
|
574 |
+
return $this->get_field( $field_data, $field_content );
|
575 |
+
}
|
576 |
+
|
577 |
+
function get_product_selection_field( $field_data ) {
|
578 |
+
|
579 |
+
$value = $field_data['value'];
|
580 |
+
|
581 |
+
$multiple = '';
|
582 |
+
|
583 |
+
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
584 |
+
$multiple = ' multiple="multiple"';
|
585 |
+
}
|
586 |
+
|
587 |
+
$allow_clear = '';
|
588 |
+
|
589 |
+
if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
|
590 |
+
$allow_clear = ' data-allow_clear="allow_clear"';
|
591 |
+
}
|
592 |
+
|
593 |
+
$field_content = '<select
|
594 |
+
name="' . $field_data['name'] . '[]"
|
595 |
+
class="wcf-product-search" ' . $multiple . $allow_clear . '
|
596 |
+
data-placeholder="' . __( 'Search for a product…', 'cartflows' ) . '"
|
597 |
+
data-action="woocommerce_json_search_products_and_variations">';
|
598 |
+
|
599 |
+
if ( is_array( $value ) && ! empty( $value ) ) {
|
600 |
+
|
601 |
+
foreach ( $value as $data_key => $product_id ) {
|
602 |
+
|
603 |
+
$product = wc_get_product( $product_id );
|
604 |
+
|
605 |
+
// posts.
|
606 |
+
if ( ! empty( $product ) ) {
|
607 |
+
$post_title = $product->get_name() . ' (#' . $product_id . ')';
|
608 |
+
|
609 |
+
$field_content .= '<option value="' . $product_id . '" selected="selected" >' . $post_title . '</option>';
|
610 |
+
}
|
611 |
+
}
|
612 |
+
}
|
613 |
+
$field_content .= '</select>';
|
614 |
+
|
615 |
+
return $this->get_field( $field_data, $field_content );
|
616 |
+
}
|
617 |
+
|
618 |
+
function get_coupon_selection_field( $field_data ) {
|
619 |
+
|
620 |
+
$value = $field_data['value'];
|
621 |
+
|
622 |
+
$multiple = '';
|
623 |
+
|
624 |
+
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
625 |
+
$multiple = ' multiple="multiple"';
|
626 |
+
}
|
627 |
+
|
628 |
+
$allow_clear = '';
|
629 |
+
|
630 |
+
if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
|
631 |
+
$allow_clear = ' data-allow_clear="allow_clear"';
|
632 |
+
}
|
633 |
+
|
634 |
+
$field_content = '<select
|
635 |
+
name="' . $field_data['name'] . '[]"
|
636 |
+
class="wc-coupon-search wcf-coupon-search" ' . $multiple . $allow_clear . '
|
637 |
+
data-placeholder="' . __( 'Search for a coupon…', 'cartflows' ) . '"
|
638 |
+
data-action="wcf_json_search_coupons">';
|
639 |
+
|
640 |
+
if ( is_array( $value ) && ! empty( $value ) ) {
|
641 |
+
|
642 |
+
$all_discount_types = wc_get_coupon_types();
|
643 |
+
|
644 |
+
foreach ( $value as $coupon_title ) {
|
645 |
+
|
646 |
+
$coupon = new WC_Coupon( $coupon_title );
|
647 |
+
|
648 |
+
$discount_type = $coupon->get_discount_type();
|
649 |
+
|
650 |
+
if ( isset( $discount_type ) && $discount_type ) {
|
651 |
+
$discount_type = ' ( Type: ' . $all_discount_types[ $discount_type ] . ' )';
|
652 |
+
}
|
653 |
+
|
654 |
+
$field_content .= '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>';
|
655 |
+
}
|
656 |
+
}
|
657 |
+
|
658 |
+
$field_content .= '</select>';
|
659 |
+
|
660 |
+
return $this->get_field( $field_data, $field_content );
|
661 |
+
}
|
662 |
+
|
663 |
+
function get_page_selection_field( $field_data ) {
|
664 |
+
|
665 |
+
$value = $field_data['value'];
|
666 |
+
|
667 |
+
$multiple = '';
|
668 |
+
|
669 |
+
if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
|
670 |
+
$multiple = 'multiple="multiple"';
|
671 |
+
}
|
672 |
+
|
673 |
+
$field_content = '<select
|
674 |
+
name="' . $field_data['name'] . '[]"
|
675 |
+
class="wcf-search-pages" ' . $multiple . '"
|
676 |
+
data-action="wcf_json_search_pages">';
|
677 |
+
|
678 |
+
if ( is_array( $value ) && ! empty( $value ) ) {
|
679 |
+
|
680 |
+
foreach ( $value as $data_key => $data_value ) {
|
681 |
+
|
682 |
+
$field_content .= '<option value="' . $data_value . '">' . get_the_title( $data_value ) . '</option>';
|
683 |
+
}
|
684 |
+
}
|
685 |
+
|
686 |
+
$field_content .= '</select>';
|
687 |
+
|
688 |
+
return $this->get_field( $field_data, $field_content );
|
689 |
+
}
|
690 |
+
|
691 |
+
function get_section( $field_data ) {
|
692 |
+
$field_html = '<div class="wcf-field-row wcf-field-section">';
|
693 |
+
$field_html .= '<div class="wcf-field-section-heading" colspan="2">';
|
694 |
+
$field_html .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
|
695 |
+
|
696 |
+
if ( isset( $field_data['help'] ) ) {
|
697 |
+
$field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help" title="' . esc_attr( $field_data['help'] ) . '"></i>';
|
698 |
+
}
|
699 |
+
$field_html .= '</div>';
|
700 |
+
$field_html .= '</div>';
|
701 |
+
return $field_html;
|
702 |
+
}
|
703 |
+
|
704 |
+
function get_description_field( $field_data ) {
|
705 |
+
|
706 |
+
$field_html = '<div class="wcf-field-row wcf-field-desc ' . $field_data['name'] . '">';
|
707 |
+
$field_html .= '<div class="wcf-field-desc-content">';
|
708 |
+
$field_html .= $field_data['content'];
|
709 |
+
$field_html .= '</div>';
|
710 |
+
$field_html .= '</div>';
|
711 |
+
|
712 |
+
return $field_html;
|
713 |
+
}
|
714 |
+
|
715 |
+
function get_checkout_field_repeater( $field_data ) {
|
716 |
+
|
717 |
+
$value = array();
|
718 |
+
|
719 |
+
$value[0] = array(
|
720 |
+
'add_to' => '',
|
721 |
+
'type' => '',
|
722 |
+
'label' => '',
|
723 |
+
'name' => '',
|
724 |
+
);
|
725 |
+
|
726 |
+
$field_content = '';
|
727 |
+
|
728 |
+
$field_content .= '<div class="wcf-field-row">';
|
729 |
+
// $field_content .= '<div class="wcf-field-row-heading">';
|
730 |
+
// $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
|
731 |
+
// $field_content .= '</div>';
|
732 |
+
$field_content .= '<div class="wcf-field-row-content">';
|
733 |
+
$field_content .= '<div class="wcf-cpf-wrap">';
|
734 |
+
|
735 |
+
foreach ( $value as $p_key => $p_data ) {
|
736 |
+
$field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
|
737 |
+
$field_content .= '<div class="wcf-cpf-row-header">';
|
738 |
+
$field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
|
739 |
+
$field_content .= '</div>';
|
740 |
+
|
741 |
+
$field_content .= '<div class="wcf-cpf-row-standard-fields">';
|
742 |
+
|
743 |
+
/* Add To */
|
744 |
+
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
|
745 |
+
$field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
|
746 |
+
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
747 |
+
$field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
|
748 |
+
$field_content .= '<option value="billing">Billing</option>';
|
749 |
+
$field_content .= '<option value="shipping">Shipping</option>';
|
750 |
+
$field_content .= '</select>';
|
751 |
+
$field_content .= '</span>';
|
752 |
+
$field_content .= '</div>';
|
753 |
+
|
754 |
+
/* Type */
|
755 |
+
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
|
756 |
+
$field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
|
757 |
+
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
758 |
+
$field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
|
759 |
+
$field_content .= '<option value="text">Text</option>';
|
760 |
+
$field_content .= '<option value="textarea">Textarea</option>';
|
761 |
+
$field_content .= '<option value="select">Select</option>';
|
762 |
+
$field_content .= '<option value="checkbox">Checkbox</option>';
|
763 |
+
$field_content .= '</select>';
|
764 |
+
$field_content .= '</span>';
|
765 |
+
$field_content .= '</div>';
|
766 |
+
|
767 |
+
/* Textarea */
|
768 |
+
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
|
769 |
+
$field_content .= '<span class="wcf-cpf-row-setting-label">Options *</span>';
|
770 |
+
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
771 |
+
$field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
|
772 |
+
$field_content .= '</span>';
|
773 |
+
$field_content .= '</div>';
|
774 |
+
|
775 |
+
/* Label */
|
776 |
+
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
|
777 |
+
$field_content .= '<span class="wcf-cpf-row-setting-label">Label *</span>';
|
778 |
+
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
779 |
+
$field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
|
780 |
+
$field_content .= '</span>';
|
781 |
+
$field_content .= '</div>';
|
782 |
+
|
783 |
+
/* Name */
|
784 |
+
$field_content .= '<div class="wcf-cpf-fields wcf-cpf-name">';
|
785 |
+
$field_content .= '<span class="wcf-cpf-row-setting-label">Name *</span>';
|
786 |
+
$field_content .= '<span class="wcf-cpf-row-setting-field">';
|
787 |
+
$field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][name]" class="wcf-cpf-name">';
|
788 |
+
$field_content .= '</span>';
|
789 |
+
$field_content .= '</div>';
|
790 |
+
|
791 |
+
$field_content .= '</div>';
|
792 |
+
$field_content .= '</div>';
|
793 |
+
}
|
794 |
+
|
795 |
+
/* Add New Custom Field */
|
796 |
+
$field_content .= '<div class="wcf-cpf-add-row">';
|
797 |
+
$field_content .= '<div class="wcf-cpf-add-wrap">';
|
798 |
+
$field_content .= '<button class="button button-secondary wcf-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
|
799 |
+
$field_content .= '</div>';
|
800 |
+
$field_content .= '</div>';
|
801 |
+
/* End Add new custom field */
|
802 |
+
|
803 |
+
$field_content .= '</div>';
|
804 |
+
$field_content .= '</div>';
|
805 |
+
$field_content .= '</div>';
|
806 |
+
|
807 |
+
return $field_content;
|
808 |
+
}
|
809 |
+
|
810 |
+
function get_product_selection_repeater( $field_data ) {
|
811 |
+
|
812 |
+
$value = $field_data['value'];
|
813 |
+
|
814 |
+
if ( ! is_array( $value ) ) {
|
815 |
+
|
816 |
+
$value[0] = array(
|
817 |
+
'product' => '',
|
818 |
+
);
|
819 |
+
} else {
|
820 |
+
|
821 |
+
if ( ! isset( $value[0] ) ) {
|
822 |
+
|
823 |
+
$value[0] = array(
|
824 |
+
'product' => '',
|
825 |
+
);
|
826 |
+
}
|
827 |
+
}
|
828 |
+
|
829 |
+
$field_html = '';
|
830 |
+
|
831 |
+
$field_html .= '<script type="text/html" id="tmpl-wcf-product-repeater">';
|
832 |
+
$field_html .= $this->generate_product_repeater_html( '{{id}}' );
|
833 |
+
$field_html .= '</script>';
|
834 |
+
|
835 |
+
$field_html .= '<div class="wcf-field-row">';
|
836 |
+
$field_html .= '<div class="wcf-field-row-content">';
|
837 |
+
$field_html .= '<div class="wcf-repeatables-wrap">';
|
838 |
+
|
839 |
+
if ( is_array( $value ) ) {
|
840 |
+
|
841 |
+
foreach ( $value as $p_key => $p_data ) {
|
842 |
+
|
843 |
+
$selected_options = '';
|
844 |
+
|
845 |
+
if ( isset( $p_data['product'] ) ) {
|
846 |
+
|
847 |
+
$product = wc_get_product( $p_data['product'] );
|
848 |
+
|
849 |
+
// posts.
|
850 |
+
if ( ! empty( $product ) ) {
|
851 |
+
$post_title = $product->get_name() . ' (#' . $p_data['product'] . ')';
|
852 |
+
|
853 |
+
$selected_options = '<option value="' . $p_data['product'] . '" selected="selected" >' . $post_title . '</option>';
|
854 |
+
}
|
855 |
+
}
|
856 |
+
|
857 |
+
$field_html .= $this->generate_product_repeater_html( $p_key, $selected_options );
|
858 |
+
}
|
859 |
+
}
|
860 |
+
|
861 |
+
$field_html .= '<div class="wcf-add-repeatable-row">';
|
862 |
+
$field_html .= '<div class="submit wcf-add-repeatable-wrap">';
|
863 |
+
$field_html .= '<button class="button-primary wcf-add-repeatable" data-name="wcf-checkout-products">Add New Product</button>';
|
864 |
+
$field_html .= '</div>';
|
865 |
+
$field_html .= '</div>';
|
866 |
+
$field_html .= '</div>';
|
867 |
+
$field_html .= '</div>';
|
868 |
+
$field_html .= '</div>';
|
869 |
+
|
870 |
+
$field_html .= '<div class="wcf-field-row wcf-repeat-notice">';
|
871 |
+
$field_html .= '<p><i>The selected products will be automatically added in the cart for this checkout.</i></p>';
|
872 |
+
$field_html .= '</div>';
|
873 |
+
|
874 |
+
return $field_html;
|
875 |
+
}
|
876 |
+
|
877 |
+
function generate_product_repeater_html( $id, $options = '' ) {
|
878 |
+
|
879 |
+
$field_html = '<div class="wcf-repeatable-row" data-key="' . $id . '">';
|
880 |
+
|
881 |
+
$field_html .= '<div class="wcf-repeatable-row-standard-fields">';
|
882 |
+
|
883 |
+
/* Product Name */
|
884 |
+
$field_html .= '<div class="wcf-repeatable-fields wcf-sel-product">';
|
885 |
+
$field_html .= '<span class="wcf-repeatable-row-setting-field">';
|
886 |
+
$field_html .= '<select
|
887 |
+
name="wcf-checkout-products[' . $id . '][product]"
|
888 |
+
class="wcf-product-search"
|
889 |
+
data-allow_clear="allow_clear"
|
890 |
+
data-placeholder="' . __( 'Search for a product…', 'cartflows' ) . '"
|
891 |
+
data-action="woocommerce_json_search_products_and_variations">';
|
892 |
+
$field_html .= $options;
|
893 |
+
$field_html .= '</select>';
|
894 |
+
$field_html .= '</span>';
|
895 |
+
$field_html .= '<span class="wcf-repeatable-row-actions">';
|
896 |
+
$field_html .= '<a class="wcf-remove-row wcf-repeatable-remove button" data-type="product">';
|
897 |
+
$field_html .= '<span class="dashicons dashicons-trash"></span>';
|
898 |
+
$field_html .= '<span class="wcf-repeatable-remove-button">'. __( 'Remove', 'cartflows' ).'</span>';
|
899 |
+
$field_html .= '</a>';
|
900 |
+
$field_html .= '</span>';
|
901 |
+
$field_html .= '</div>';
|
902 |
+
$field_html .= '</div>';
|
903 |
+
$field_html .= '</div>';
|
904 |
+
|
905 |
+
return $field_html;
|
906 |
+
}
|
907 |
+
|
908 |
+
function get_image_field( $field_data ) {
|
909 |
+
|
910 |
+
$value = $field_data['value'];
|
911 |
+
|
912 |
+
$attr = '';
|
913 |
+
|
914 |
+
if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
|
915 |
+
|
916 |
+
foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
|
917 |
+
$attr .= ' ' . $attr_key . '="' . $attr_value . '"';
|
918 |
+
}
|
919 |
+
}
|
920 |
+
|
921 |
+
$display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
|
922 |
+
|
923 |
+
$field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
|
924 |
+
if( isset( $value ) ){
|
925 |
+
$field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
|
926 |
+
}
|
927 |
+
$field_content .= '</div>';
|
928 |
+
// $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
|
929 |
+
$field_content .= '<input type="hidden" id="wcf-image-value" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
|
930 |
+
|
931 |
+
$field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
|
932 |
+
|
933 |
+
$display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
|
934 |
+
|
935 |
+
$field_content .= '<button type="button" class="wcf-remove-image button-secondary" style="'.$display_remove_button.'">Remove Image</button>';
|
936 |
+
|
937 |
+
return $this->get_field( $field_data, $field_content );
|
938 |
+
}
|
939 |
+
|
940 |
+
/**
|
941 |
+
* Localize variables in admin
|
942 |
+
*
|
943 |
+
* @param array $vars variables.
|
944 |
+
*/
|
945 |
+
function localize_vars( $vars ) {
|
946 |
+
|
947 |
+
$ajax_actions = array(
|
948 |
+
'wcf_add_checkout_custom_field',
|
949 |
+
'wcf_delete_checkout_custom_field',
|
950 |
+
'wcf_json_search_pages',
|
951 |
+
'wcf_json_search_coupons'
|
952 |
+
);
|
953 |
+
|
954 |
+
foreach ( $ajax_actions as $action ) {
|
955 |
+
|
956 |
+
$vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
|
957 |
+
}
|
958 |
+
|
959 |
+
return $vars;
|
960 |
+
}
|
961 |
+
}
|
962 |
+
// @codingStandardsIgnoreEnd
|
modules/checkout/classes/class-cartflows-checkout-markup.php
CHANGED
@@ -1,942 +1,942 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Checkout markup.
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Checkout Markup
|
10 |
-
*
|
11 |
-
* @since 1.0.0
|
12 |
-
*/
|
13 |
-
class Cartflows_Checkout_Markup {
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Member Variable
|
17 |
-
*
|
18 |
-
* @var object instance
|
19 |
-
*/
|
20 |
-
private static $instance;
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Initiator
|
24 |
-
*/
|
25 |
-
public static function get_instance() {
|
26 |
-
if ( ! isset( self::$instance ) ) {
|
27 |
-
self::$instance = new self;
|
28 |
-
}
|
29 |
-
return self::$instance;
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Constructor
|
34 |
-
*/
|
35 |
-
public function __construct() {
|
36 |
-
|
37 |
-
/* Set is checkout flag */
|
38 |
-
add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
|
39 |
-
|
40 |
-
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_checkout_fields' ), 10, 2 );
|
41 |
-
|
42 |
-
/* Checkout Shortcode */
|
43 |
-
add_shortcode( 'cartflows_checkout', array( $this, 'checkout_shortcode_markup' ) );
|
44 |
-
|
45 |
-
/* Preconfigured cart data */
|
46 |
-
add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
|
47 |
-
|
48 |
-
/* Embed Checkout */
|
49 |
-
add_action( 'wp', array( $this, 'shortcode_load_data' ), 999 );
|
50 |
-
|
51 |
-
/* Ajax Endpoint */
|
52 |
-
add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ) );
|
53 |
-
|
54 |
-
add_filter( 'cartflows_add_before_main_section', array( $this, 'enable_logo_in_header' ) );
|
55 |
-
|
56 |
-
add_filter( 'cartflows_primary_container_bottom', array( $this, 'show_cartflows_copyright_message' ) );
|
57 |
-
|
58 |
-
add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
|
59 |
-
|
60 |
-
add_action( 'wp_ajax_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
|
61 |
-
add_action( 'wp_ajax_nopriv_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
|
62 |
-
|
63 |
-
add_filter( 'global_cartflows_js_localize', array( $this, 'add_localize_vars' ) );
|
64 |
-
|
65 |
-
/* Global Checkout */
|
66 |
-
add_action( 'template_redirect', array( $this, 'global_checkout_template_redirect' ), 1 );
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Redirect from default to the global checkout page
|
71 |
-
*
|
72 |
-
* @since 1.0.0
|
73 |
-
*/
|
74 |
-
function global_checkout_template_redirect() {
|
75 |
-
|
76 |
-
if ( ! is_checkout() ) {
|
77 |
-
return;
|
78 |
-
}
|
79 |
-
|
80 |
-
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
81 |
-
return;
|
82 |
-
}
|
83 |
-
|
84 |
-
// redirect only from any non HC checkout pages.
|
85 |
-
$order_pay_endpoint = get_option( 'woocommerce_checkout_order_pay_endpoint', 'order-pay' );
|
86 |
-
$order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
|
87 |
-
|
88 |
-
$common = Cartflows_Helper::get_common_settings();
|
89 |
-
|
90 |
-
$global_checkout = $common['global_checkout'];
|
91 |
-
|
92 |
-
if (
|
93 |
-
// ignore on order-pay.
|
94 |
-
false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
|
95 |
-
// ignore on TY page.
|
96 |
-
false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
|
97 |
-
) {
|
98 |
-
|
99 |
-
if ( '' !== $global_checkout ) {
|
100 |
-
|
101 |
-
$link = get_permalink( $global_checkout );
|
102 |
-
|
103 |
-
if ( ! empty( $link ) ) {
|
104 |
-
|
105 |
-
wp_redirect( $link );
|
106 |
-
die();
|
107 |
-
}
|
108 |
-
}
|
109 |
-
}
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Check for checkout flag
|
114 |
-
*
|
115 |
-
* @param bool $is_checkout is checkout.
|
116 |
-
*
|
117 |
-
* @return bool
|
118 |
-
*/
|
119 |
-
function woo_checkout_flag( $is_checkout ) {
|
120 |
-
|
121 |
-
if ( ! is_admin() ) {
|
122 |
-
|
123 |
-
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
124 |
-
|
125 |
-
$is_checkout = true;
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
-
return $is_checkout;
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* Render checkout shortcode markup.
|
134 |
-
*
|
135 |
-
* @param array $atts attributes.
|
136 |
-
* @return string
|
137 |
-
*/
|
138 |
-
function checkout_shortcode_markup( $atts ) {
|
139 |
-
|
140 |
-
$atts = shortcode_atts(
|
141 |
-
array(
|
142 |
-
'id' => 0,
|
143 |
-
),
|
144 |
-
$atts
|
145 |
-
);
|
146 |
-
|
147 |
-
$checkout_id = intval( $atts['id'] );
|
148 |
-
|
149 |
-
if ( empty( $checkout_id ) ) {
|
150 |
-
|
151 |
-
if ( ! _is_wcf_checkout_type() ) {
|
152 |
-
|
153 |
-
return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
|
154 |
-
}
|
155 |
-
|
156 |
-
global $post;
|
157 |
-
|
158 |
-
$checkout_id = intval( $post->ID );
|
159 |
-
}
|
160 |
-
|
161 |
-
$output = '';
|
162 |
-
|
163 |
-
ob_start();
|
164 |
-
|
165 |
-
do_action( 'cartflows_checkout_form_before', $checkout_id );
|
166 |
-
|
167 |
-
$checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
|
168 |
-
|
169 |
-
$template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
|
170 |
-
|
171 |
-
$template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
|
172 |
-
|
173 |
-
if ( file_exists( $template_layout ) ) {
|
174 |
-
include $template_layout;
|
175 |
-
} else {
|
176 |
-
include $template_default;
|
177 |
-
}
|
178 |
-
|
179 |
-
$output .= ob_get_clean();
|
180 |
-
|
181 |
-
return $output;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Configure Cart Data.
|
186 |
-
*
|
187 |
-
* @since 1.0.0
|
188 |
-
*
|
189 |
-
* @return void
|
190 |
-
*/
|
191 |
-
function preconfigured_cart_data() {
|
192 |
-
|
193 |
-
if ( is_admin() ) {
|
194 |
-
return;
|
195 |
-
}
|
196 |
-
|
197 |
-
global $post;
|
198 |
-
|
199 |
-
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
200 |
-
|
201 |
-
if ( wp_doing_ajax() ) {
|
202 |
-
|
203 |
-
return;
|
204 |
-
} else {
|
205 |
-
|
206 |
-
if ( _is_wcf_checkout_type() ) {
|
207 |
-
$checkout_id = $post->ID;
|
208 |
-
} else {
|
209 |
-
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
210 |
-
}
|
211 |
-
|
212 |
-
$flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
|
213 |
-
|
214 |
-
if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
|
215 |
-
$products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
|
216 |
-
} else {
|
217 |
-
$products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
|
218 |
-
}
|
219 |
-
|
220 |
-
if ( ! is_array( $products ) ) {
|
221 |
-
|
222 |
-
if ( 'dummy' === $products ) {
|
223 |
-
|
224 |
-
$args = array(
|
225 |
-
'posts_per_page' => 1,
|
226 |
-
'orderby' => 'rand',
|
227 |
-
'post_type' => 'product',
|
228 |
-
'meta_query' => array(
|
229 |
-
// Exclude out of stock products.
|
230 |
-
array(
|
231 |
-
'key' => '_stock_status',
|
232 |
-
'value' => 'outofstock',
|
233 |
-
'compare' => 'NOT IN',
|
234 |
-
),
|
235 |
-
),
|
236 |
-
'tax_query' => array(
|
237 |
-
array(
|
238 |
-
'taxonomy' => 'product_type',
|
239 |
-
'field' => 'slug',
|
240 |
-
'terms' => 'simple',
|
241 |
-
),
|
242 |
-
),
|
243 |
-
);
|
244 |
-
|
245 |
-
$random_product = get_posts( $args );
|
246 |
-
|
247 |
-
if ( isset( $random_product[0]->ID ) ) {
|
248 |
-
$products = array(
|
249 |
-
array(
|
250 |
-
'product' => $random_product[0]->ID,
|
251 |
-
),
|
252 |
-
);
|
253 |
-
} else {
|
254 |
-
return;
|
255 |
-
}
|
256 |
-
} else {
|
257 |
-
return;
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
if ( is_array( $products ) && count( $products ) < 1 ) {
|
262 |
-
|
263 |
-
return;
|
264 |
-
}
|
265 |
-
/* Empty the current cart */
|
266 |
-
WC()->cart->empty_cart();
|
267 |
-
|
268 |
-
/* Set customer session if not set */
|
269 |
-
if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
|
270 |
-
WC()->session->set_customer_session_cookie( true );
|
271 |
-
}
|
272 |
-
|
273 |
-
foreach ( $products as $index => $data ) {
|
274 |
-
|
275 |
-
if ( ! isset( $data['product'] ) ) {
|
276 |
-
return;
|
277 |
-
}
|
278 |
-
|
279 |
-
$product_id = $data['product'];
|
280 |
-
$_product = wc_get_product( $product_id );
|
281 |
-
|
282 |
-
if ( ! empty( $_product ) ) {
|
283 |
-
|
284 |
-
$quantity = 1;
|
285 |
-
|
286 |
-
if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
|
287 |
-
|
288 |
-
if ( $_product->is_type( 'variable' ) ) {
|
289 |
-
|
290 |
-
$default_attributes = $_product->get_default_attributes();
|
291 |
-
|
292 |
-
if ( ! empty( $default_attributes ) ) {
|
293 |
-
|
294 |
-
foreach ( $_product->get_children() as $variation_id ) {
|
295 |
-
|
296 |
-
$single_variation = new WC_Product_Variation( $variation_id );
|
297 |
-
|
298 |
-
if ( $default_attributes == $single_variation->get_attributes() ) {
|
299 |
-
WC()->cart->add_to_cart( $variation_id, $quantity );
|
300 |
-
}
|
301 |
-
}
|
302 |
-
} else {
|
303 |
-
|
304 |
-
$product_childrens = $_product->get_children();
|
305 |
-
|
306 |
-
if ( isset( $product_childrens[0] ) ) {
|
307 |
-
WC()->cart->add_to_cart( $product_childrens[0], $quantity );
|
308 |
-
} else {
|
309 |
-
echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
|
310 |
-
}
|
311 |
-
}
|
312 |
-
} else {
|
313 |
-
WC()->cart->add_to_cart( $product_id, $quantity );
|
314 |
-
}
|
315 |
-
} else {
|
316 |
-
|
317 |
-
echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
|
318 |
-
// WC()->cart->add_to_cart( $product_id, $quantity );.
|
319 |
-
}
|
320 |
-
}
|
321 |
-
}
|
322 |
-
|
323 |
-
do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
|
324 |
-
}
|
325 |
-
}
|
326 |
-
}
|
327 |
-
|
328 |
-
/**
|
329 |
-
* Load shortcode data.
|
330 |
-
*
|
331 |
-
* @return void
|
332 |
-
*/
|
333 |
-
function shortcode_load_data() {
|
334 |
-
|
335 |
-
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
336 |
-
|
337 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
|
338 |
-
|
339 |
-
// Outputting the hidden field in checkout page.
|
340 |
-
add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
|
341 |
-
add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
|
342 |
-
|
343 |
-
remove_all_actions( 'woocommerce_checkout_billing' );
|
344 |
-
remove_all_actions( 'woocommerce_checkout_shipping' );
|
345 |
-
|
346 |
-
// Hook in actions once.
|
347 |
-
add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
|
348 |
-
add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
|
349 |
-
|
350 |
-
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
|
351 |
-
|
352 |
-
add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
|
353 |
-
|
354 |
-
add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
|
355 |
-
|
356 |
-
global $post;
|
357 |
-
|
358 |
-
if ( _is_wcf_checkout_type() ) {
|
359 |
-
$checkout_id = $post->ID;
|
360 |
-
} else {
|
361 |
-
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
362 |
-
}
|
363 |
-
|
364 |
-
do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
|
365 |
-
}
|
366 |
-
}
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Render checkout ID hidden field.
|
370 |
-
*
|
371 |
-
* @param array $checkout checkout session data.
|
372 |
-
* @return void
|
373 |
-
*/
|
374 |
-
function checkout_shortcode_post_id( $checkout ) {
|
375 |
-
|
376 |
-
global $post;
|
377 |
-
|
378 |
-
if ( _is_wcf_checkout_type() ) {
|
379 |
-
$checkout_id = $post->ID;
|
380 |
-
} else {
|
381 |
-
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
382 |
-
}
|
383 |
-
|
384 |
-
$flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
|
385 |
-
|
386 |
-
echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
|
387 |
-
echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
|
388 |
-
}
|
389 |
-
|
390 |
-
/**
|
391 |
-
* Load shortcode scripts.
|
392 |
-
*
|
393 |
-
* @return void
|
394 |
-
*/
|
395 |
-
function shortcode_scripts() {
|
396 |
-
|
397 |
-
wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
|
398 |
-
wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
|
399 |
-
|
400 |
-
if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
|
401 |
-
wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
|
402 |
-
wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
|
403 |
-
}
|
404 |
-
|
405 |
-
wp_enqueue_script(
|
406 |
-
'wcf-checkout-template',
|
407 |
-
CARTFLOWS_URL . 'assets/js/checkout-template.js',
|
408 |
-
array( 'jquery' ),
|
409 |
-
CARTFLOWS_VER,
|
410 |
-
true
|
411 |
-
);
|
412 |
-
|
413 |
-
do_action( 'cartflows_checkout_scripts' );
|
414 |
-
|
415 |
-
$style = $this->generate_style();
|
416 |
-
|
417 |
-
wp_add_inline_style( 'wcf-checkout-template', $style );
|
418 |
-
|
419 |
-
}
|
420 |
-
|
421 |
-
/**
|
422 |
-
* Generate styles.
|
423 |
-
*
|
424 |
-
* @return string
|
425 |
-
*/
|
426 |
-
function generate_style() {
|
427 |
-
|
428 |
-
global $post;
|
429 |
-
|
430 |
-
if ( _is_wcf_checkout_type() ) {
|
431 |
-
$checkout_id = $post->ID;
|
432 |
-
} else {
|
433 |
-
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
434 |
-
}
|
435 |
-
|
436 |
-
CartFlows_Font_Families::render_fonts( $checkout_id );
|
437 |
-
|
438 |
-
$primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
|
439 |
-
|
440 |
-
$base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
|
441 |
-
|
442 |
-
$header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
|
443 |
-
|
444 |
-
/*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
|
445 |
-
|
446 |
-
$field_tb_padding = '';
|
447 |
-
$field_lr_padding = '';
|
448 |
-
|
449 |
-
$field_heading_color = '';
|
450 |
-
$field_color = '';
|
451 |
-
$field_bg_color = '';
|
452 |
-
$field_border_color = '';
|
453 |
-
$field_label_color = '';
|
454 |
-
$submit_tb_padding = '';
|
455 |
-
$submit_lr_padding = '';
|
456 |
-
$hl_bg_color = '';
|
457 |
-
$field_input_size = '';
|
458 |
-
$box_border_color = '';
|
459 |
-
$section_bg_color = '';
|
460 |
-
$submit_button_height = '';
|
461 |
-
$submit_color = '';
|
462 |
-
$submit_bg_color = $primary_color;
|
463 |
-
$submit_border_color = $primary_color;
|
464 |
-
|
465 |
-
$submit_hover_color = '';
|
466 |
-
$submit_bg_hover_color = $primary_color;
|
467 |
-
$submit_border_hover_color = $primary_color;
|
468 |
-
|
469 |
-
$section_heading_color = '';
|
470 |
-
|
471 |
-
$is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
|
472 |
-
|
473 |
-
$button_font_family = '';
|
474 |
-
$button_font_weight = '';
|
475 |
-
$input_font_family = '';
|
476 |
-
$input_font_weight = '';
|
477 |
-
$heading_font_family = '';
|
478 |
-
$heading_font_weight = '';
|
479 |
-
$base_font_family = $base_font_family;
|
480 |
-
/*$base_font_weight = $base_font_weight;*/
|
481 |
-
|
482 |
-
if ( 'yes' == $is_advance_option ) {
|
483 |
-
|
484 |
-
/**
|
485 |
-
* Get Font Family and Font Weight weight values
|
486 |
-
*/
|
487 |
-
$section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
|
488 |
-
|
489 |
-
$heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
|
490 |
-
$heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
|
491 |
-
$section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
|
492 |
-
$button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
|
493 |
-
$button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
|
494 |
-
$input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
|
495 |
-
$input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
|
496 |
-
$field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
|
497 |
-
$field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
|
498 |
-
$field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
|
499 |
-
|
500 |
-
$field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
|
501 |
-
|
502 |
-
$field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
|
503 |
-
|
504 |
-
$field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
|
505 |
-
|
506 |
-
$field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
|
507 |
-
|
508 |
-
$field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
|
509 |
-
|
510 |
-
$submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
|
511 |
-
|
512 |
-
$submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
|
513 |
-
|
514 |
-
$submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
|
515 |
-
|
516 |
-
$submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
|
517 |
-
|
518 |
-
$submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
|
519 |
-
|
520 |
-
$submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
|
521 |
-
|
522 |
-
$submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
|
523 |
-
|
524 |
-
$submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
|
525 |
-
|
526 |
-
$hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
|
527 |
-
|
528 |
-
$box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
|
529 |
-
|
530 |
-
$submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
|
531 |
-
|
532 |
-
/**
|
533 |
-
* Get font values
|
534 |
-
*/
|
535 |
-
|
536 |
-
if ( 'custom' == $submit_button_height ) {
|
537 |
-
$submit_button_height = '38px';
|
538 |
-
}
|
539 |
-
|
540 |
-
if ( 'custom' == $field_input_size ) {
|
541 |
-
$field_input_size = '38px';
|
542 |
-
}
|
543 |
-
}
|
544 |
-
|
545 |
-
$output = "
|
546 |
-
.wcf-embed-checkout-form .wcf-checkout-header-image img{
|
547 |
-
width: {$header_logo_width}px;
|
548 |
-
}
|
549 |
-
.wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:after,
|
550 |
-
.wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:not(:checked):after,
|
551 |
-
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label:after,
|
552 |
-
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label:after {
|
553 |
-
background: {$primary_color};
|
554 |
-
}
|
555 |
-
|
556 |
-
.wcf-embed-checkout-form .woocommerce-checkout label{
|
557 |
-
color: {$field_label_color};
|
558 |
-
}
|
559 |
-
.wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
|
560 |
-
background-color: {$hl_bg_color};
|
561 |
-
font-family: {$input_font_family};
|
562 |
-
font-weight: {$input_font_weight};
|
563 |
-
}
|
564 |
-
|
565 |
-
.wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
|
566 |
-
.wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
|
567 |
-
.wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
|
568 |
-
{
|
569 |
-
border-color: {$hl_bg_color};
|
570 |
-
border-right-color: transparent;
|
571 |
-
border-left-color: transparent;
|
572 |
-
border-top-color: transparent;
|
573 |
-
position: absolute;
|
574 |
-
}
|
575 |
-
|
576 |
-
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
|
577 |
-
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
|
578 |
-
font-family: {$input_font_family};
|
579 |
-
font-weight: {$input_font_weight};
|
580 |
-
}
|
581 |
-
|
582 |
-
.wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
|
583 |
-
.wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
|
584 |
-
.wcf-embed-checkout-form .woocommerce form .form-row textarea,
|
585 |
-
.wcf-embed-checkout-form .select2-container--default .select2-selection--single {
|
586 |
-
color: {$field_color};
|
587 |
-
background: {$field_bg_color};
|
588 |
-
border-color: {$field_border_color};
|
589 |
-
padding-top: {$field_tb_padding}px;
|
590 |
-
padding-bottom: {$field_tb_padding}px;
|
591 |
-
padding-left: {$field_lr_padding}px;
|
592 |
-
padding-right: {$field_lr_padding}px;
|
593 |
-
min-height: {$field_input_size};
|
594 |
-
font-family: {$input_font_family};
|
595 |
-
font-weight: {$input_font_weight};
|
596 |
-
}
|
597 |
-
|
598 |
-
.wcf-embed-checkout-form .woocommerce .col2-set .col-1,
|
599 |
-
.wcf-embed-checkout-form .woocommerce .col2-set .col-2,
|
600 |
-
.wcf-embed-checkout-form .woocommerce-checkout .shop_table,
|
601 |
-
.wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
|
602 |
-
.wcf-embed-checkout-form .woocommerce-checkout #payment,
|
603 |
-
.wcf-embed-checkout-form .woocommerce form.checkout_coupon
|
604 |
-
{
|
605 |
-
background-color: {$section_bg_color};
|
606 |
-
border-color: {$box_border_color};
|
607 |
-
font-family: {$input_font_family};
|
608 |
-
font-weight: {$input_font_weight};
|
609 |
-
}
|
610 |
-
|
611 |
-
.woocommerce table.shop_table th{
|
612 |
-
color: {$field_label_color};
|
613 |
-
}
|
614 |
-
.wcf-embed-checkout-form .woocommerce .woocommerce-info,
|
615 |
-
.wcf-embed-checkout-form .woocommerce-message{
|
616 |
-
border-top-color: {$primary_color};
|
617 |
-
background-color: {$hl_bg_color};
|
618 |
-
}
|
619 |
-
.wcf-embed-checkout-form .woocommerce a{
|
620 |
-
color: {$primary_color};
|
621 |
-
}
|
622 |
-
.wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
|
623 |
-
color: {$field_color};
|
624 |
-
}
|
625 |
-
.wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
|
626 |
-
color: {$field_color};
|
627 |
-
}
|
628 |
-
.wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
|
629 |
-
color: {$field_color};
|
630 |
-
}
|
631 |
-
.wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
|
632 |
-
color: {$field_color};
|
633 |
-
}
|
634 |
-
.wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
|
635 |
-
color: {$field_color};
|
636 |
-
}
|
637 |
-
.wcf-embed-checkout-form .woocommerce form p.form-row label {
|
638 |
-
color: {$field_label_color};
|
639 |
-
font-family: {$input_font_family};
|
640 |
-
font-weight: {$input_font_weight};
|
641 |
-
}
|
642 |
-
.wcf-embed-checkout-form .woocommerce #order_review button {
|
643 |
-
color: {$submit_color};
|
644 |
-
background: {$submit_bg_color};
|
645 |
-
padding-top: {$submit_tb_padding}px;
|
646 |
-
padding-bottom: {$submit_tb_padding}px;
|
647 |
-
padding-left: {$submit_lr_padding}px;
|
648 |
-
padding-right: {$submit_lr_padding}px;
|
649 |
-
border-color: {$submit_border_color};
|
650 |
-
min-height: {$submit_button_height};
|
651 |
-
font-family: {$button_font_family};
|
652 |
-
font-weight: {$button_font_weight};
|
653 |
-
}
|
654 |
-
.wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
|
655 |
-
.wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
|
656 |
-
background: {$submit_bg_color};
|
657 |
-
border: 1px {$submit_border_color} solid;
|
658 |
-
color: {$submit_color};
|
659 |
-
min-height: {$submit_button_height};
|
660 |
-
font-family: {$button_font_family};
|
661 |
-
font-weight: {$button_font_weight};
|
662 |
-
}
|
663 |
-
.wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
|
664 |
-
.wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
|
665 |
-
.wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
|
666 |
-
.wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
|
667 |
-
color: {$submit_hover_color};
|
668 |
-
background-color: {$submit_bg_hover_color};
|
669 |
-
border-color: {$submit_border_hover_color};
|
670 |
-
}
|
671 |
-
.wcf-embed-checkout-form .woocommerce h3,
|
672 |
-
.wcf-embed-checkout-form .woocommerce h3 span,
|
673 |
-
.wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
|
674 |
-
color: {$section_heading_color};
|
675 |
-
font-family: {$heading_font_family};
|
676 |
-
font-weight: {$heading_font_weight};
|
677 |
-
}
|
678 |
-
.wcf-embed-checkout-form .woocommerce-info::before,
|
679 |
-
.wcf-embed-checkout-form .woocommerce-message::before{
|
680 |
-
color: {$primary_color};
|
681 |
-
}
|
682 |
-
.wcf-embed-checkout-form{
|
683 |
-
font-family: {$base_font_family};
|
684 |
-
}";
|
685 |
-
|
686 |
-
return $output;
|
687 |
-
}
|
688 |
-
|
689 |
-
/**
|
690 |
-
* Get ajax end points.
|
691 |
-
*
|
692 |
-
* @param string $endpoint_url end point URL.
|
693 |
-
* @return string
|
694 |
-
*/
|
695 |
-
function get_ajax_endpoint( $endpoint_url ) {
|
696 |
-
|
697 |
-
global $post;
|
698 |
-
|
699 |
-
if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
|
700 |
-
|
701 |
-
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
702 |
-
|
703 |
-
if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
|
704 |
-
|
705 |
-
$query_args = array(
|
706 |
-
'wc-ajax' => '%%endpoint%%',
|
707 |
-
);
|
708 |
-
|
709 |
-
$uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
|
710 |
-
$uri = $uri[0];
|
711 |
-
|
712 |
-
$endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
|
713 |
-
}
|
714 |
-
}
|
715 |
-
}
|
716 |
-
|
717 |
-
return $endpoint_url;
|
718 |
-
}
|
719 |
-
|
720 |
-
|
721 |
-
/**
|
722 |
-
* Save checkout fields.
|
723 |
-
*
|
724 |
-
* @param int $order_id order id.
|
725 |
-
* @param array $posted posted data.
|
726 |
-
* @return void
|
727 |
-
*/
|
728 |
-
function save_checkout_fields( $order_id, $posted ) {
|
729 |
-
|
730 |
-
if ( isset( $_POST['_wcf_checkout_id'] ) ) {
|
731 |
-
|
732 |
-
$checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
|
733 |
-
|
734 |
-
update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
|
735 |
-
|
736 |
-
/*
|
737 |
-
Custom Field To Do
|
738 |
-
$custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
|
739 |
-
|
740 |
-
if ( 'yes' === $custom_fields ) {
|
741 |
-
|
742 |
-
$billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
|
743 |
-
|
744 |
-
foreach ( $billing_fields as $field => $data ) {
|
745 |
-
|
746 |
-
if ( isset( $data['custom'] ) && $data['custom'] ) {
|
747 |
-
|
748 |
-
if ( isset( $_POST[ $field ] ) ) {
|
749 |
-
update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
|
750 |
-
}
|
751 |
-
}
|
752 |
-
}
|
753 |
-
|
754 |
-
$shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
|
755 |
-
|
756 |
-
foreach ( $shipping_fields as $field => $data ) {
|
757 |
-
|
758 |
-
if ( isset( $data['custom'] ) && $data['custom'] ) {
|
759 |
-
|
760 |
-
if ( isset( $_POST[ $field ] ) ) {
|
761 |
-
update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
|
762 |
-
}
|
763 |
-
}
|
764 |
-
}
|
765 |
-
}
|
766 |
-
*/
|
767 |
-
if ( isset( $_POST['_wcf_flow_id'] ) ) {
|
768 |
-
|
769 |
-
$checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
|
770 |
-
|
771 |
-
update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
|
772 |
-
}
|
773 |
-
}
|
774 |
-
|
775 |
-
}
|
776 |
-
|
777 |
-
/**
|
778 |
-
* Enable Logo In Header Of Checkout Page
|
779 |
-
*
|
780 |
-
* @return void
|
781 |
-
*/
|
782 |
-
function enable_logo_in_header() {
|
783 |
-
global $post;
|
784 |
-
|
785 |
-
if ( _is_wcf_checkout_type() ) {
|
786 |
-
$checkout_id = $post->ID;
|
787 |
-
} else {
|
788 |
-
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
789 |
-
}
|
790 |
-
|
791 |
-
$header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
|
792 |
-
$add_image_markup = '';
|
793 |
-
|
794 |
-
if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
|
795 |
-
$add_image_markup = '<div class="wcf-checkout-header-image">';
|
796 |
-
$add_image_markup .= '<img src="' . $header_logo_image . '" />';
|
797 |
-
$add_image_markup .= '</div>';
|
798 |
-
}
|
799 |
-
|
800 |
-
echo $add_image_markup;
|
801 |
-
}
|
802 |
-
|
803 |
-
/**
|
804 |
-
* Add text to the bootom of the checkout page.
|
805 |
-
*
|
806 |
-
* @return void
|
807 |
-
*/
|
808 |
-
function show_cartflows_copyright_message() {
|
809 |
-
$output_string = '';
|
810 |
-
|
811 |
-
$output_string .= '<div class="wcf-footer-primary">';
|
812 |
-
$output_string .= '<div class="wcf-footer-content">';
|
813 |
-
$output_string .= '<p class="wcf-footer-message">';
|
814 |
-
$output_string .= 'Checkout powered by CartFlows';
|
815 |
-
$output_string .= '</p>';
|
816 |
-
$output_string .= '</div>';
|
817 |
-
$output_string .= '</div>';
|
818 |
-
|
819 |
-
echo $output_string;
|
820 |
-
}
|
821 |
-
|
822 |
-
/**
|
823 |
-
* Redirect users to our checkout if hidden param
|
824 |
-
*
|
825 |
-
* @param string $redirect redirect url.
|
826 |
-
* @param object $user user.
|
827 |
-
* @return string
|
828 |
-
*/
|
829 |
-
function after_login_redirect( $redirect, $user ) {
|
830 |
-
|
831 |
-
if ( isset( $_POST['_wcf_checkout_id'] ) ) {
|
832 |
-
|
833 |
-
$checkout_id = intval( $_POST['_wcf_checkout_id'] );
|
834 |
-
|
835 |
-
$redirect = get_permalink( $checkout_id );
|
836 |
-
}
|
837 |
-
|
838 |
-
return $redirect;
|
839 |
-
}
|
840 |
-
|
841 |
-
/**
|
842 |
-
* Display coupon code field after review order fields.
|
843 |
-
*/
|
844 |
-
function display_custom_coupon_field() {
|
845 |
-
|
846 |
-
$coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
|
847 |
-
|
848 |
-
if ( ! $coupon_enabled ) {
|
849 |
-
return;
|
850 |
-
}
|
851 |
-
|
852 |
-
ob_start();
|
853 |
-
|
854 |
-
?>
|
855 |
-
<div class="wcf-custom-coupon-field">
|
856 |
-
<div class="wcf-coupon-col-1">
|
857 |
-
<span>
|
858 |
-
<input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
|
859 |
-
</span>
|
860 |
-
</div>
|
861 |
-
<div class="wcf-coupon-col-2">
|
862 |
-
<span>
|
863 |
-
<button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
|
864 |
-
</span>
|
865 |
-
</div>
|
866 |
-
</div>
|
867 |
-
|
868 |
-
<?php
|
869 |
-
|
870 |
-
echo ob_get_clean();
|
871 |
-
}
|
872 |
-
|
873 |
-
/**
|
874 |
-
* Apply coupon on submit of custom coupon form.
|
875 |
-
*/
|
876 |
-
function apply_coupon() {
|
877 |
-
|
878 |
-
check_ajax_referer( 'cf-apply-coupon', 'security' );
|
879 |
-
|
880 |
-
$result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
|
881 |
-
|
882 |
-
echo json_encode( $result );
|
883 |
-
die();
|
884 |
-
}
|
885 |
-
|
886 |
-
/**
|
887 |
-
* Added ajax nonce to localize variable.
|
888 |
-
*
|
889 |
-
* @param array $vars localize variables.
|
890 |
-
*/
|
891 |
-
function add_localize_vars( $vars ) {
|
892 |
-
|
893 |
-
$vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
|
894 |
-
|
895 |
-
return $vars;
|
896 |
-
}
|
897 |
-
|
898 |
-
/**
|
899 |
-
* Add custom class to the fields to change the UI to three column.
|
900 |
-
*
|
901 |
-
* @param array $fields fields.
|
902 |
-
*/
|
903 |
-
function add_three_column_layout_fields( $fields ) {
|
904 |
-
|
905 |
-
if ( empty( $fields['billing']['billing_address_2'] ) ) {
|
906 |
-
|
907 |
-
if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
|
908 |
-
$fields['billing']['billing_address_1']['class'][] = 'form-row-full';
|
909 |
-
}
|
910 |
-
}
|
911 |
-
|
912 |
-
if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
|
913 |
-
|
914 |
-
if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
|
915 |
-
$fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
|
916 |
-
}
|
917 |
-
}
|
918 |
-
|
919 |
-
if ( isset( $fields['billing']['billing_city'] ) &&
|
920 |
-
isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
|
921 |
-
|
922 |
-
$fields['billing']['billing_city']['class'] = array( 'wcf-form-col-3' );
|
923 |
-
$fields['billing']['billing_state']['class'] = array( 'wcf-form-col-3' );
|
924 |
-
$fields['billing']['billing_postcode']['class'] = array( 'wcf-form-col-3' );
|
925 |
-
}
|
926 |
-
|
927 |
-
if ( isset( $fields['shipping']['shipping_city'] ) &&
|
928 |
-
isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
|
929 |
-
|
930 |
-
$fields['shipping']['shipping_city']['class'] = array( 'wcf-form-col-3' );
|
931 |
-
$fields['shipping']['shipping_state']['class'] = array( 'wcf-form-col-3' );
|
932 |
-
$fields['shipping']['shipping_postcode']['class'] = array( 'wcf-form-col-3' );
|
933 |
-
}
|
934 |
-
|
935 |
-
return $fields;
|
936 |
-
}
|
937 |
-
}
|
938 |
-
|
939 |
-
/**
|
940 |
-
* Kicking this off by calling 'get_instance()' method
|
941 |
-
*/
|
942 |
-
Cartflows_Checkout_Markup::get_instance();
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Checkout markup.
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Checkout Markup
|
10 |
+
*
|
11 |
+
* @since 1.0.0
|
12 |
+
*/
|
13 |
+
class Cartflows_Checkout_Markup {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Member Variable
|
17 |
+
*
|
18 |
+
* @var object instance
|
19 |
+
*/
|
20 |
+
private static $instance;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Initiator
|
24 |
+
*/
|
25 |
+
public static function get_instance() {
|
26 |
+
if ( ! isset( self::$instance ) ) {
|
27 |
+
self::$instance = new self;
|
28 |
+
}
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Constructor
|
34 |
+
*/
|
35 |
+
public function __construct() {
|
36 |
+
|
37 |
+
/* Set is checkout flag */
|
38 |
+
add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
|
39 |
+
|
40 |
+
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_checkout_fields' ), 10, 2 );
|
41 |
+
|
42 |
+
/* Checkout Shortcode */
|
43 |
+
add_shortcode( 'cartflows_checkout', array( $this, 'checkout_shortcode_markup' ) );
|
44 |
+
|
45 |
+
/* Preconfigured cart data */
|
46 |
+
add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
|
47 |
+
|
48 |
+
/* Embed Checkout */
|
49 |
+
add_action( 'wp', array( $this, 'shortcode_load_data' ), 999 );
|
50 |
+
|
51 |
+
/* Ajax Endpoint */
|
52 |
+
add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ) );
|
53 |
+
|
54 |
+
add_filter( 'cartflows_add_before_main_section', array( $this, 'enable_logo_in_header' ) );
|
55 |
+
|
56 |
+
add_filter( 'cartflows_primary_container_bottom', array( $this, 'show_cartflows_copyright_message' ) );
|
57 |
+
|
58 |
+
add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
|
59 |
+
|
60 |
+
add_action( 'wp_ajax_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
|
61 |
+
add_action( 'wp_ajax_nopriv_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
|
62 |
+
|
63 |
+
add_filter( 'global_cartflows_js_localize', array( $this, 'add_localize_vars' ) );
|
64 |
+
|
65 |
+
/* Global Checkout */
|
66 |
+
add_action( 'template_redirect', array( $this, 'global_checkout_template_redirect' ), 1 );
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Redirect from default to the global checkout page
|
71 |
+
*
|
72 |
+
* @since 1.0.0
|
73 |
+
*/
|
74 |
+
function global_checkout_template_redirect() {
|
75 |
+
|
76 |
+
if ( ! is_checkout() ) {
|
77 |
+
return;
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
81 |
+
return;
|
82 |
+
}
|
83 |
+
|
84 |
+
// redirect only from any non HC checkout pages.
|
85 |
+
$order_pay_endpoint = get_option( 'woocommerce_checkout_order_pay_endpoint', 'order-pay' );
|
86 |
+
$order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
|
87 |
+
|
88 |
+
$common = Cartflows_Helper::get_common_settings();
|
89 |
+
|
90 |
+
$global_checkout = $common['global_checkout'];
|
91 |
+
|
92 |
+
if (
|
93 |
+
// ignore on order-pay.
|
94 |
+
false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
|
95 |
+
// ignore on TY page.
|
96 |
+
false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
|
97 |
+
) {
|
98 |
+
|
99 |
+
if ( '' !== $global_checkout ) {
|
100 |
+
|
101 |
+
$link = get_permalink( $global_checkout );
|
102 |
+
|
103 |
+
if ( ! empty( $link ) ) {
|
104 |
+
|
105 |
+
wp_redirect( $link );
|
106 |
+
die();
|
107 |
+
}
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Check for checkout flag
|
114 |
+
*
|
115 |
+
* @param bool $is_checkout is checkout.
|
116 |
+
*
|
117 |
+
* @return bool
|
118 |
+
*/
|
119 |
+
function woo_checkout_flag( $is_checkout ) {
|
120 |
+
|
121 |
+
if ( ! is_admin() ) {
|
122 |
+
|
123 |
+
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
124 |
+
|
125 |
+
$is_checkout = true;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
return $is_checkout;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Render checkout shortcode markup.
|
134 |
+
*
|
135 |
+
* @param array $atts attributes.
|
136 |
+
* @return string
|
137 |
+
*/
|
138 |
+
function checkout_shortcode_markup( $atts ) {
|
139 |
+
|
140 |
+
$atts = shortcode_atts(
|
141 |
+
array(
|
142 |
+
'id' => 0,
|
143 |
+
),
|
144 |
+
$atts
|
145 |
+
);
|
146 |
+
|
147 |
+
$checkout_id = intval( $atts['id'] );
|
148 |
+
|
149 |
+
if ( empty( $checkout_id ) ) {
|
150 |
+
|
151 |
+
if ( ! _is_wcf_checkout_type() ) {
|
152 |
+
|
153 |
+
return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
|
154 |
+
}
|
155 |
+
|
156 |
+
global $post;
|
157 |
+
|
158 |
+
$checkout_id = intval( $post->ID );
|
159 |
+
}
|
160 |
+
|
161 |
+
$output = '';
|
162 |
+
|
163 |
+
ob_start();
|
164 |
+
|
165 |
+
do_action( 'cartflows_checkout_form_before', $checkout_id );
|
166 |
+
|
167 |
+
$checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
|
168 |
+
|
169 |
+
$template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
|
170 |
+
|
171 |
+
$template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
|
172 |
+
|
173 |
+
if ( file_exists( $template_layout ) ) {
|
174 |
+
include $template_layout;
|
175 |
+
} else {
|
176 |
+
include $template_default;
|
177 |
+
}
|
178 |
+
|
179 |
+
$output .= ob_get_clean();
|
180 |
+
|
181 |
+
return $output;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Configure Cart Data.
|
186 |
+
*
|
187 |
+
* @since 1.0.0
|
188 |
+
*
|
189 |
+
* @return void
|
190 |
+
*/
|
191 |
+
function preconfigured_cart_data() {
|
192 |
+
|
193 |
+
if ( is_admin() ) {
|
194 |
+
return;
|
195 |
+
}
|
196 |
+
|
197 |
+
global $post;
|
198 |
+
|
199 |
+
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
200 |
+
|
201 |
+
if ( wp_doing_ajax() ) {
|
202 |
+
|
203 |
+
return;
|
204 |
+
} else {
|
205 |
+
|
206 |
+
if ( _is_wcf_checkout_type() ) {
|
207 |
+
$checkout_id = $post->ID;
|
208 |
+
} else {
|
209 |
+
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
210 |
+
}
|
211 |
+
|
212 |
+
$flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
|
213 |
+
|
214 |
+
if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
|
215 |
+
$products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
|
216 |
+
} else {
|
217 |
+
$products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
|
218 |
+
}
|
219 |
+
|
220 |
+
if ( ! is_array( $products ) ) {
|
221 |
+
|
222 |
+
if ( 'dummy' === $products ) {
|
223 |
+
|
224 |
+
$args = array(
|
225 |
+
'posts_per_page' => 1,
|
226 |
+
'orderby' => 'rand',
|
227 |
+
'post_type' => 'product',
|
228 |
+
'meta_query' => array(
|
229 |
+
// Exclude out of stock products.
|
230 |
+
array(
|
231 |
+
'key' => '_stock_status',
|
232 |
+
'value' => 'outofstock',
|
233 |
+
'compare' => 'NOT IN',
|
234 |
+
),
|
235 |
+
),
|
236 |
+
'tax_query' => array(
|
237 |
+
array(
|
238 |
+
'taxonomy' => 'product_type',
|
239 |
+
'field' => 'slug',
|
240 |
+
'terms' => 'simple',
|
241 |
+
),
|
242 |
+
),
|
243 |
+
);
|
244 |
+
|
245 |
+
$random_product = get_posts( $args );
|
246 |
+
|
247 |
+
if ( isset( $random_product[0]->ID ) ) {
|
248 |
+
$products = array(
|
249 |
+
array(
|
250 |
+
'product' => $random_product[0]->ID,
|
251 |
+
),
|
252 |
+
);
|
253 |
+
} else {
|
254 |
+
return;
|
255 |
+
}
|
256 |
+
} else {
|
257 |
+
return;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
if ( is_array( $products ) && count( $products ) < 1 ) {
|
262 |
+
|
263 |
+
return;
|
264 |
+
}
|
265 |
+
/* Empty the current cart */
|
266 |
+
WC()->cart->empty_cart();
|
267 |
+
|
268 |
+
/* Set customer session if not set */
|
269 |
+
if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
|
270 |
+
WC()->session->set_customer_session_cookie( true );
|
271 |
+
}
|
272 |
+
|
273 |
+
foreach ( $products as $index => $data ) {
|
274 |
+
|
275 |
+
if ( ! isset( $data['product'] ) ) {
|
276 |
+
return;
|
277 |
+
}
|
278 |
+
|
279 |
+
$product_id = $data['product'];
|
280 |
+
$_product = wc_get_product( $product_id );
|
281 |
+
|
282 |
+
if ( ! empty( $_product ) ) {
|
283 |
+
|
284 |
+
$quantity = 1;
|
285 |
+
|
286 |
+
if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
|
287 |
+
|
288 |
+
if ( $_product->is_type( 'variable' ) ) {
|
289 |
+
|
290 |
+
$default_attributes = $_product->get_default_attributes();
|
291 |
+
|
292 |
+
if ( ! empty( $default_attributes ) ) {
|
293 |
+
|
294 |
+
foreach ( $_product->get_children() as $variation_id ) {
|
295 |
+
|
296 |
+
$single_variation = new WC_Product_Variation( $variation_id );
|
297 |
+
|
298 |
+
if ( $default_attributes == $single_variation->get_attributes() ) {
|
299 |
+
WC()->cart->add_to_cart( $variation_id, $quantity );
|
300 |
+
}
|
301 |
+
}
|
302 |
+
} else {
|
303 |
+
|
304 |
+
$product_childrens = $_product->get_children();
|
305 |
+
|
306 |
+
if ( isset( $product_childrens[0] ) ) {
|
307 |
+
WC()->cart->add_to_cart( $product_childrens[0], $quantity );
|
308 |
+
} else {
|
309 |
+
echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
|
310 |
+
}
|
311 |
+
}
|
312 |
+
} else {
|
313 |
+
WC()->cart->add_to_cart( $product_id, $quantity );
|
314 |
+
}
|
315 |
+
} else {
|
316 |
+
|
317 |
+
echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
|
318 |
+
// WC()->cart->add_to_cart( $product_id, $quantity );.
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
|
324 |
+
}
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
/**
|
329 |
+
* Load shortcode data.
|
330 |
+
*
|
331 |
+
* @return void
|
332 |
+
*/
|
333 |
+
function shortcode_load_data() {
|
334 |
+
|
335 |
+
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
336 |
+
|
337 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
|
338 |
+
|
339 |
+
// Outputting the hidden field in checkout page.
|
340 |
+
add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
|
341 |
+
add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
|
342 |
+
|
343 |
+
remove_all_actions( 'woocommerce_checkout_billing' );
|
344 |
+
remove_all_actions( 'woocommerce_checkout_shipping' );
|
345 |
+
|
346 |
+
// Hook in actions once.
|
347 |
+
add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
|
348 |
+
add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
|
349 |
+
|
350 |
+
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
|
351 |
+
|
352 |
+
add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
|
353 |
+
|
354 |
+
add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
|
355 |
+
|
356 |
+
global $post;
|
357 |
+
|
358 |
+
if ( _is_wcf_checkout_type() ) {
|
359 |
+
$checkout_id = $post->ID;
|
360 |
+
} else {
|
361 |
+
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
362 |
+
}
|
363 |
+
|
364 |
+
do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Render checkout ID hidden field.
|
370 |
+
*
|
371 |
+
* @param array $checkout checkout session data.
|
372 |
+
* @return void
|
373 |
+
*/
|
374 |
+
function checkout_shortcode_post_id( $checkout ) {
|
375 |
+
|
376 |
+
global $post;
|
377 |
+
|
378 |
+
if ( _is_wcf_checkout_type() ) {
|
379 |
+
$checkout_id = $post->ID;
|
380 |
+
} else {
|
381 |
+
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
382 |
+
}
|
383 |
+
|
384 |
+
$flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
|
385 |
+
|
386 |
+
echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
|
387 |
+
echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
|
388 |
+
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Load shortcode scripts.
|
392 |
+
*
|
393 |
+
* @return void
|
394 |
+
*/
|
395 |
+
function shortcode_scripts() {
|
396 |
+
|
397 |
+
wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
|
398 |
+
wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
|
399 |
+
|
400 |
+
if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
|
401 |
+
wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
|
402 |
+
wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
|
403 |
+
}
|
404 |
+
|
405 |
+
wp_enqueue_script(
|
406 |
+
'wcf-checkout-template',
|
407 |
+
CARTFLOWS_URL . 'assets/js/checkout-template.js',
|
408 |
+
array( 'jquery' ),
|
409 |
+
CARTFLOWS_VER,
|
410 |
+
true
|
411 |
+
);
|
412 |
+
|
413 |
+
do_action( 'cartflows_checkout_scripts' );
|
414 |
+
|
415 |
+
$style = $this->generate_style();
|
416 |
+
|
417 |
+
wp_add_inline_style( 'wcf-checkout-template', $style );
|
418 |
+
|
419 |
+
}
|
420 |
+
|
421 |
+
/**
|
422 |
+
* Generate styles.
|
423 |
+
*
|
424 |
+
* @return string
|
425 |
+
*/
|
426 |
+
function generate_style() {
|
427 |
+
|
428 |
+
global $post;
|
429 |
+
|
430 |
+
if ( _is_wcf_checkout_type() ) {
|
431 |
+
$checkout_id = $post->ID;
|
432 |
+
} else {
|
433 |
+
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
434 |
+
}
|
435 |
+
|
436 |
+
CartFlows_Font_Families::render_fonts( $checkout_id );
|
437 |
+
|
438 |
+
$primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
|
439 |
+
|
440 |
+
$base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
|
441 |
+
|
442 |
+
$header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
|
443 |
+
|
444 |
+
/*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
|
445 |
+
|
446 |
+
$field_tb_padding = '';
|
447 |
+
$field_lr_padding = '';
|
448 |
+
|
449 |
+
$field_heading_color = '';
|
450 |
+
$field_color = '';
|
451 |
+
$field_bg_color = '';
|
452 |
+
$field_border_color = '';
|
453 |
+
$field_label_color = '';
|
454 |
+
$submit_tb_padding = '';
|
455 |
+
$submit_lr_padding = '';
|
456 |
+
$hl_bg_color = '';
|
457 |
+
$field_input_size = '';
|
458 |
+
$box_border_color = '';
|
459 |
+
$section_bg_color = '';
|
460 |
+
$submit_button_height = '';
|
461 |
+
$submit_color = '';
|
462 |
+
$submit_bg_color = $primary_color;
|
463 |
+
$submit_border_color = $primary_color;
|
464 |
+
|
465 |
+
$submit_hover_color = '';
|
466 |
+
$submit_bg_hover_color = $primary_color;
|
467 |
+
$submit_border_hover_color = $primary_color;
|
468 |
+
|
469 |
+
$section_heading_color = '';
|
470 |
+
|
471 |
+
$is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
|
472 |
+
|
473 |
+
$button_font_family = '';
|
474 |
+
$button_font_weight = '';
|
475 |
+
$input_font_family = '';
|
476 |
+
$input_font_weight = '';
|
477 |
+
$heading_font_family = '';
|
478 |
+
$heading_font_weight = '';
|
479 |
+
$base_font_family = $base_font_family;
|
480 |
+
/*$base_font_weight = $base_font_weight;*/
|
481 |
+
|
482 |
+
if ( 'yes' == $is_advance_option ) {
|
483 |
+
|
484 |
+
/**
|
485 |
+
* Get Font Family and Font Weight weight values
|
486 |
+
*/
|
487 |
+
$section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
|
488 |
+
|
489 |
+
$heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
|
490 |
+
$heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
|
491 |
+
$section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
|
492 |
+
$button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
|
493 |
+
$button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
|
494 |
+
$input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
|
495 |
+
$input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
|
496 |
+
$field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
|
497 |
+
$field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
|
498 |
+
$field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
|
499 |
+
|
500 |
+
$field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
|
501 |
+
|
502 |
+
$field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
|
503 |
+
|
504 |
+
$field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
|
505 |
+
|
506 |
+
$field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
|
507 |
+
|
508 |
+
$field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
|
509 |
+
|
510 |
+
$submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
|
511 |
+
|
512 |
+
$submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
|
513 |
+
|
514 |
+
$submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
|
515 |
+
|
516 |
+
$submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
|
517 |
+
|
518 |
+
$submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
|
519 |
+
|
520 |
+
$submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
|
521 |
+
|
522 |
+
$submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
|
523 |
+
|
524 |
+
$submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
|
525 |
+
|
526 |
+
$hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
|
527 |
+
|
528 |
+
$box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
|
529 |
+
|
530 |
+
$submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
|
531 |
+
|
532 |
+
/**
|
533 |
+
* Get font values
|
534 |
+
*/
|
535 |
+
|
536 |
+
if ( 'custom' == $submit_button_height ) {
|
537 |
+
$submit_button_height = '38px';
|
538 |
+
}
|
539 |
+
|
540 |
+
if ( 'custom' == $field_input_size ) {
|
541 |
+
$field_input_size = '38px';
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
$output = "
|
546 |
+
.wcf-embed-checkout-form .wcf-checkout-header-image img{
|
547 |
+
width: {$header_logo_width}px;
|
548 |
+
}
|
549 |
+
.wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:after,
|
550 |
+
.wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:not(:checked):after,
|
551 |
+
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label:after,
|
552 |
+
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label:after {
|
553 |
+
background: {$primary_color};
|
554 |
+
}
|
555 |
+
|
556 |
+
.wcf-embed-checkout-form .woocommerce-checkout label{
|
557 |
+
color: {$field_label_color};
|
558 |
+
}
|
559 |
+
.wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
|
560 |
+
background-color: {$hl_bg_color};
|
561 |
+
font-family: {$input_font_family};
|
562 |
+
font-weight: {$input_font_weight};
|
563 |
+
}
|
564 |
+
|
565 |
+
.wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
|
566 |
+
.wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
|
567 |
+
.wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
|
568 |
+
{
|
569 |
+
border-color: {$hl_bg_color};
|
570 |
+
border-right-color: transparent;
|
571 |
+
border-left-color: transparent;
|
572 |
+
border-top-color: transparent;
|
573 |
+
position: absolute;
|
574 |
+
}
|
575 |
+
|
576 |
+
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
|
577 |
+
.wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
|
578 |
+
font-family: {$input_font_family};
|
579 |
+
font-weight: {$input_font_weight};
|
580 |
+
}
|
581 |
+
|
582 |
+
.wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
|
583 |
+
.wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
|
584 |
+
.wcf-embed-checkout-form .woocommerce form .form-row textarea,
|
585 |
+
.wcf-embed-checkout-form .select2-container--default .select2-selection--single {
|
586 |
+
color: {$field_color};
|
587 |
+
background: {$field_bg_color};
|
588 |
+
border-color: {$field_border_color};
|
589 |
+
padding-top: {$field_tb_padding}px;
|
590 |
+
padding-bottom: {$field_tb_padding}px;
|
591 |
+
padding-left: {$field_lr_padding}px;
|
592 |
+
padding-right: {$field_lr_padding}px;
|
593 |
+
min-height: {$field_input_size};
|
594 |
+
font-family: {$input_font_family};
|
595 |
+
font-weight: {$input_font_weight};
|
596 |
+
}
|
597 |
+
|
598 |
+
.wcf-embed-checkout-form .woocommerce .col2-set .col-1,
|
599 |
+
.wcf-embed-checkout-form .woocommerce .col2-set .col-2,
|
600 |
+
.wcf-embed-checkout-form .woocommerce-checkout .shop_table,
|
601 |
+
.wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
|
602 |
+
.wcf-embed-checkout-form .woocommerce-checkout #payment,
|
603 |
+
.wcf-embed-checkout-form .woocommerce form.checkout_coupon
|
604 |
+
{
|
605 |
+
background-color: {$section_bg_color};
|
606 |
+
border-color: {$box_border_color};
|
607 |
+
font-family: {$input_font_family};
|
608 |
+
font-weight: {$input_font_weight};
|
609 |
+
}
|
610 |
+
|
611 |
+
.woocommerce table.shop_table th{
|
612 |
+
color: {$field_label_color};
|
613 |
+
}
|
614 |
+
.wcf-embed-checkout-form .woocommerce .woocommerce-info,
|
615 |
+
.wcf-embed-checkout-form .woocommerce-message{
|
616 |
+
border-top-color: {$primary_color};
|
617 |
+
background-color: {$hl_bg_color};
|
618 |
+
}
|
619 |
+
.wcf-embed-checkout-form .woocommerce a{
|
620 |
+
color: {$primary_color};
|
621 |
+
}
|
622 |
+
.wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
|
623 |
+
color: {$field_color};
|
624 |
+
}
|
625 |
+
.wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
|
626 |
+
color: {$field_color};
|
627 |
+
}
|
628 |
+
.wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
|
629 |
+
color: {$field_color};
|
630 |
+
}
|
631 |
+
.wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
|
632 |
+
color: {$field_color};
|
633 |
+
}
|
634 |
+
.wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
|
635 |
+
color: {$field_color};
|
636 |
+
}
|
637 |
+
.wcf-embed-checkout-form .woocommerce form p.form-row label {
|
638 |
+
color: {$field_label_color};
|
639 |
+
font-family: {$input_font_family};
|
640 |
+
font-weight: {$input_font_weight};
|
641 |
+
}
|
642 |
+
.wcf-embed-checkout-form .woocommerce #order_review button {
|
643 |
+
color: {$submit_color};
|
644 |
+
background: {$submit_bg_color};
|
645 |
+
padding-top: {$submit_tb_padding}px;
|
646 |
+
padding-bottom: {$submit_tb_padding}px;
|
647 |
+
padding-left: {$submit_lr_padding}px;
|
648 |
+
padding-right: {$submit_lr_padding}px;
|
649 |
+
border-color: {$submit_border_color};
|
650 |
+
min-height: {$submit_button_height};
|
651 |
+
font-family: {$button_font_family};
|
652 |
+
font-weight: {$button_font_weight};
|
653 |
+
}
|
654 |
+
.wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
|
655 |
+
.wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
|
656 |
+
background: {$submit_bg_color};
|
657 |
+
border: 1px {$submit_border_color} solid;
|
658 |
+
color: {$submit_color};
|
659 |
+
min-height: {$submit_button_height};
|
660 |
+
font-family: {$button_font_family};
|
661 |
+
font-weight: {$button_font_weight};
|
662 |
+
}
|
663 |
+
.wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
|
664 |
+
.wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
|
665 |
+
.wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
|
666 |
+
.wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
|
667 |
+
color: {$submit_hover_color};
|
668 |
+
background-color: {$submit_bg_hover_color};
|
669 |
+
border-color: {$submit_border_hover_color};
|
670 |
+
}
|
671 |
+
.wcf-embed-checkout-form .woocommerce h3,
|
672 |
+
.wcf-embed-checkout-form .woocommerce h3 span,
|
673 |
+
.wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
|
674 |
+
color: {$section_heading_color};
|
675 |
+
font-family: {$heading_font_family};
|
676 |
+
font-weight: {$heading_font_weight};
|
677 |
+
}
|
678 |
+
.wcf-embed-checkout-form .woocommerce-info::before,
|
679 |
+
.wcf-embed-checkout-form .woocommerce-message::before{
|
680 |
+
color: {$primary_color};
|
681 |
+
}
|
682 |
+
.wcf-embed-checkout-form{
|
683 |
+
font-family: {$base_font_family};
|
684 |
+
}";
|
685 |
+
|
686 |
+
return $output;
|
687 |
+
}
|
688 |
+
|
689 |
+
/**
|
690 |
+
* Get ajax end points.
|
691 |
+
*
|
692 |
+
* @param string $endpoint_url end point URL.
|
693 |
+
* @return string
|
694 |
+
*/
|
695 |
+
function get_ajax_endpoint( $endpoint_url ) {
|
696 |
+
|
697 |
+
global $post;
|
698 |
+
|
699 |
+
if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
|
700 |
+
|
701 |
+
if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
|
702 |
+
|
703 |
+
if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
|
704 |
+
|
705 |
+
$query_args = array(
|
706 |
+
'wc-ajax' => '%%endpoint%%',
|
707 |
+
);
|
708 |
+
|
709 |
+
$uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
|
710 |
+
$uri = $uri[0];
|
711 |
+
|
712 |
+
$endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
|
713 |
+
}
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
return $endpoint_url;
|
718 |
+
}
|
719 |
+
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Save checkout fields.
|
723 |
+
*
|
724 |
+
* @param int $order_id order id.
|
725 |
+
* @param array $posted posted data.
|
726 |
+
* @return void
|
727 |
+
*/
|
728 |
+
function save_checkout_fields( $order_id, $posted ) {
|
729 |
+
|
730 |
+
if ( isset( $_POST['_wcf_checkout_id'] ) ) {
|
731 |
+
|
732 |
+
$checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
|
733 |
+
|
734 |
+
update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
|
735 |
+
|
736 |
+
/*
|
737 |
+
Custom Field To Do
|
738 |
+
$custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
|
739 |
+
|
740 |
+
if ( 'yes' === $custom_fields ) {
|
741 |
+
|
742 |
+
$billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
|
743 |
+
|
744 |
+
foreach ( $billing_fields as $field => $data ) {
|
745 |
+
|
746 |
+
if ( isset( $data['custom'] ) && $data['custom'] ) {
|
747 |
+
|
748 |
+
if ( isset( $_POST[ $field ] ) ) {
|
749 |
+
update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
|
750 |
+
}
|
751 |
+
}
|
752 |
+
}
|
753 |
+
|
754 |
+
$shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
|
755 |
+
|
756 |
+
foreach ( $shipping_fields as $field => $data ) {
|
757 |
+
|
758 |
+
if ( isset( $data['custom'] ) && $data['custom'] ) {
|
759 |
+
|
760 |
+
if ( isset( $_POST[ $field ] ) ) {
|
761 |
+
update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
|
762 |
+
}
|
763 |
+
}
|
764 |
+
}
|
765 |
+
}
|
766 |
+
*/
|
767 |
+
if ( isset( $_POST['_wcf_flow_id'] ) ) {
|
768 |
+
|
769 |
+
$checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
|
770 |
+
|
771 |
+
update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
|
772 |
+
}
|
773 |
+
}
|
774 |
+
|
775 |
+
}
|
776 |
+
|
777 |
+
/**
|
778 |
+
* Enable Logo In Header Of Checkout Page
|
779 |
+
*
|
780 |
+
* @return void
|
781 |
+
*/
|
782 |
+
function enable_logo_in_header() {
|
783 |
+
global $post;
|
784 |
+
|
785 |
+
if ( _is_wcf_checkout_type() ) {
|
786 |
+
$checkout_id = $post->ID;
|
787 |
+
} else {
|
788 |
+
$checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
|
789 |
+
}
|
790 |
+
|
791 |
+
$header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
|
792 |
+
$add_image_markup = '';
|
793 |
+
|
794 |
+
if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
|
795 |
+
$add_image_markup = '<div class="wcf-checkout-header-image">';
|
796 |
+
$add_image_markup .= '<img src="' . $header_logo_image . '" />';
|
797 |
+
$add_image_markup .= '</div>';
|
798 |
+
}
|
799 |
+
|
800 |
+
echo $add_image_markup;
|
801 |
+
}
|
802 |
+
|
803 |
+
/**
|
804 |
+
* Add text to the bootom of the checkout page.
|
805 |
+
*
|
806 |
+
* @return void
|
807 |
+
*/
|
808 |
+
function show_cartflows_copyright_message() {
|
809 |
+
$output_string = '';
|
810 |
+
|
811 |
+
$output_string .= '<div class="wcf-footer-primary">';
|
812 |
+
$output_string .= '<div class="wcf-footer-content">';
|
813 |
+
$output_string .= '<p class="wcf-footer-message">';
|
814 |
+
$output_string .= 'Checkout powered by CartFlows';
|
815 |
+
$output_string .= '</p>';
|
816 |
+
$output_string .= '</div>';
|
817 |
+
$output_string .= '</div>';
|
818 |
+
|
819 |
+
echo $output_string;
|
820 |
+
}
|
821 |
+
|
822 |
+
/**
|
823 |
+
* Redirect users to our checkout if hidden param
|
824 |
+
*
|
825 |
+
* @param string $redirect redirect url.
|
826 |
+
* @param object $user user.
|
827 |
+
* @return string
|
828 |
+
*/
|
829 |
+
function after_login_redirect( $redirect, $user ) {
|
830 |
+
|
831 |
+
if ( isset( $_POST['_wcf_checkout_id'] ) ) {
|
832 |
+
|
833 |
+
$checkout_id = intval( $_POST['_wcf_checkout_id'] );
|
834 |
+
|
835 |
+
$redirect = get_permalink( $checkout_id );
|
836 |
+
}
|
837 |
+
|
838 |
+
return $redirect;
|
839 |
+
}
|
840 |
+
|
841 |
+
/**
|
842 |
+
* Display coupon code field after review order fields.
|
843 |
+
*/
|
844 |
+
function display_custom_coupon_field() {
|
845 |
+
|
846 |
+
$coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
|
847 |
+
|
848 |
+
if ( ! $coupon_enabled ) {
|
849 |
+
return;
|
850 |
+
}
|
851 |
+
|
852 |
+
ob_start();
|
853 |
+
|
854 |
+
?>
|
855 |
+
<div class="wcf-custom-coupon-field">
|
856 |
+
<div class="wcf-coupon-col-1">
|
857 |
+
<span>
|
858 |
+
<input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
|
859 |
+
</span>
|
860 |
+
</div>
|
861 |
+
<div class="wcf-coupon-col-2">
|
862 |
+
<span>
|
863 |
+
<button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
|
864 |
+
</span>
|
865 |
+
</div>
|
866 |
+
</div>
|
867 |
+
|
868 |
+
<?php
|
869 |
+
|
870 |
+
echo ob_get_clean();
|
871 |
+
}
|
872 |
+
|
873 |
+
/**
|
874 |
+
* Apply coupon on submit of custom coupon form.
|
875 |
+
*/
|
876 |
+
function apply_coupon() {
|
877 |
+
|
878 |
+
check_ajax_referer( 'cf-apply-coupon', 'security' );
|
879 |
+
|
880 |
+
$result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
|
881 |
+
|
882 |
+
echo json_encode( $result );
|
883 |
+
die();
|
884 |
+
}
|
885 |
+
|
886 |
+
/**
|
887 |
+
* Added ajax nonce to localize variable.
|
888 |
+
*
|
889 |
+
* @param array $vars localize variables.
|
890 |
+
*/
|
891 |
+
function add_localize_vars( $vars ) {
|
892 |
+
|
893 |
+
$vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
|
894 |
+
|
895 |
+
return $vars;
|
896 |
+
}
|
897 |
+
|
898 |
+
/**
|
899 |
+
* Add custom class to the fields to change the UI to three column.
|
900 |
+
*
|
901 |
+
* @param array $fields fields.
|
902 |
+
*/
|
903 |
+
function add_three_column_layout_fields( $fields ) {
|
904 |
+
|
905 |
+
if ( empty( $fields['billing']['billing_address_2'] ) ) {
|
906 |
+
|
907 |
+
if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
|
908 |
+
$fields['billing']['billing_address_1']['class'][] = 'form-row-full';
|
909 |
+
}
|
910 |
+
}
|
911 |
+
|
912 |
+
if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
|
913 |
+
|
914 |
+
if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
|
915 |
+
$fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
|
916 |
+
}
|
917 |
+
}
|
918 |
+
|
919 |
+
if ( isset( $fields['billing']['billing_city'] ) &&
|
920 |
+
isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
|
921 |
+
|
922 |
+
$fields['billing']['billing_city']['class'] = array( 'wcf-form-col-3' );
|
923 |
+
$fields['billing']['billing_state']['class'] = array( 'wcf-form-col-3' );
|
924 |
+
$fields['billing']['billing_postcode']['class'] = array( 'wcf-form-col-3' );
|
925 |
+
}
|
926 |
+
|
927 |
+
if ( isset( $fields['shipping']['shipping_city'] ) &&
|
928 |
+
isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
|
929 |
+
|
930 |
+
$fields['shipping']['shipping_city']['class'] = array( 'wcf-form-col-3' );
|
931 |
+
$fields['shipping']['shipping_state']['class'] = array( 'wcf-form-col-3' );
|
932 |
+
$fields['shipping']['shipping_postcode']['class'] = array( 'wcf-form-col-3' );
|
933 |
+
}
|
934 |
+
|
935 |
+
return $fields;
|
936 |
+
}
|
937 |
+
}
|
938 |
+
|
939 |
+
/**
|
940 |
+
* Kicking this off by calling 'get_instance()' method
|
941 |
+
*/
|
942 |
+
Cartflows_Checkout_Markup::get_instance();
|
modules/checkout/classes/class-cartflows-checkout-meta.php
CHANGED
@@ -1,759 +1,759 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Checkout post meta
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Meta Boxes setup
|
10 |
-
*/
|
11 |
-
class Cartflows_Checkout_Meta extends Cartflows_Meta {
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Instance
|
15 |
-
*
|
16 |
-
* @var $instance
|
17 |
-
*/
|
18 |
-
private static $instance;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Meta Option
|
22 |
-
*
|
23 |
-
* @var $meta_option
|
24 |
-
*/
|
25 |
-
private static $meta_option = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Initiator
|
29 |
-
*/
|
30 |
-
public static function get_instance() {
|
31 |
-
if ( ! isset( self::$instance ) ) {
|
32 |
-
self::$instance = new self;
|
33 |
-
}
|
34 |
-
|
35 |
-
return self::$instance;
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Constructor
|
40 |
-
*/
|
41 |
-
public function __construct() {
|
42 |
-
|
43 |
-
/* Init Metabox */
|
44 |
-
add_action( 'load-post.php', array( $this, 'init_metabox' ) );
|
45 |
-
add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
|
46 |
-
}
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Init Metabox
|
50 |
-
*/
|
51 |
-
public function init_metabox() {
|
52 |
-
|
53 |
-
add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
|
54 |
-
add_action( 'save_post', array( $this, 'save_meta_box' ) );
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Setup Metabox
|
59 |
-
*/
|
60 |
-
function setup_meta_box() {
|
61 |
-
|
62 |
-
// Get all posts.
|
63 |
-
$post_types = get_post_types();
|
64 |
-
|
65 |
-
if ( _is_wcf_checkout_type() ) {
|
66 |
-
add_meta_box(
|
67 |
-
'wcf-checkout-settings', // Id.
|
68 |
-
__( 'Checkout Layout', 'cartflows' ), // Title.
|
69 |
-
array( $this, 'markup_meta_box' ), // Callback.
|
70 |
-
wcf()->utils->get_step_post_type(), // Post_type.
|
71 |
-
'normal', // Context.
|
72 |
-
'high' // Priority.
|
73 |
-
);
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Metabox Markup
|
79 |
-
*
|
80 |
-
* @param object $post Post object.
|
81 |
-
* @return void
|
82 |
-
*/
|
83 |
-
function markup_meta_box( $post ) {
|
84 |
-
|
85 |
-
wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
|
86 |
-
|
87 |
-
$stored = get_post_meta( $post->ID );
|
88 |
-
|
89 |
-
$checkout_meta = self::get_meta_option( $post->ID );
|
90 |
-
|
91 |
-
// Set stored and override defaults.
|
92 |
-
foreach ( $stored as $key => $value ) {
|
93 |
-
if ( array_key_exists( $key, $checkout_meta ) ) {
|
94 |
-
self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
|
95 |
-
} else {
|
96 |
-
self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
|
97 |
-
}
|
98 |
-
}
|
99 |
-
|
100 |
-
// Get defaults.
|
101 |
-
$meta = self::get_meta_option( $post->ID );
|
102 |
-
$checkout_data = array();
|
103 |
-
|
104 |
-
foreach ( $meta as $key => $value ) {
|
105 |
-
|
106 |
-
$checkout_data[ $key ] = $meta[ $key ]['default'];
|
107 |
-
}
|
108 |
-
|
109 |
-
/*
|
110 |
-
$billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
|
111 |
-
|
112 |
-
foreach ( $billing_fields as $key => $value ) {
|
113 |
-
|
114 |
-
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
115 |
-
}
|
116 |
-
|
117 |
-
$shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
|
118 |
-
|
119 |
-
foreach ( $shipping_fields as $key => $value ) {
|
120 |
-
|
121 |
-
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
122 |
-
}
|
123 |
-
|
124 |
-
$additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
|
125 |
-
|
126 |
-
foreach ( $additional_fields as $key => $value ) {
|
127 |
-
|
128 |
-
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
129 |
-
}
|
130 |
-
*/
|
131 |
-
|
132 |
-
do_action( 'wcf_checkout_settings_markup_before' );
|
133 |
-
$this->tabs_markup( $checkout_data, $post->ID );
|
134 |
-
do_action( 'wcf_checkout_settings_markup_after' );
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Page Header Tabs
|
139 |
-
*
|
140 |
-
* @param array $options options.
|
141 |
-
* @param int $post_id post ID.
|
142 |
-
*/
|
143 |
-
function tabs_markup( $options, $post_id ) {
|
144 |
-
|
145 |
-
$active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
|
146 |
-
|
147 |
-
if ( empty( $active_tab ) ) {
|
148 |
-
$active_tab = 'wcf-checkout-shortcodes';
|
149 |
-
}
|
150 |
-
|
151 |
-
$tabs = array(
|
152 |
-
array(
|
153 |
-
'title' => __( 'Shortcodes', 'cartflows' ),
|
154 |
-
'id' => 'wcf-checkout-shortcodes',
|
155 |
-
'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
156 |
-
'icon' => 'dashicons-editor-code',
|
157 |
-
'help_text' => 'Help Helpppp...',
|
158 |
-
),
|
159 |
-
array(
|
160 |
-
'title' => __( 'Select Product', 'cartflows' ),
|
161 |
-
'id' => 'wcf-checkout-general',
|
162 |
-
'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
163 |
-
'icon' => 'dashicons-info',
|
164 |
-
),
|
165 |
-
array(
|
166 |
-
'title' => __( 'Order Bump', 'cartflows' ),
|
167 |
-
'id' => 'wcf-product-order-bump',
|
168 |
-
'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
169 |
-
'icon' => 'dashicons-cart',
|
170 |
-
),
|
171 |
-
array(
|
172 |
-
'title' => __( 'Checkout Design', 'cartflows' ),
|
173 |
-
'id' => 'wcf-checkout-style',
|
174 |
-
'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
175 |
-
'icon' => 'dashicons-admin-customizer',
|
176 |
-
),
|
177 |
-
array(
|
178 |
-
'title' => __( 'Checkout Fields', 'cartflows' ),
|
179 |
-
'id' => 'wcf-checkout-custom-fields',
|
180 |
-
'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
181 |
-
'icon' => 'dashicons-welcome-widgets-menus',
|
182 |
-
),
|
183 |
-
array(
|
184 |
-
'title' => __( 'Logo ( Optional )', 'cartflows' ),
|
185 |
-
'id' => 'wcf-checkout-header',
|
186 |
-
'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
187 |
-
'icon' => 'dashicons-format-image',
|
188 |
-
),
|
189 |
-
);
|
190 |
-
|
191 |
-
?>
|
192 |
-
<div class="wcf-checkout-table wcf-metabox-wrap widefat">
|
193 |
-
<div class="wcf-table-container">
|
194 |
-
<div class="wcf-column-left">
|
195 |
-
<div class="wcf-tab-wrapper">
|
196 |
-
|
197 |
-
<?php foreach ( $tabs as $key => $tab ) { ?>
|
198 |
-
<div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
|
199 |
-
<span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
|
200 |
-
<span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
|
201 |
-
</div>
|
202 |
-
<?php } ?>
|
203 |
-
|
204 |
-
<input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
|
205 |
-
</div>
|
206 |
-
</div>
|
207 |
-
<div class="wcf-column-right">
|
208 |
-
<?php $this->tab_shortcodes( $options, $post_id ); ?>
|
209 |
-
<?php $this->tab_general( $options, $post_id ); ?>
|
210 |
-
<?php $this->tab_style( $options, $post_id ); ?>
|
211 |
-
<?php $this->tab_product_bump( $options, $post_id ); ?>
|
212 |
-
<?php $this->tab_custom_fields( $options, $post_id ); ?>
|
213 |
-
<?php $this->tab_header_content( $options, $post_id ); ?>
|
214 |
-
<?php $this->right_column_footer( $options, $post_id ); ?>
|
215 |
-
</div>
|
216 |
-
</div>
|
217 |
-
</div>
|
218 |
-
|
219 |
-
<?php
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Shortcodes tab
|
224 |
-
*
|
225 |
-
* @param array $options options.
|
226 |
-
* @param int $post_id post ID.
|
227 |
-
*/
|
228 |
-
function tab_shortcodes( $options, $post_id ) {
|
229 |
-
?>
|
230 |
-
<div class="wcf-checkout-shortcodes wcf-tab-content widefat">
|
231 |
-
|
232 |
-
<?php
|
233 |
-
|
234 |
-
echo wcf()->meta->get_shortcode_field(
|
235 |
-
array(
|
236 |
-
'label' => 'Checkout Page',
|
237 |
-
'name' => 'wcf-checkout-shortcode',
|
238 |
-
'content' => '[cartflows_checkout]',
|
239 |
-
'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
|
240 |
-
)
|
241 |
-
);
|
242 |
-
?>
|
243 |
-
</div>
|
244 |
-
<?php
|
245 |
-
}
|
246 |
-
|
247 |
-
|
248 |
-
/**
|
249 |
-
* General tab
|
250 |
-
*
|
251 |
-
* @param array $options options.
|
252 |
-
* @param int $post_id post ID.
|
253 |
-
*/
|
254 |
-
function tab_general( $options, $post_id ) {
|
255 |
-
?>
|
256 |
-
<div class="wcf-checkout-general wcf-tab-content widefat">
|
257 |
-
|
258 |
-
<?php
|
259 |
-
|
260 |
-
echo wcf()->meta->get_product_selection_repeater(
|
261 |
-
array(
|
262 |
-
'name' => 'wcf-checkout-products',
|
263 |
-
'value' => $options['wcf-checkout-products'],
|
264 |
-
'allow_clear' => true,
|
265 |
-
)
|
266 |
-
);
|
267 |
-
|
268 |
-
do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
|
269 |
-
|
270 |
-
?>
|
271 |
-
</div>
|
272 |
-
<?php
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Product bump tab
|
277 |
-
*
|
278 |
-
* @param array $options options.
|
279 |
-
* @param int $post_id post ID.
|
280 |
-
*/
|
281 |
-
function tab_product_bump( $options, $post_id ) {
|
282 |
-
?>
|
283 |
-
<div class="wcf-product-order-bump wcf-tab-content widefat">
|
284 |
-
<?php
|
285 |
-
if ( ! _is_cartflows_pro() ) {
|
286 |
-
|
287 |
-
echo wcf()->meta->get_description_field(
|
288 |
-
array(
|
289 |
-
'name' => 'wcf-upgrade-to-pro',
|
290 |
-
/* translators: %s: link */
|
291 |
-
'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
|
292 |
-
)
|
293 |
-
);
|
294 |
-
}
|
295 |
-
?>
|
296 |
-
|
297 |
-
<?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
|
298 |
-
</div>
|
299 |
-
<?php
|
300 |
-
}
|
301 |
-
/**
|
302 |
-
* Tab custom fields
|
303 |
-
*
|
304 |
-
* @param array $options options.
|
305 |
-
* @param int $post_id post ID.
|
306 |
-
*/
|
307 |
-
function tab_custom_fields( $options, $post_id ) {
|
308 |
-
?>
|
309 |
-
<div class="wcf-checkout-custom-fields wcf-tab-content widefat">
|
310 |
-
<?php
|
311 |
-
/* Custom Checkout Fields Section */
|
312 |
-
|
313 |
-
if ( ! _is_cartflows_pro() ) {
|
314 |
-
|
315 |
-
echo wcf()->meta->get_description_field(
|
316 |
-
array(
|
317 |
-
'name' => 'wcf-upgrade-to-pro',
|
318 |
-
/* translators: %s: link */
|
319 |
-
'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
|
320 |
-
)
|
321 |
-
);
|
322 |
-
}
|
323 |
-
?>
|
324 |
-
<?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
|
325 |
-
</div>
|
326 |
-
<?php
|
327 |
-
}
|
328 |
-
|
329 |
-
/**
|
330 |
-
* Tab style
|
331 |
-
*
|
332 |
-
* @param array $options options.
|
333 |
-
* @param int $post_id post ID.
|
334 |
-
*/
|
335 |
-
function tab_style( $options, $post_id ) {
|
336 |
-
?>
|
337 |
-
|
338 |
-
<div class="wcf-checkout-style wcf-tab-content widefat">
|
339 |
-
<div class="wcf-cs-fields">
|
340 |
-
<div class="wcf-cs-checkbox-field">
|
341 |
-
<?php
|
342 |
-
|
343 |
-
$layout_pro_option = array();
|
344 |
-
|
345 |
-
if ( ! _is_cartflows_pro() ) {
|
346 |
-
$layout_pro_option = array(
|
347 |
-
'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
|
348 |
-
);
|
349 |
-
}
|
350 |
-
|
351 |
-
echo wcf()->meta->get_select_field(
|
352 |
-
array(
|
353 |
-
'label' => __( 'Checkout Skin', 'cartflows' ),
|
354 |
-
'name' => 'wcf-checkout-layout',
|
355 |
-
'value' => $options['wcf-checkout-layout'],
|
356 |
-
'options' => array(
|
357 |
-
'one-column' => __( 'One Column', 'cartflows' ),
|
358 |
-
'two-column' => __( 'Two Column', 'cartflows' ),
|
359 |
-
),
|
360 |
-
'pro-options' => $layout_pro_option,
|
361 |
-
|
362 |
-
)
|
363 |
-
);
|
364 |
-
|
365 |
-
echo wcf()->meta->get_color_picker_field(
|
366 |
-
array(
|
367 |
-
'label' => __( 'Primary Color', 'cartflows' ),
|
368 |
-
'name' => 'wcf-primary-color',
|
369 |
-
'value' => $options['wcf-primary-color'],
|
370 |
-
)
|
371 |
-
);
|
372 |
-
|
373 |
-
echo wcf()->meta->get_font_family_field(
|
374 |
-
array(
|
375 |
-
'for' => 'wcf-base',
|
376 |
-
'label' => __( 'Font Family', 'cartflows' ),
|
377 |
-
'name' => 'wcf-base-font-family',
|
378 |
-
'value' => $options['wcf-base-font-family'],
|
379 |
-
)
|
380 |
-
);
|
381 |
-
|
382 |
-
echo wcf()->meta->get_checkbox_field(
|
383 |
-
array(
|
384 |
-
'label' => __( 'Advance Options', 'cartflows' ),
|
385 |
-
'name' => 'wcf-advance-options-fields',
|
386 |
-
'value' => $options['wcf-advance-options-fields'],
|
387 |
-
'after' => 'Enable',
|
388 |
-
)
|
389 |
-
);
|
390 |
-
?>
|
391 |
-
</div>
|
392 |
-
<div class="wcf-cs-fields-options">
|
393 |
-
<?php
|
394 |
-
echo wcf()->meta->get_section(
|
395 |
-
array(
|
396 |
-
'label' => __( 'Heading', 'cartflows' ),
|
397 |
-
)
|
398 |
-
);
|
399 |
-
|
400 |
-
echo wcf()->meta->get_color_picker_field(
|
401 |
-
array(
|
402 |
-
'label' => __( 'Heading Color', 'cartflows' ),
|
403 |
-
'name' => 'wcf-heading-color',
|
404 |
-
'value' => $options['wcf-heading-color'],
|
405 |
-
)
|
406 |
-
);
|
407 |
-
|
408 |
-
echo wcf()->meta->get_font_family_field(
|
409 |
-
array(
|
410 |
-
'for' => 'wcf-heading',
|
411 |
-
'label' => __( 'Font Family', 'cartflows' ),
|
412 |
-
'name' => 'wcf-heading-font-family',
|
413 |
-
'value' => $options['wcf-heading-font-family'],
|
414 |
-
)
|
415 |
-
);
|
416 |
-
|
417 |
-
echo wcf()->meta->get_font_weight_field(
|
418 |
-
array(
|
419 |
-
'for' => 'wcf-heading',
|
420 |
-
'label' => __( 'Font Weight', 'cartflows' ),
|
421 |
-
'name' => 'wcf-heading-font-weight',
|
422 |
-
'value' => $options['wcf-heading-font-weight'],
|
423 |
-
)
|
424 |
-
);
|
425 |
-
|
426 |
-
echo wcf()->meta->get_section(
|
427 |
-
array(
|
428 |
-
'label' => __( 'Input Fields', 'cartflows' ),
|
429 |
-
)
|
430 |
-
);
|
431 |
-
|
432 |
-
$fields_skin_pro_option = array();
|
433 |
-
|
434 |
-
if ( ! _is_cartflows_pro() ) {
|
435 |
-
$fields_skin_pro_option = array(
|
436 |
-
'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
|
437 |
-
);
|
438 |
-
}
|
439 |
-
|
440 |
-
echo wcf()->meta->get_select_field(
|
441 |
-
array(
|
442 |
-
'label' => __( 'Style', 'cartflows' ),
|
443 |
-
'name' => 'wcf-fields-skins',
|
444 |
-
'value' => $options['wcf-fields-skins'],
|
445 |
-
'options' => array(
|
446 |
-
'default' => __( 'Default', 'cartflows' ),
|
447 |
-
'style-one' => __( 'Floating Labels', 'cartflows' ),
|
448 |
-
),
|
449 |
-
'pro-options' => $fields_skin_pro_option,
|
450 |
-
|
451 |
-
)
|
452 |
-
);
|
453 |
-
|
454 |
-
echo wcf()->meta->get_font_family_field(
|
455 |
-
array(
|
456 |
-
'for' => 'wcf-input',
|
457 |
-
'label' => __( 'Font Family', 'cartflows' ),
|
458 |
-
'name' => 'wcf-input-font-family',
|
459 |
-
'value' => $options['wcf-input-font-family'],
|
460 |
-
)
|
461 |
-
);
|
462 |
-
|
463 |
-
echo wcf()->meta->get_font_weight_field(
|
464 |
-
array(
|
465 |
-
'for' => 'wcf-input',
|
466 |
-
'label' => __( 'Font Weight', 'cartflows' ),
|
467 |
-
'name' => 'wcf-input-font-weight',
|
468 |
-
'value' => $options['wcf-input-font-weight'],
|
469 |
-
)
|
470 |
-
);
|
471 |
-
|
472 |
-
echo wcf()->meta->get_select_field(
|
473 |
-
array(
|
474 |
-
'label' => __( 'Size', 'cartflows' ),
|
475 |
-
'name' => 'wcf-input-field-size',
|
476 |
-
'value' => $options['wcf-input-field-size'],
|
477 |
-
'options' => array(
|
478 |
-
'33px' => __( 'Extra Small', 'cartflows' ),
|
479 |
-
'38px' => __( 'Small', 'cartflows' ),
|
480 |
-
'44px' => __( 'Medium', 'cartflows' ),
|
481 |
-
'58px' => __( 'Large', 'cartflows' ),
|
482 |
-
'68px' => __( 'Extra Large', 'cartflows' ),
|
483 |
-
'custom' => __( 'Custom', 'cartflows' ),
|
484 |
-
),
|
485 |
-
)
|
486 |
-
);
|
487 |
-
|
488 |
-
echo wcf()->meta->get_number_field(
|
489 |
-
array(
|
490 |
-
'label' => __( 'Top Bottom Spacing', 'cartflows' ),
|
491 |
-
'name' => 'wcf-field-tb-padding',
|
492 |
-
'value' => $options['wcf-field-tb-padding'],
|
493 |
-
)
|
494 |
-
);
|
495 |
-
|
496 |
-
echo wcf()->meta->get_number_field(
|
497 |
-
array(
|
498 |
-
'label' => __( 'Left Right Spacing', 'cartflows' ),
|
499 |
-
'name' => 'wcf-field-lr-padding',
|
500 |
-
'value' => $options['wcf-field-lr-padding'],
|
501 |
-
)
|
502 |
-
);
|
503 |
-
|
504 |
-
echo wcf()->meta->get_color_picker_field(
|
505 |
-
array(
|
506 |
-
'label' => __( 'Text / Placeholder Color', 'cartflows' ),
|
507 |
-
'name' => 'wcf-field-color',
|
508 |
-
'value' => $options['wcf-field-color'],
|
509 |
-
)
|
510 |
-
);
|
511 |
-
|
512 |
-
echo wcf()->meta->get_color_picker_field(
|
513 |
-
array(
|
514 |
-
'label' => __( 'Background Color', 'cartflows' ),
|
515 |
-
'name' => 'wcf-field-bg-color',
|
516 |
-
'value' => $options['wcf-field-bg-color'],
|
517 |
-
)
|
518 |
-
);
|
519 |
-
|
520 |
-
echo wcf()->meta->get_color_picker_field(
|
521 |
-
array(
|
522 |
-
'label' => __( 'Border Color', 'cartflows' ),
|
523 |
-
'name' => 'wcf-field-border-color',
|
524 |
-
'value' => $options['wcf-field-border-color'],
|
525 |
-
)
|
526 |
-
);
|
527 |
-
echo wcf()->meta->get_color_picker_field(
|
528 |
-
array(
|
529 |
-
'label' => __( 'Label Color', 'cartflows' ),
|
530 |
-
'name' => 'wcf-field-label-color',
|
531 |
-
'value' => $options['wcf-field-label-color'],
|
532 |
-
)
|
533 |
-
);
|
534 |
-
|
535 |
-
?>
|
536 |
-
</div>
|
537 |
-
<div class="wcf-cs-button-options">
|
538 |
-
<?php
|
539 |
-
|
540 |
-
echo wcf()->meta->get_section(
|
541 |
-
array(
|
542 |
-
'label' => __( 'Buttons', 'cartflows' ),
|
543 |
-
)
|
544 |
-
);
|
545 |
-
|
546 |
-
echo wcf()->meta->get_font_family_field(
|
547 |
-
array(
|
548 |
-
'for' => 'wcf-button',
|
549 |
-
'label' => __( 'Font Family', 'cartflows' ),
|
550 |
-
'name' => 'wcf-button-font-family',
|
551 |
-
'value' => $options['wcf-button-font-family'],
|
552 |
-
)
|
553 |
-
);
|
554 |
-
|
555 |
-
echo wcf()->meta->get_font_weight_field(
|
556 |
-
array(
|
557 |
-
'for' => 'wcf-button',
|
558 |
-
'label' => __( 'Font Weight', 'cartflows' ),
|
559 |
-
'name' => 'wcf-button-font-weight',
|
560 |
-
'value' => $options['wcf-button-font-weight'],
|
561 |
-
)
|
562 |
-
);
|
563 |
-
|
564 |
-
echo wcf()->meta->get_select_field(
|
565 |
-
array(
|
566 |
-
'label' => __( 'Size', 'cartflows' ),
|
567 |
-
'name' => 'wcf-input-button-size',
|
568 |
-
'value' => $options['wcf-input-button-size'],
|
569 |
-
'options' => array(
|
570 |
-
'33px' => __( 'Extra Small', 'cartflows' ),
|
571 |
-
'38px' => __( 'Small', 'cartflows' ),
|
572 |
-
'44px' => __( 'Medium', 'cartflows' ),
|
573 |
-
'58px' => __( 'Large', 'cartflows' ),
|
574 |
-
'68px' => __( 'Extra Large', 'cartflows' ),
|
575 |
-
'custom' => __( 'Custom', 'cartflows' ),
|
576 |
-
),
|
577 |
-
)
|
578 |
-
);
|
579 |
-
|
580 |
-
echo wcf()->meta->get_number_field(
|
581 |
-
array(
|
582 |
-
'label' => __( 'Top Bottom Spacing', 'cartflows' ),
|
583 |
-
'name' => 'wcf-submit-tb-padding',
|
584 |
-
'value' => $options['wcf-submit-tb-padding'],
|
585 |
-
)
|
586 |
-
);
|
587 |
-
|
588 |
-
echo wcf()->meta->get_number_field(
|
589 |
-
array(
|
590 |
-
'label' => __( 'Left Right Spacing', 'cartflows' ),
|
591 |
-
'name' => 'wcf-submit-lr-padding',
|
592 |
-
'value' => $options['wcf-submit-lr-padding'],
|
593 |
-
)
|
594 |
-
);
|
595 |
-
|
596 |
-
echo wcf()->meta->get_color_picker_field(
|
597 |
-
array(
|
598 |
-
'label' => __( 'Text Color', 'cartflows' ),
|
599 |
-
'name' => 'wcf-submit-color',
|
600 |
-
'value' => $options['wcf-submit-color'],
|
601 |
-
)
|
602 |
-
);
|
603 |
-
|
604 |
-
echo wcf()->meta->get_color_picker_field(
|
605 |
-
array(
|
606 |
-
'label' => __( 'Text Hover Color', 'cartflows' ),
|
607 |
-
'name' => 'wcf-submit-hover-color',
|
608 |
-
'value' => $options['wcf-submit-hover-color'],
|
609 |
-
)
|
610 |
-
);
|
611 |
-
|
612 |
-
echo wcf()->meta->get_color_picker_field(
|
613 |
-
array(
|
614 |
-
'label' => __( 'Background Color', 'cartflows' ),
|
615 |
-
'name' => 'wcf-submit-bg-color',
|
616 |
-
'value' => $options['wcf-submit-bg-color'],
|
617 |
-
)
|
618 |
-
);
|
619 |
-
|
620 |
-
echo wcf()->meta->get_color_picker_field(
|
621 |
-
array(
|
622 |
-
'label' => __( 'Background Hover Color', 'cartflows' ),
|
623 |
-
'name' => 'wcf-submit-bg-hover-color',
|
624 |
-
'value' => $options['wcf-submit-bg-hover-color'],
|
625 |
-
)
|
626 |
-
);
|
627 |
-
|
628 |
-
echo wcf()->meta->get_color_picker_field(
|
629 |
-
array(
|
630 |
-
'label' => __( 'Border Color', 'cartflows' ),
|
631 |
-
'name' => 'wcf-submit-border-color',
|
632 |
-
'value' => $options['wcf-submit-border-color'],
|
633 |
-
)
|
634 |
-
);
|
635 |
-
|
636 |
-
echo wcf()->meta->get_color_picker_field(
|
637 |
-
array(
|
638 |
-
'label' => __( 'Border Hover Color', 'cartflows' ),
|
639 |
-
'name' => 'wcf-submit-border-hover-color',
|
640 |
-
'value' => $options['wcf-submit-border-hover-color'],
|
641 |
-
)
|
642 |
-
);
|
643 |
-
|
644 |
-
?>
|
645 |
-
</div>
|
646 |
-
<div class="wcf-cs-section-options">
|
647 |
-
<?php
|
648 |
-
|
649 |
-
echo wcf()->meta->get_section(
|
650 |
-
array(
|
651 |
-
'label' => __( 'Sections', 'cartflows' ),
|
652 |
-
)
|
653 |
-
);
|
654 |
-
|
655 |
-
echo wcf()->meta->get_color_picker_field(
|
656 |
-
array(
|
657 |
-
'label' => __( 'Highlight Area Background Color', 'cartflows' ),
|
658 |
-
'name' => 'wcf-hl-bg-color',
|
659 |
-
'value' => $options['wcf-hl-bg-color'],
|
660 |
-
)
|
661 |
-
);
|
662 |
-
|
663 |
-
echo wcf()->meta->get_hidden_field(
|
664 |
-
array(
|
665 |
-
'name' => 'wcf-field-google-font-url',
|
666 |
-
'value' => $options['wcf-field-google-font-url'],
|
667 |
-
)
|
668 |
-
);
|
669 |
-
?>
|
670 |
-
</div>
|
671 |
-
<?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
|
672 |
-
</div>
|
673 |
-
</div>
|
674 |
-
<?php
|
675 |
-
}
|
676 |
-
|
677 |
-
|
678 |
-
/**
|
679 |
-
* Tab Header (Used for add logo into header)
|
680 |
-
*
|
681 |
-
* @param array $options options.
|
682 |
-
* @param int $post_id post ID.
|
683 |
-
*/
|
684 |
-
function tab_header_content( $options, $post_id ) {
|
685 |
-
?>
|
686 |
-
|
687 |
-
<div class="wcf-checkout-header wcf-tab-content widefat">
|
688 |
-
<?php
|
689 |
-
|
690 |
-
$layout_pro_option = array();
|
691 |
-
|
692 |
-
echo wcf()->meta->get_image_field(
|
693 |
-
array(
|
694 |
-
'name' => 'wcf-header-logo-image',
|
695 |
-
'value' => $options['wcf-header-logo-image'],
|
696 |
-
'label' => __( 'Header Logo', 'cartflows' ),
|
697 |
-
)
|
698 |
-
);
|
699 |
-
|
700 |
-
echo wcf()->meta->get_number_field(
|
701 |
-
array(
|
702 |
-
'name' => 'wcf-header-logo-width',
|
703 |
-
'value' => $options['wcf-header-logo-width'],
|
704 |
-
'label' => __( 'Logo Width (In px)', 'cartflows' ),
|
705 |
-
)
|
706 |
-
);
|
707 |
-
?>
|
708 |
-
<?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
|
709 |
-
</div>
|
710 |
-
<?php
|
711 |
-
}
|
712 |
-
/**
|
713 |
-
* Get metabox options
|
714 |
-
*
|
715 |
-
* @param int $post_id post ID.
|
716 |
-
*/
|
717 |
-
public static function get_meta_option( $post_id ) {
|
718 |
-
|
719 |
-
if ( null === self::$meta_option ) {
|
720 |
-
|
721 |
-
/**
|
722 |
-
* Set metabox options
|
723 |
-
*
|
724 |
-
* @see http://php.net/manual/en/filter.filters.sanitize.php
|
725 |
-
*/
|
726 |
-
self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
|
727 |
-
}
|
728 |
-
|
729 |
-
return self::$meta_option;
|
730 |
-
}
|
731 |
-
|
732 |
-
/**
|
733 |
-
* Metabox Save
|
734 |
-
*
|
735 |
-
* @param number $post_id Post ID.
|
736 |
-
* @return void
|
737 |
-
*/
|
738 |
-
function save_meta_box( $post_id ) {
|
739 |
-
|
740 |
-
// Checks save status.
|
741 |
-
$is_autosave = wp_is_post_autosave( $post_id );
|
742 |
-
$is_revision = wp_is_post_revision( $post_id );
|
743 |
-
|
744 |
-
$is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
|
745 |
-
|
746 |
-
// Exits script depending on save status.
|
747 |
-
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
|
748 |
-
return;
|
749 |
-
}
|
750 |
-
|
751 |
-
wcf()->options->save_checkout_fields( $post_id );
|
752 |
-
}
|
753 |
-
|
754 |
-
}
|
755 |
-
|
756 |
-
/**
|
757 |
-
* Kicking this off by calling 'get_instance()' method
|
758 |
-
*/
|
759 |
-
Cartflows_Checkout_Meta::get_instance();
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Checkout post meta
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Meta Boxes setup
|
10 |
+
*/
|
11 |
+
class Cartflows_Checkout_Meta extends Cartflows_Meta {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Instance
|
15 |
+
*
|
16 |
+
* @var $instance
|
17 |
+
*/
|
18 |
+
private static $instance;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Meta Option
|
22 |
+
*
|
23 |
+
* @var $meta_option
|
24 |
+
*/
|
25 |
+
private static $meta_option = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Initiator
|
29 |
+
*/
|
30 |
+
public static function get_instance() {
|
31 |
+
if ( ! isset( self::$instance ) ) {
|
32 |
+
self::$instance = new self;
|
33 |
+
}
|
34 |
+
|
35 |
+
return self::$instance;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Constructor
|
40 |
+
*/
|
41 |
+
public function __construct() {
|
42 |
+
|
43 |
+
/* Init Metabox */
|
44 |
+
add_action( 'load-post.php', array( $this, 'init_metabox' ) );
|
45 |
+
add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Init Metabox
|
50 |
+
*/
|
51 |
+
public function init_metabox() {
|
52 |
+
|
53 |
+
add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) );
|
54 |
+
add_action( 'save_post', array( $this, 'save_meta_box' ) );
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Setup Metabox
|
59 |
+
*/
|
60 |
+
function setup_meta_box() {
|
61 |
+
|
62 |
+
// Get all posts.
|
63 |
+
$post_types = get_post_types();
|
64 |
+
|
65 |
+
if ( _is_wcf_checkout_type() ) {
|
66 |
+
add_meta_box(
|
67 |
+
'wcf-checkout-settings', // Id.
|
68 |
+
__( 'Checkout Layout', 'cartflows' ), // Title.
|
69 |
+
array( $this, 'markup_meta_box' ), // Callback.
|
70 |
+
wcf()->utils->get_step_post_type(), // Post_type.
|
71 |
+
'normal', // Context.
|
72 |
+
'high' // Priority.
|
73 |
+
);
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Metabox Markup
|
79 |
+
*
|
80 |
+
* @param object $post Post object.
|
81 |
+
* @return void
|
82 |
+
*/
|
83 |
+
function markup_meta_box( $post ) {
|
84 |
+
|
85 |
+
wp_nonce_field( 'save-nonce-checkout-step-meta', 'nonce-checkout-step-meta' );
|
86 |
+
|
87 |
+
$stored = get_post_meta( $post->ID );
|
88 |
+
|
89 |
+
$checkout_meta = self::get_meta_option( $post->ID );
|
90 |
+
|
91 |
+
// Set stored and override defaults.
|
92 |
+
foreach ( $stored as $key => $value ) {
|
93 |
+
if ( array_key_exists( $key, $checkout_meta ) ) {
|
94 |
+
self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : '';
|
95 |
+
} else {
|
96 |
+
self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : '';
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
// Get defaults.
|
101 |
+
$meta = self::get_meta_option( $post->ID );
|
102 |
+
$checkout_data = array();
|
103 |
+
|
104 |
+
foreach ( $meta as $key => $value ) {
|
105 |
+
|
106 |
+
$checkout_data[ $key ] = $meta[ $key ]['default'];
|
107 |
+
}
|
108 |
+
|
109 |
+
/*
|
110 |
+
$billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post->ID );
|
111 |
+
|
112 |
+
foreach ( $billing_fields as $key => $value ) {
|
113 |
+
|
114 |
+
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
115 |
+
}
|
116 |
+
|
117 |
+
$shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post->ID );
|
118 |
+
|
119 |
+
foreach ( $shipping_fields as $key => $value ) {
|
120 |
+
|
121 |
+
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
122 |
+
}
|
123 |
+
|
124 |
+
$additional_fields = Cartflows_Helper::get_checkout_fields( 'additional', $post->ID );
|
125 |
+
|
126 |
+
foreach ( $additional_fields as $key => $value ) {
|
127 |
+
|
128 |
+
$checkout_data[ 'wcf-' . $key ] = $meta[ 'wcf-' . $key ]['default'];
|
129 |
+
}
|
130 |
+
*/
|
131 |
+
|
132 |
+
do_action( 'wcf_checkout_settings_markup_before' );
|
133 |
+
$this->tabs_markup( $checkout_data, $post->ID );
|
134 |
+
do_action( 'wcf_checkout_settings_markup_after' );
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Page Header Tabs
|
139 |
+
*
|
140 |
+
* @param array $options options.
|
141 |
+
* @param int $post_id post ID.
|
142 |
+
*/
|
143 |
+
function tabs_markup( $options, $post_id ) {
|
144 |
+
|
145 |
+
$active_tab = get_post_meta( $post_id, 'wcf-active-tab', true );
|
146 |
+
|
147 |
+
if ( empty( $active_tab ) ) {
|
148 |
+
$active_tab = 'wcf-checkout-shortcodes';
|
149 |
+
}
|
150 |
+
|
151 |
+
$tabs = array(
|
152 |
+
array(
|
153 |
+
'title' => __( 'Shortcodes', 'cartflows' ),
|
154 |
+
'id' => 'wcf-checkout-shortcodes',
|
155 |
+
'class' => 'wcf-checkout-shortcodes' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
156 |
+
'icon' => 'dashicons-editor-code',
|
157 |
+
'help_text' => 'Help Helpppp...',
|
158 |
+
),
|
159 |
+
array(
|
160 |
+
'title' => __( 'Select Product', 'cartflows' ),
|
161 |
+
'id' => 'wcf-checkout-general',
|
162 |
+
'class' => 'wcf-checkout-general' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
163 |
+
'icon' => 'dashicons-info',
|
164 |
+
),
|
165 |
+
array(
|
166 |
+
'title' => __( 'Order Bump', 'cartflows' ),
|
167 |
+
'id' => 'wcf-product-order-bump',
|
168 |
+
'class' => 'wcf-product-order-bump' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
169 |
+
'icon' => 'dashicons-cart',
|
170 |
+
),
|
171 |
+
array(
|
172 |
+
'title' => __( 'Checkout Design', 'cartflows' ),
|
173 |
+
'id' => 'wcf-checkout-style',
|
174 |
+
'class' => 'wcf-checkout-style' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
175 |
+
'icon' => 'dashicons-admin-customizer',
|
176 |
+
),
|
177 |
+
array(
|
178 |
+
'title' => __( 'Checkout Fields', 'cartflows' ),
|
179 |
+
'id' => 'wcf-checkout-custom-fields',
|
180 |
+
'class' => 'wcf-checkout-custom-fields' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
181 |
+
'icon' => 'dashicons-welcome-widgets-menus',
|
182 |
+
),
|
183 |
+
array(
|
184 |
+
'title' => __( 'Logo ( Optional )', 'cartflows' ),
|
185 |
+
'id' => 'wcf-checkout-header',
|
186 |
+
'class' => 'wcf-checkout-header' === $active_tab ? 'wcf-tab wp-ui-text-highlight active' : 'wcf-tab',
|
187 |
+
'icon' => 'dashicons-format-image',
|
188 |
+
),
|
189 |
+
);
|
190 |
+
|
191 |
+
?>
|
192 |
+
<div class="wcf-checkout-table wcf-metabox-wrap widefat">
|
193 |
+
<div class="wcf-table-container">
|
194 |
+
<div class="wcf-column-left">
|
195 |
+
<div class="wcf-tab-wrapper">
|
196 |
+
|
197 |
+
<?php foreach ( $tabs as $key => $tab ) { ?>
|
198 |
+
<div class="<?php echo esc_attr( $tab['class'] ); ?>" data-tab="<?php echo esc_attr( $tab['id'] ); ?>">
|
199 |
+
<span class="dashicons <?php echo esc_attr( $tab['icon'] ); ?>"></span>
|
200 |
+
<span class="wcf-tab-title"><?php echo esc_html( $tab['title'] ); ?></span>
|
201 |
+
</div>
|
202 |
+
<?php } ?>
|
203 |
+
|
204 |
+
<input type="hidden" id="wcf-active-tab" name="wcf-active-tab" value="<?php echo esc_attr( $active_tab ); ?>" />
|
205 |
+
</div>
|
206 |
+
</div>
|
207 |
+
<div class="wcf-column-right">
|
208 |
+
<?php $this->tab_shortcodes( $options, $post_id ); ?>
|
209 |
+
<?php $this->tab_general( $options, $post_id ); ?>
|
210 |
+
<?php $this->tab_style( $options, $post_id ); ?>
|
211 |
+
<?php $this->tab_product_bump( $options, $post_id ); ?>
|
212 |
+
<?php $this->tab_custom_fields( $options, $post_id ); ?>
|
213 |
+
<?php $this->tab_header_content( $options, $post_id ); ?>
|
214 |
+
<?php $this->right_column_footer( $options, $post_id ); ?>
|
215 |
+
</div>
|
216 |
+
</div>
|
217 |
+
</div>
|
218 |
+
|
219 |
+
<?php
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Shortcodes tab
|
224 |
+
*
|
225 |
+
* @param array $options options.
|
226 |
+
* @param int $post_id post ID.
|
227 |
+
*/
|
228 |
+
function tab_shortcodes( $options, $post_id ) {
|
229 |
+
?>
|
230 |
+
<div class="wcf-checkout-shortcodes wcf-tab-content widefat">
|
231 |
+
|
232 |
+
<?php
|
233 |
+
|
234 |
+
echo wcf()->meta->get_shortcode_field(
|
235 |
+
array(
|
236 |
+
'label' => 'Checkout Page',
|
237 |
+
'name' => 'wcf-checkout-shortcode',
|
238 |
+
'content' => '[cartflows_checkout]',
|
239 |
+
'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
|
240 |
+
)
|
241 |
+
);
|
242 |
+
?>
|
243 |
+
</div>
|
244 |
+
<?php
|
245 |
+
}
|
246 |
+
|
247 |
+
|
248 |
+
/**
|
249 |
+
* General tab
|
250 |
+
*
|
251 |
+
* @param array $options options.
|
252 |
+
* @param int $post_id post ID.
|
253 |
+
*/
|
254 |
+
function tab_general( $options, $post_id ) {
|
255 |
+
?>
|
256 |
+
<div class="wcf-checkout-general wcf-tab-content widefat">
|
257 |
+
|
258 |
+
<?php
|
259 |
+
|
260 |
+
echo wcf()->meta->get_product_selection_repeater(
|
261 |
+
array(
|
262 |
+
'name' => 'wcf-checkout-products',
|
263 |
+
'value' => $options['wcf-checkout-products'],
|
264 |
+
'allow_clear' => true,
|
265 |
+
)
|
266 |
+
);
|
267 |
+
|
268 |
+
do_action( 'cartflows_checkout_general_tab_content', $options, $post_id );
|
269 |
+
|
270 |
+
?>
|
271 |
+
</div>
|
272 |
+
<?php
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Product bump tab
|
277 |
+
*
|
278 |
+
* @param array $options options.
|
279 |
+
* @param int $post_id post ID.
|
280 |
+
*/
|
281 |
+
function tab_product_bump( $options, $post_id ) {
|
282 |
+
?>
|
283 |
+
<div class="wcf-product-order-bump wcf-tab-content widefat">
|
284 |
+
<?php
|
285 |
+
if ( ! _is_cartflows_pro() ) {
|
286 |
+
|
287 |
+
echo wcf()->meta->get_description_field(
|
288 |
+
array(
|
289 |
+
'name' => 'wcf-upgrade-to-pro',
|
290 |
+
/* translators: %s: link */
|
291 |
+
'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Order Bump feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
|
292 |
+
)
|
293 |
+
);
|
294 |
+
}
|
295 |
+
?>
|
296 |
+
|
297 |
+
<?php do_action( 'cartflows_order_bump_tab_content', $options, $post_id ); ?>
|
298 |
+
</div>
|
299 |
+
<?php
|
300 |
+
}
|
301 |
+
/**
|
302 |
+
* Tab custom fields
|
303 |
+
*
|
304 |
+
* @param array $options options.
|
305 |
+
* @param int $post_id post ID.
|
306 |
+
*/
|
307 |
+
function tab_custom_fields( $options, $post_id ) {
|
308 |
+
?>
|
309 |
+
<div class="wcf-checkout-custom-fields wcf-tab-content widefat">
|
310 |
+
<?php
|
311 |
+
/* Custom Checkout Fields Section */
|
312 |
+
|
313 |
+
if ( ! _is_cartflows_pro() ) {
|
314 |
+
|
315 |
+
echo wcf()->meta->get_description_field(
|
316 |
+
array(
|
317 |
+
'name' => 'wcf-upgrade-to-pro',
|
318 |
+
/* translators: %s: link */
|
319 |
+
'content' => '<i>' . sprintf( __( 'Upgrade to %1$sCartFlows Pro%2$s for Custom Fields feature', 'cartflows' ), '<a href="https://cartflows.com/" target="_blank">', '</a>' ) . '</i>',
|
320 |
+
)
|
321 |
+
);
|
322 |
+
}
|
323 |
+
?>
|
324 |
+
<?php do_action( 'cartflows_custom_fields_tab_content', $options, $post_id ); ?>
|
325 |
+
</div>
|
326 |
+
<?php
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Tab style
|
331 |
+
*
|
332 |
+
* @param array $options options.
|
333 |
+
* @param int $post_id post ID.
|
334 |
+
*/
|
335 |
+
function tab_style( $options, $post_id ) {
|
336 |
+
?>
|
337 |
+
|
338 |
+
<div class="wcf-checkout-style wcf-tab-content widefat">
|
339 |
+
<div class="wcf-cs-fields">
|
340 |
+
<div class="wcf-cs-checkbox-field">
|
341 |
+
<?php
|
342 |
+
|
343 |
+
$layout_pro_option = array();
|
344 |
+
|
345 |
+
if ( ! _is_cartflows_pro() ) {
|
346 |
+
$layout_pro_option = array(
|
347 |
+
'one-column' => __( 'One Column (Available in CartFlows Pro) ', 'cartflows' ),
|
348 |
+
);
|
349 |
+
}
|
350 |
+
|
351 |
+
echo wcf()->meta->get_select_field(
|
352 |
+
array(
|
353 |
+
'label' => __( 'Checkout Skin', 'cartflows' ),
|
354 |
+
'name' => 'wcf-checkout-layout',
|
355 |
+
'value' => $options['wcf-checkout-layout'],
|
356 |
+
'options' => array(
|
357 |
+
'one-column' => __( 'One Column', 'cartflows' ),
|
358 |
+
'two-column' => __( 'Two Column', 'cartflows' ),
|
359 |
+
),
|
360 |
+
'pro-options' => $layout_pro_option,
|
361 |
+
|
362 |
+
)
|
363 |
+
);
|
364 |
+
|
365 |
+
echo wcf()->meta->get_color_picker_field(
|
366 |
+
array(
|
367 |
+
'label' => __( 'Primary Color', 'cartflows' ),
|
368 |
+
'name' => 'wcf-primary-color',
|
369 |
+
'value' => $options['wcf-primary-color'],
|
370 |
+
)
|
371 |
+
);
|
372 |
+
|
373 |
+
echo wcf()->meta->get_font_family_field(
|
374 |
+
array(
|
375 |
+
'for' => 'wcf-base',
|
376 |
+
'label' => __( 'Font Family', 'cartflows' ),
|
377 |
+
'name' => 'wcf-base-font-family',
|
378 |
+
'value' => $options['wcf-base-font-family'],
|
379 |
+
)
|
380 |
+
);
|
381 |
+
|
382 |
+
echo wcf()->meta->get_checkbox_field(
|
383 |
+
array(
|
384 |
+
'label' => __( 'Advance Options', 'cartflows' ),
|
385 |
+
'name' => 'wcf-advance-options-fields',
|
386 |
+
'value' => $options['wcf-advance-options-fields'],
|
387 |
+
'after' => 'Enable',
|
388 |
+
)
|
389 |
+
);
|
390 |
+
?>
|
391 |
+
</div>
|
392 |
+
<div class="wcf-cs-fields-options">
|
393 |
+
<?php
|
394 |
+
echo wcf()->meta->get_section(
|
395 |
+
array(
|
396 |
+
'label' => __( 'Heading', 'cartflows' ),
|
397 |
+
)
|
398 |
+
);
|
399 |
+
|
400 |
+
echo wcf()->meta->get_color_picker_field(
|
401 |
+
array(
|
402 |
+
'label' => __( 'Heading Color', 'cartflows' ),
|
403 |
+
'name' => 'wcf-heading-color',
|
404 |
+
'value' => $options['wcf-heading-color'],
|
405 |
+
)
|
406 |
+
);
|
407 |
+
|
408 |
+
echo wcf()->meta->get_font_family_field(
|
409 |
+
array(
|
410 |
+
'for' => 'wcf-heading',
|
411 |
+
'label' => __( 'Font Family', 'cartflows' ),
|
412 |
+
'name' => 'wcf-heading-font-family',
|
413 |
+
'value' => $options['wcf-heading-font-family'],
|
414 |
+
)
|
415 |
+
);
|
416 |
+
|
417 |
+
echo wcf()->meta->get_font_weight_field(
|
418 |
+
array(
|
419 |
+
'for' => 'wcf-heading',
|
420 |
+
'label' => __( 'Font Weight', 'cartflows' ),
|
421 |
+
'name' => 'wcf-heading-font-weight',
|
422 |
+
'value' => $options['wcf-heading-font-weight'],
|
423 |
+
)
|
424 |
+
);
|
425 |
+
|
426 |
+
echo wcf()->meta->get_section(
|
427 |
+
array(
|
428 |
+
'label' => __( 'Input Fields', 'cartflows' ),
|
429 |
+
)
|
430 |
+
);
|
431 |
+
|
432 |
+
$fields_skin_pro_option = array();
|
433 |
+
|
434 |
+
if ( ! _is_cartflows_pro() ) {
|
435 |
+
$fields_skin_pro_option = array(
|
436 |
+
'skin-one' => __( 'Floating Labels (Available in CartFlows Pro)', 'cartflows' ),
|
437 |
+
);
|
438 |
+
}
|
439 |
+
|
440 |
+
echo wcf()->meta->get_select_field(
|
441 |
+
array(
|
442 |
+
'label' => __( 'Style', 'cartflows' ),
|
443 |
+
'name' => 'wcf-fields-skins',
|
444 |
+
'value' => $options['wcf-fields-skins'],
|
445 |
+
'options' => array(
|
446 |
+
'default' => __( 'Default', 'cartflows' ),
|
447 |
+
'style-one' => __( 'Floating Labels', 'cartflows' ),
|
448 |
+
),
|
449 |
+
'pro-options' => $fields_skin_pro_option,
|
450 |
+
|
451 |
+
)
|
452 |
+
);
|
453 |
+
|
454 |
+
echo wcf()->meta->get_font_family_field(
|
455 |
+
array(
|
456 |
+
'for' => 'wcf-input',
|
457 |
+
'label' => __( 'Font Family', 'cartflows' ),
|
458 |
+
'name' => 'wcf-input-font-family',
|
459 |
+
'value' => $options['wcf-input-font-family'],
|
460 |
+
)
|
461 |
+
);
|
462 |
+
|
463 |
+
echo wcf()->meta->get_font_weight_field(
|
464 |
+
array(
|
465 |
+
'for' => 'wcf-input',
|
466 |
+
'label' => __( 'Font Weight', 'cartflows' ),
|
467 |
+
'name' => 'wcf-input-font-weight',
|
468 |
+
'value' => $options['wcf-input-font-weight'],
|
469 |
+
)
|
470 |
+
);
|
471 |
+
|
472 |
+
echo wcf()->meta->get_select_field(
|
473 |
+
array(
|
474 |
+
'label' => __( 'Size', 'cartflows' ),
|
475 |
+
'name' => 'wcf-input-field-size',
|
476 |
+
'value' => $options['wcf-input-field-size'],
|
477 |
+
'options' => array(
|
478 |
+
'33px' => __( 'Extra Small', 'cartflows' ),
|
479 |
+
'38px' => __( 'Small', 'cartflows' ),
|
480 |
+
'44px' => __( 'Medium', 'cartflows' ),
|
481 |
+
'58px' => __( 'Large', 'cartflows' ),
|
482 |
+
'68px' => __( 'Extra Large', 'cartflows' ),
|
483 |
+
'custom' => __( 'Custom', 'cartflows' ),
|
484 |
+
),
|
485 |
+
)
|
486 |
+
);
|
487 |
+
|
488 |
+
echo wcf()->meta->get_number_field(
|
489 |
+
array(
|
490 |
+
'label' => __( 'Top Bottom Spacing', 'cartflows' ),
|
491 |
+
'name' => 'wcf-field-tb-padding',
|
492 |
+
'value' => $options['wcf-field-tb-padding'],
|
493 |
+
)
|
494 |
+
);
|
495 |
+
|
496 |
+
echo wcf()->meta->get_number_field(
|
497 |
+
array(
|
498 |
+
'label' => __( 'Left Right Spacing', 'cartflows' ),
|
499 |
+
'name' => 'wcf-field-lr-padding',
|
500 |
+
'value' => $options['wcf-field-lr-padding'],
|
501 |
+
)
|
502 |
+
);
|
503 |
+
|
504 |
+
echo wcf()->meta->get_color_picker_field(
|
505 |
+
array(
|
506 |
+
'label' => __( 'Text / Placeholder Color', 'cartflows' ),
|
507 |
+
'name' => 'wcf-field-color',
|
508 |
+
'value' => $options['wcf-field-color'],
|
509 |
+
)
|
510 |
+
);
|
511 |
+
|
512 |
+
echo wcf()->meta->get_color_picker_field(
|
513 |
+
array(
|
514 |
+
'label' => __( 'Background Color', 'cartflows' ),
|
515 |
+
'name' => 'wcf-field-bg-color',
|
516 |
+
'value' => $options['wcf-field-bg-color'],
|
517 |
+
)
|
518 |
+
);
|
519 |
+
|
520 |
+
echo wcf()->meta->get_color_picker_field(
|
521 |
+
array(
|
522 |
+
'label' => __( 'Border Color', 'cartflows' ),
|
523 |
+
'name' => 'wcf-field-border-color',
|
524 |
+
'value' => $options['wcf-field-border-color'],
|
525 |
+
)
|
526 |
+
);
|
527 |
+
echo wcf()->meta->get_color_picker_field(
|
528 |
+
array(
|
529 |
+
'label' => __( 'Label Color', 'cartflows' ),
|
530 |
+
'name' => 'wcf-field-label-color',
|
531 |
+
'value' => $options['wcf-field-label-color'],
|
532 |
+
)
|
533 |
+
);
|
534 |
+
|
535 |
+
?>
|
536 |
+
</div>
|
537 |
+
<div class="wcf-cs-button-options">
|
538 |
+
<?php
|
539 |
+
|
540 |
+
echo wcf()->meta->get_section(
|
541 |
+
array(
|
542 |
+
'label' => __( 'Buttons', 'cartflows' ),
|
543 |
+
)
|
544 |
+
);
|
545 |
+
|
546 |
+
echo wcf()->meta->get_font_family_field(
|
547 |
+
array(
|
548 |
+
'for' => 'wcf-button',
|
549 |
+
'label' => __( 'Font Family', 'cartflows' ),
|
550 |
+
'name' => 'wcf-button-font-family',
|
551 |
+
'value' => $options['wcf-button-font-family'],
|
552 |
+
)
|
553 |
+
);
|
554 |
+
|
555 |
+
echo wcf()->meta->get_font_weight_field(
|
556 |
+
array(
|
557 |
+
'for' => 'wcf-button',
|
558 |
+
'label' => __( 'Font Weight', 'cartflows' ),
|
559 |
+
'name' => 'wcf-button-font-weight',
|
560 |
+
'value' => $options['wcf-button-font-weight'],
|
561 |
+
)
|
562 |
+
);
|
563 |
+
|
564 |
+
echo wcf()->meta->get_select_field(
|
565 |
+
array(
|
566 |
+
'label' => __( 'Size', 'cartflows' ),
|
567 |
+
'name' => 'wcf-input-button-size',
|
568 |
+
'value' => $options['wcf-input-button-size'],
|
569 |
+
'options' => array(
|
570 |
+
'33px' => __( 'Extra Small', 'cartflows' ),
|
571 |
+
'38px' => __( 'Small', 'cartflows' ),
|
572 |
+
'44px' => __( 'Medium', 'cartflows' ),
|
573 |
+
'58px' => __( 'Large', 'cartflows' ),
|
574 |
+
'68px' => __( 'Extra Large', 'cartflows' ),
|
575 |
+
'custom' => __( 'Custom', 'cartflows' ),
|
576 |
+
),
|
577 |
+
)
|
578 |
+
);
|
579 |
+
|
580 |
+
echo wcf()->meta->get_number_field(
|
581 |
+
array(
|
582 |
+
'label' => __( 'Top Bottom Spacing', 'cartflows' ),
|
583 |
+
'name' => 'wcf-submit-tb-padding',
|
584 |
+
'value' => $options['wcf-submit-tb-padding'],
|
585 |
+
)
|
586 |
+
);
|
587 |
+
|
588 |
+
echo wcf()->meta->get_number_field(
|
589 |
+
array(
|
590 |
+
'label' => __( 'Left Right Spacing', 'cartflows' ),
|
591 |
+
'name' => 'wcf-submit-lr-padding',
|
592 |
+
'value' => $options['wcf-submit-lr-padding'],
|
593 |
+
)
|
594 |
+
);
|
595 |
+
|
596 |
+
echo wcf()->meta->get_color_picker_field(
|
597 |
+
array(
|
598 |
+
'label' => __( 'Text Color', 'cartflows' ),
|
599 |
+
'name' => 'wcf-submit-color',
|
600 |
+
'value' => $options['wcf-submit-color'],
|
601 |
+
)
|
602 |
+
);
|
603 |
+
|
604 |
+
echo wcf()->meta->get_color_picker_field(
|
605 |
+
array(
|
606 |
+
'label' => __( 'Text Hover Color', 'cartflows' ),
|
607 |
+
'name' => 'wcf-submit-hover-color',
|
608 |
+
'value' => $options['wcf-submit-hover-color'],
|
609 |
+
)
|
610 |
+
);
|
611 |
+
|
612 |
+
echo wcf()->meta->get_color_picker_field(
|
613 |
+
array(
|
614 |
+
'label' => __( 'Background Color', 'cartflows' ),
|
615 |
+
'name' => 'wcf-submit-bg-color',
|
616 |
+
'value' => $options['wcf-submit-bg-color'],
|
617 |
+
)
|
618 |
+
);
|
619 |
+
|
620 |
+
echo wcf()->meta->get_color_picker_field(
|
621 |
+
array(
|
622 |
+
'label' => __( 'Background Hover Color', 'cartflows' ),
|
623 |
+
'name' => 'wcf-submit-bg-hover-color',
|
624 |
+
'value' => $options['wcf-submit-bg-hover-color'],
|
625 |
+
)
|
626 |
+
);
|
627 |
+
|
628 |
+
echo wcf()->meta->get_color_picker_field(
|
629 |
+
array(
|
630 |
+
'label' => __( 'Border Color', 'cartflows' ),
|
631 |
+
'name' => 'wcf-submit-border-color',
|
632 |
+
'value' => $options['wcf-submit-border-color'],
|
633 |
+
)
|
634 |
+
);
|
635 |
+
|
636 |
+
echo wcf()->meta->get_color_picker_field(
|
637 |
+
array(
|
638 |
+
'label' => __( 'Border Hover Color', 'cartflows' ),
|
639 |
+
'name' => 'wcf-submit-border-hover-color',
|
640 |
+
'value' => $options['wcf-submit-border-hover-color'],
|
641 |
+
)
|
642 |
+
);
|
643 |
+
|
644 |
+
?>
|
645 |
+
</div>
|
646 |
+
<div class="wcf-cs-section-options">
|
647 |
+
<?php
|
648 |
+
|
649 |
+
echo wcf()->meta->get_section(
|
650 |
+
array(
|
651 |
+
'label' => __( 'Sections', 'cartflows' ),
|
652 |
+
)
|
653 |
+
);
|
654 |
+
|
655 |
+
echo wcf()->meta->get_color_picker_field(
|
656 |
+
array(
|
657 |
+
'label' => __( 'Highlight Area Background Color', 'cartflows' ),
|
658 |
+
'name' => 'wcf-hl-bg-color',
|
659 |
+
'value' => $options['wcf-hl-bg-color'],
|
660 |
+
)
|
661 |
+
);
|
662 |
+
|
663 |
+
echo wcf()->meta->get_hidden_field(
|
664 |
+
array(
|
665 |
+
'name' => 'wcf-field-google-font-url',
|
666 |
+
'value' => $options['wcf-field-google-font-url'],
|
667 |
+
)
|
668 |
+
);
|
669 |
+
?>
|
670 |
+
</div>
|
671 |
+
<?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
|
672 |
+
</div>
|
673 |
+
</div>
|
674 |
+
<?php
|
675 |
+
}
|
676 |
+
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Tab Header (Used for add logo into header)
|
680 |
+
*
|
681 |
+
* @param array $options options.
|
682 |
+
* @param int $post_id post ID.
|
683 |
+
*/
|
684 |
+
function tab_header_content( $options, $post_id ) {
|
685 |
+
?>
|
686 |
+
|
687 |
+
<div class="wcf-checkout-header wcf-tab-content widefat">
|
688 |
+
<?php
|
689 |
+
|
690 |
+
$layout_pro_option = array();
|
691 |
+
|
692 |
+
echo wcf()->meta->get_image_field(
|
693 |
+
array(
|
694 |
+
'name' => 'wcf-header-logo-image',
|
695 |
+
'value' => $options['wcf-header-logo-image'],
|
696 |
+
'label' => __( 'Header Logo', 'cartflows' ),
|
697 |
+
)
|
698 |
+
);
|
699 |
+
|
700 |
+
echo wcf()->meta->get_number_field(
|
701 |
+
array(
|
702 |
+
'name' => 'wcf-header-logo-width',
|
703 |
+
'value' => $options['wcf-header-logo-width'],
|
704 |
+
'label' => __( 'Logo Width (In px)', 'cartflows' ),
|
705 |
+
)
|
706 |
+
);
|
707 |
+
?>
|
708 |
+
<?php do_action( 'cartflows_checkout_style_tab_content', $options, $post_id ); ?>
|
709 |
+
</div>
|
710 |
+
<?php
|
711 |
+
}
|
712 |
+
/**
|
713 |
+
* Get metabox options
|
714 |
+
*
|
715 |
+
* @param int $post_id post ID.
|
716 |
+
*/
|
717 |
+
public static function get_meta_option( $post_id ) {
|
718 |
+
|
719 |
+
if ( null === self::$meta_option ) {
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Set metabox options
|
723 |
+
*
|
724 |
+
* @see http://php.net/manual/en/filter.filters.sanitize.php
|
725 |
+
*/
|
726 |
+
self::$meta_option = wcf()->options->get_checkout_fields( $post_id );
|
727 |
+
}
|
728 |
+
|
729 |
+
return self::$meta_option;
|
730 |
+
}
|
731 |
+
|
732 |
+
/**
|
733 |
+
* Metabox Save
|
734 |
+
*
|
735 |
+
* @param number $post_id Post ID.
|
736 |
+
* @return void
|
737 |
+
*/
|
738 |
+
function save_meta_box( $post_id ) {
|
739 |
+
|
740 |
+
// Checks save status.
|
741 |
+
$is_autosave = wp_is_post_autosave( $post_id );
|
742 |
+
$is_revision = wp_is_post_revision( $post_id );
|
743 |
+
|
744 |
+
$is_valid_nonce = ( isset( $_POST['nonce-checkout-step-meta'] ) && wp_verify_nonce( $_POST['nonce-checkout-step-meta'], 'save-nonce-checkout-step-meta' ) ) ? true : false;
|
745 |
+
|
746 |
+
// Exits script depending on save status.
|
747 |
+
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
|
748 |
+
return;
|
749 |
+
}
|
750 |
+
|
751 |
+
wcf()->options->save_checkout_fields( $post_id );
|
752 |
+
}
|
753 |
+
|
754 |
+
}
|
755 |
+
|
756 |
+
/**
|
757 |
+
* Kicking this off by calling 'get_instance()' method
|
758 |
+
*/
|
759 |
+
Cartflows_Checkout_Meta::get_instance();
|
modules/flow/classes/class-cartflows-step-post-type.php
CHANGED
@@ -1,449 +1,449 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Step post type.
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Initialization
|
10 |
-
*
|
11 |
-
* @since 1.0.0
|
12 |
-
*/
|
13 |
-
class Cartflows_Step_Post_Type {
|
14 |
-
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Member Variable
|
18 |
-
*
|
19 |
-
* @var instance
|
20 |
-
*/
|
21 |
-
private static $instance;
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Member Variable
|
25 |
-
*
|
26 |
-
* @var body_classes
|
27 |
-
*/
|
28 |
-
private $body_classes = array();
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Initiator
|
32 |
-
*/
|
33 |
-
public static function get_instance() {
|
34 |
-
if ( ! isset( self::$instance ) ) {
|
35 |
-
self::$instance = new self;
|
36 |
-
}
|
37 |
-
return self::$instance;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Constructor
|
42 |
-
*/
|
43 |
-
public function __construct() {
|
44 |
-
|
45 |
-
add_action( 'init', array( $this, 'step_post_type' ) );
|
46 |
-
add_action( 'init', array( $this, 'add_wp_templates_support' ) );
|
47 |
-
add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
|
48 |
-
add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
|
49 |
-
add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
|
50 |
-
add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ) );
|
51 |
-
|
52 |
-
add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Trys to load page.php for a header, footer or part theme layout.
|
57 |
-
*
|
58 |
-
* @since 1.0.0
|
59 |
-
* @param string $template The current template to be loaded.
|
60 |
-
* @return string
|
61 |
-
*/
|
62 |
-
function load_page_template( $template ) {
|
63 |
-
|
64 |
-
global $post;
|
65 |
-
|
66 |
-
if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Remove Next/Prev Navigation
|
70 |
-
* add_filter('next_post_link', '__return_empty_string');
|
71 |
-
* add_filter('previous_post_link', '__return_empty_string');
|
72 |
-
*
|
73 |
-
* $page = locate_template( array( 'page.php' ) );
|
74 |
-
*
|
75 |
-
* if ( ! empty( $page ) ) {
|
76 |
-
* return $page;
|
77 |
-
* }
|
78 |
-
*/
|
79 |
-
|
80 |
-
$page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
|
81 |
-
|
82 |
-
$page_template = apply_filters( 'cartflows_page_template', $page_template );
|
83 |
-
|
84 |
-
$file = '';
|
85 |
-
|
86 |
-
switch ( $page_template ) {
|
87 |
-
|
88 |
-
case 'cartflows-default':
|
89 |
-
$file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
|
90 |
-
$this->body_classes[] = $page_template;
|
91 |
-
break;
|
92 |
-
case 'cartflows-canvas':
|
93 |
-
$file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
|
94 |
-
$this->body_classes[] = $page_template;
|
95 |
-
break;
|
96 |
-
default:
|
97 |
-
$file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
|
98 |
-
$this->body_classes[] = 'cartflows-default';
|
99 |
-
break;
|
100 |
-
}
|
101 |
-
|
102 |
-
// Just to be safe, we check if the file exist first.
|
103 |
-
if ( file_exists( $file ) ) {
|
104 |
-
|
105 |
-
/* Add Body Class */
|
106 |
-
add_filter( 'body_class', [ $this, 'body_class' ] );
|
107 |
-
|
108 |
-
return $file;
|
109 |
-
} else {
|
110 |
-
echo $file;
|
111 |
-
}
|
112 |
-
}
|
113 |
-
|
114 |
-
return $template;
|
115 |
-
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Body classes.
|
119 |
-
*
|
120 |
-
* @since 1.0.0
|
121 |
-
* @param array $classes Body classes.
|
122 |
-
* @return array
|
123 |
-
*/
|
124 |
-
function body_class( $classes = [] ) {
|
125 |
-
|
126 |
-
$classes = array_merge( $classes, $this->body_classes );
|
127 |
-
|
128 |
-
return $classes;
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Create custom post type
|
133 |
-
*/
|
134 |
-
function step_post_type() {
|
135 |
-
|
136 |
-
$labels = array(
|
137 |
-
'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
|
138 |
-
'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
|
139 |
-
'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
|
140 |
-
'all_items' => esc_html__( 'All Steps', 'cartflows' ),
|
141 |
-
'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
|
142 |
-
'view_item' => esc_html__( 'View Step', 'cartflows' ),
|
143 |
-
'add_new' => esc_html__( 'Add New', 'cartflows' ),
|
144 |
-
'update_item' => esc_html__( 'Update Step', 'cartflows' ),
|
145 |
-
'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
|
146 |
-
'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
|
147 |
-
);
|
148 |
-
|
149 |
-
$args = array(
|
150 |
-
'labels' => $labels,
|
151 |
-
'public' => true,
|
152 |
-
'query_var' => true,
|
153 |
-
'can_export' => true,
|
154 |
-
'exclude_from_search' => true,
|
155 |
-
'show_ui' => true,
|
156 |
-
'show_in_menu' => false,
|
157 |
-
'show_in_admin_bar' => true,
|
158 |
-
'supports' => array( 'title', 'editor', 'elementor' ),
|
159 |
-
'capability_type' => 'post',
|
160 |
-
'capabilities' => array(
|
161 |
-
'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
|
162 |
-
),
|
163 |
-
'map_meta_cap' => true,
|
164 |
-
);
|
165 |
-
|
166 |
-
register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
|
167 |
-
|
168 |
-
$args = array(
|
169 |
-
'label' => __( 'Step Type', 'cartflows' ),
|
170 |
-
'public' => false,
|
171 |
-
'rewrite' => false,
|
172 |
-
'hierarchical' => false,
|
173 |
-
);
|
174 |
-
|
175 |
-
register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
|
176 |
-
|
177 |
-
$args = array(
|
178 |
-
'label' => __( 'Step Flow', 'cartflows' ),
|
179 |
-
'public' => false,
|
180 |
-
'rewrite' => false,
|
181 |
-
'hierarchical' => false,
|
182 |
-
);
|
183 |
-
|
184 |
-
register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Register 'Elementor' & 'Beaver Builder' site types.
|
188 |
-
*
|
189 |
-
* @see self::add_terms();
|
190 |
-
*/
|
191 |
-
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
192 |
-
|
193 |
-
$terms = array(
|
194 |
-
array(
|
195 |
-
'name' => __( 'Landing', 'cartflows' ),
|
196 |
-
'args' => array(
|
197 |
-
'slug' => 'landing',
|
198 |
-
),
|
199 |
-
),
|
200 |
-
array(
|
201 |
-
'name' => __( 'Checkout', 'cartflows' ),
|
202 |
-
'args' => array(
|
203 |
-
'slug' => 'checkout',
|
204 |
-
),
|
205 |
-
),
|
206 |
-
array(
|
207 |
-
'name' => __( 'Thank You', 'cartflows' ),
|
208 |
-
'args' => array(
|
209 |
-
'slug' => 'thankyou',
|
210 |
-
),
|
211 |
-
),
|
212 |
-
array(
|
213 |
-
'name' => __( 'Upsell', 'cartflows' ),
|
214 |
-
'args' => array(
|
215 |
-
'slug' => 'upsell',
|
216 |
-
),
|
217 |
-
),
|
218 |
-
array(
|
219 |
-
'name' => __( 'Downsell', 'cartflows' ),
|
220 |
-
'args' => array(
|
221 |
-
'slug' => 'downsell',
|
222 |
-
),
|
223 |
-
),
|
224 |
-
);
|
225 |
-
|
226 |
-
$this->add_terms( $taxonomy, $terms );
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Add WordPress templates.
|
231 |
-
*
|
232 |
-
* Adds Cartflows templates to steps
|
233 |
-
*
|
234 |
-
* @since 1.0.0
|
235 |
-
* @access public
|
236 |
-
*/
|
237 |
-
function add_wp_templates_support() {
|
238 |
-
add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
|
239 |
-
}
|
240 |
-
|
241 |
-
/**
|
242 |
-
* Add page templates.
|
243 |
-
*
|
244 |
-
* @since 1.0.0
|
245 |
-
* @access public
|
246 |
-
*
|
247 |
-
* @param array $page_templates Array of page templates.
|
248 |
-
*
|
249 |
-
* @param object $wp_theme wp theme.
|
250 |
-
* @param object $post post.
|
251 |
-
*
|
252 |
-
* @return array Page templates.
|
253 |
-
*/
|
254 |
-
function add_page_templates( $page_templates, $wp_theme, $post ) {
|
255 |
-
|
256 |
-
$page_templates = array(
|
257 |
-
'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
|
258 |
-
);
|
259 |
-
|
260 |
-
return $page_templates;
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Have WordPress match postname to any of our public post types.
|
265 |
-
* All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
|
266 |
-
* By default, WordPress only accounts for posts and pages where the slug is /post-name/.
|
267 |
-
*
|
268 |
-
* @param string $query query statement.
|
269 |
-
*/
|
270 |
-
function add_cpt_post_names_to_main_query( $query ) {
|
271 |
-
|
272 |
-
// Bail if this is not the main query.
|
273 |
-
if ( ! $query->is_main_query() ) {
|
274 |
-
return;
|
275 |
-
}
|
276 |
-
// Bail if this query doesn't match our very specific rewrite rule.
|
277 |
-
if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
|
278 |
-
return;
|
279 |
-
}
|
280 |
-
// Bail if we're not querying based on the post name.
|
281 |
-
if ( empty( $query->query['name'] ) ) {
|
282 |
-
return;
|
283 |
-
}
|
284 |
-
// Add CPT to the list of post types WP will include when it queries based on the post name.
|
285 |
-
$query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
|
286 |
-
}
|
287 |
-
|
288 |
-
/**
|
289 |
-
* Modify permalink
|
290 |
-
*
|
291 |
-
* @param string $post_link post link.
|
292 |
-
* @param array $post post data.
|
293 |
-
* @param string $leavename leave name.
|
294 |
-
* @return string
|
295 |
-
*/
|
296 |
-
function post_type_permalinks( $post_link, $post, $leavename ) {
|
297 |
-
|
298 |
-
// If elementor page preview, return post link as it is.
|
299 |
-
if ( isset( $_REQUEST['elementor-preview'] ) ) {
|
300 |
-
return $post_link;
|
301 |
-
}
|
302 |
-
|
303 |
-
$structure = get_option( 'permalink_structure' );
|
304 |
-
|
305 |
-
if ( '/%postname%/' === $structure ) {
|
306 |
-
|
307 |
-
if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
|
308 |
-
|
309 |
-
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
|
310 |
-
}
|
311 |
-
}
|
312 |
-
|
313 |
-
return $post_link;
|
314 |
-
}
|
315 |
-
|
316 |
-
/**
|
317 |
-
* Prevent slug duplicated
|
318 |
-
*
|
319 |
-
* @param string $slug post slug.
|
320 |
-
* @param int $post_ID post id.
|
321 |
-
* @param string $post_status post status.
|
322 |
-
* @param string $post_type post type.
|
323 |
-
* @param int $post_parent post parent id.
|
324 |
-
* @param string $original_slug original slug.
|
325 |
-
* @return string
|
326 |
-
*/
|
327 |
-
function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
|
328 |
-
|
329 |
-
$check_post_types = array(
|
330 |
-
'post',
|
331 |
-
'page',
|
332 |
-
CARTFLOWS_STEP_POST_TYPE,
|
333 |
-
);
|
334 |
-
|
335 |
-
if ( ! in_array( $post_type, $check_post_types ) ) {
|
336 |
-
return $slug;
|
337 |
-
}
|
338 |
-
|
339 |
-
if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
|
340 |
-
// Saving a post, check for duplicates in POST or PAGE post types.
|
341 |
-
$post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
|
342 |
-
$page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
|
343 |
-
|
344 |
-
if ( $post_match || $page_match ) {
|
345 |
-
$slug .= '-2';
|
346 |
-
}
|
347 |
-
} else {
|
348 |
-
|
349 |
-
// Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
|
350 |
-
$custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
|
351 |
-
|
352 |
-
if ( $custom_post_type_match ) {
|
353 |
-
$slug .= '-2';
|
354 |
-
}
|
355 |
-
}
|
356 |
-
|
357 |
-
return $slug;
|
358 |
-
}
|
359 |
-
|
360 |
-
/**
|
361 |
-
* Add Update messages for any custom post type
|
362 |
-
*
|
363 |
-
* @param array $messages Array of default messages.
|
364 |
-
*/
|
365 |
-
function post_update_messages( $messages ) {
|
366 |
-
|
367 |
-
$custom_post_type = get_post_type( get_the_ID() );
|
368 |
-
|
369 |
-
if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
|
370 |
-
|
371 |
-
$obj = get_post_type_object( $custom_post_type );
|
372 |
-
$singular_name = $obj->labels->singular_name;
|
373 |
-
$messages[ $custom_post_type ] = array(
|
374 |
-
0 => '', // Unused. Messages start at index 1.
|
375 |
-
/* translators: %s: singular custom post type name */
|
376 |
-
1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
|
377 |
-
/* translators: %s: singular custom post type name */
|
378 |
-
2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
|
379 |
-
/* translators: %s: singular custom post type name */
|
380 |
-
3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
|
381 |
-
/* translators: %s: singular custom post type name */
|
382 |
-
4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
|
383 |
-
/* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
|
384 |
-
5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
385 |
-
/* translators: %s: singular custom post type name */
|
386 |
-
6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
|
387 |
-
/* translators: %s: singular custom post type name */
|
388 |
-
7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
|
389 |
-
/* translators: %s: singular custom post type name */
|
390 |
-
8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
|
391 |
-
/* translators: %s: singular custom post type name */
|
392 |
-
9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
|
393 |
-
/* translators: %s: singular custom post type name */
|
394 |
-
10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
|
395 |
-
);
|
396 |
-
}
|
397 |
-
|
398 |
-
return $messages;
|
399 |
-
}
|
400 |
-
|
401 |
-
/**
|
402 |
-
* Add Terms for Taxonomy.
|
403 |
-
*
|
404 |
-
* => Example.
|
405 |
-
*
|
406 |
-
* $taxonomy = '{taxonomy}';
|
407 |
-
* $terms = array(
|
408 |
-
* array(
|
409 |
-
* 'name' => 'Free',
|
410 |
-
* ),
|
411 |
-
* array(
|
412 |
-
* 'name' => 'Premium',
|
413 |
-
* ),
|
414 |
-
* );
|
415 |
-
*
|
416 |
-
* self::add_terms( $taxonomy, $terms );
|
417 |
-
*
|
418 |
-
* @since 1.0.0
|
419 |
-
* @param string $taxonomy Taxonomy Name.
|
420 |
-
* @param array $terms Terms list.
|
421 |
-
* @return void
|
422 |
-
*/
|
423 |
-
function add_terms( $taxonomy = '', $terms = array() ) {
|
424 |
-
|
425 |
-
foreach ( $terms as $key => $term ) {
|
426 |
-
|
427 |
-
$term_exist = term_exists( $term['name'], $taxonomy );
|
428 |
-
|
429 |
-
if ( empty( $term_exist ) ) {
|
430 |
-
|
431 |
-
/**
|
432 |
-
* Add additional args if passed from request.
|
433 |
-
*
|
434 |
-
* @see https://codex.wordpress.org/Function_Reference/wp_insert_term
|
435 |
-
*/
|
436 |
-
if ( array_key_exists( 'args', $term ) ) {
|
437 |
-
wp_insert_term( $term['name'], $taxonomy, $term['args'] );
|
438 |
-
} else {
|
439 |
-
wp_insert_term( $term['name'], $taxonomy );
|
440 |
-
}
|
441 |
-
}
|
442 |
-
}
|
443 |
-
}
|
444 |
-
}
|
445 |
-
|
446 |
-
/**
|
447 |
-
* Kicking this off by calling 'get_instance()' method
|
448 |
-
*/
|
449 |
-
Cartflows_Step_Post_Type::get_instance();
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Step post type.
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initialization
|
10 |
+
*
|
11 |
+
* @since 1.0.0
|
12 |
+
*/
|
13 |
+
class Cartflows_Step_Post_Type {
|
14 |
+
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Member Variable
|
18 |
+
*
|
19 |
+
* @var instance
|
20 |
+
*/
|
21 |
+
private static $instance;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Member Variable
|
25 |
+
*
|
26 |
+
* @var body_classes
|
27 |
+
*/
|
28 |
+
private $body_classes = array();
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Initiator
|
32 |
+
*/
|
33 |
+
public static function get_instance() {
|
34 |
+
if ( ! isset( self::$instance ) ) {
|
35 |
+
self::$instance = new self;
|
36 |
+
}
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Constructor
|
42 |
+
*/
|
43 |
+
public function __construct() {
|
44 |
+
|
45 |
+
add_action( 'init', array( $this, 'step_post_type' ) );
|
46 |
+
add_action( 'init', array( $this, 'add_wp_templates_support' ) );
|
47 |
+
add_filter( 'post_updated_messages', array( $this, 'post_update_messages' ) );
|
48 |
+
add_filter( 'post_type_link', array( $this, 'post_type_permalinks' ), 10, 3 );
|
49 |
+
add_filter( 'wp_unique_post_slug', array( $this, 'prevent_slug_duplicates' ), 10, 6 );
|
50 |
+
add_action( 'pre_get_posts', array( $this, 'add_cpt_post_names_to_main_query' ) );
|
51 |
+
|
52 |
+
add_filter( 'template_include', array( $this, 'load_page_template' ), 99 );
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Trys to load page.php for a header, footer or part theme layout.
|
57 |
+
*
|
58 |
+
* @since 1.0.0
|
59 |
+
* @param string $template The current template to be loaded.
|
60 |
+
* @return string
|
61 |
+
*/
|
62 |
+
function load_page_template( $template ) {
|
63 |
+
|
64 |
+
global $post;
|
65 |
+
|
66 |
+
if ( 'string' == gettype( $template ) && is_object( $post ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Remove Next/Prev Navigation
|
70 |
+
* add_filter('next_post_link', '__return_empty_string');
|
71 |
+
* add_filter('previous_post_link', '__return_empty_string');
|
72 |
+
*
|
73 |
+
* $page = locate_template( array( 'page.php' ) );
|
74 |
+
*
|
75 |
+
* if ( ! empty( $page ) ) {
|
76 |
+
* return $page;
|
77 |
+
* }
|
78 |
+
*/
|
79 |
+
|
80 |
+
$page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true );
|
81 |
+
|
82 |
+
$page_template = apply_filters( 'cartflows_page_template', $page_template );
|
83 |
+
|
84 |
+
$file = '';
|
85 |
+
|
86 |
+
switch ( $page_template ) {
|
87 |
+
|
88 |
+
case 'cartflows-default':
|
89 |
+
$file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
|
90 |
+
$this->body_classes[] = $page_template;
|
91 |
+
break;
|
92 |
+
case 'cartflows-canvas':
|
93 |
+
$file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php';
|
94 |
+
$this->body_classes[] = $page_template;
|
95 |
+
break;
|
96 |
+
default:
|
97 |
+
$file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php';
|
98 |
+
$this->body_classes[] = 'cartflows-default';
|
99 |
+
break;
|
100 |
+
}
|
101 |
+
|
102 |
+
// Just to be safe, we check if the file exist first.
|
103 |
+
if ( file_exists( $file ) ) {
|
104 |
+
|
105 |
+
/* Add Body Class */
|
106 |
+
add_filter( 'body_class', [ $this, 'body_class' ] );
|
107 |
+
|
108 |
+
return $file;
|
109 |
+
} else {
|
110 |
+
echo $file;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
return $template;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Body classes.
|
119 |
+
*
|
120 |
+
* @since 1.0.0
|
121 |
+
* @param array $classes Body classes.
|
122 |
+
* @return array
|
123 |
+
*/
|
124 |
+
function body_class( $classes = [] ) {
|
125 |
+
|
126 |
+
$classes = array_merge( $classes, $this->body_classes );
|
127 |
+
|
128 |
+
return $classes;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Create custom post type
|
133 |
+
*/
|
134 |
+
function step_post_type() {
|
135 |
+
|
136 |
+
$labels = array(
|
137 |
+
'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ),
|
138 |
+
'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ),
|
139 |
+
'search_items' => esc_html__( 'Search Steps', 'cartflows' ),
|
140 |
+
'all_items' => esc_html__( 'All Steps', 'cartflows' ),
|
141 |
+
'edit_item' => esc_html__( 'Edit Step', 'cartflows' ),
|
142 |
+
'view_item' => esc_html__( 'View Step', 'cartflows' ),
|
143 |
+
'add_new' => esc_html__( 'Add New', 'cartflows' ),
|
144 |
+
'update_item' => esc_html__( 'Update Step', 'cartflows' ),
|
145 |
+
'add_new_item' => esc_html__( 'Add New', 'cartflows' ),
|
146 |
+
'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ),
|
147 |
+
);
|
148 |
+
|
149 |
+
$args = array(
|
150 |
+
'labels' => $labels,
|
151 |
+
'public' => true,
|
152 |
+
'query_var' => true,
|
153 |
+
'can_export' => true,
|
154 |
+
'exclude_from_search' => true,
|
155 |
+
'show_ui' => true,
|
156 |
+
'show_in_menu' => false,
|
157 |
+
'show_in_admin_bar' => true,
|
158 |
+
'supports' => array( 'title', 'editor', 'elementor' ),
|
159 |
+
'capability_type' => 'post',
|
160 |
+
'capabilities' => array(
|
161 |
+
'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false.
|
162 |
+
),
|
163 |
+
'map_meta_cap' => true,
|
164 |
+
);
|
165 |
+
|
166 |
+
register_post_type( CARTFLOWS_STEP_POST_TYPE, $args );
|
167 |
+
|
168 |
+
$args = array(
|
169 |
+
'label' => __( 'Step Type', 'cartflows' ),
|
170 |
+
'public' => false,
|
171 |
+
'rewrite' => false,
|
172 |
+
'hierarchical' => false,
|
173 |
+
);
|
174 |
+
|
175 |
+
register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args );
|
176 |
+
|
177 |
+
$args = array(
|
178 |
+
'label' => __( 'Step Flow', 'cartflows' ),
|
179 |
+
'public' => false,
|
180 |
+
'rewrite' => false,
|
181 |
+
'hierarchical' => false,
|
182 |
+
);
|
183 |
+
|
184 |
+
register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args );
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Register 'Elementor' & 'Beaver Builder' site types.
|
188 |
+
*
|
189 |
+
* @see self::add_terms();
|
190 |
+
*/
|
191 |
+
$taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE;
|
192 |
+
|
193 |
+
$terms = array(
|
194 |
+
array(
|
195 |
+
'name' => __( 'Landing', 'cartflows' ),
|
196 |
+
'args' => array(
|
197 |
+
'slug' => 'landing',
|
198 |
+
),
|
199 |
+
),
|
200 |
+
array(
|
201 |
+
'name' => __( 'Checkout', 'cartflows' ),
|
202 |
+
'args' => array(
|
203 |
+
'slug' => 'checkout',
|
204 |
+
),
|
205 |
+
),
|
206 |
+
array(
|
207 |
+
'name' => __( 'Thank You', 'cartflows' ),
|
208 |
+
'args' => array(
|
209 |
+
'slug' => 'thankyou',
|
210 |
+
),
|
211 |
+
),
|
212 |
+
array(
|
213 |
+
'name' => __( 'Upsell', 'cartflows' ),
|
214 |
+
'args' => array(
|
215 |
+
'slug' => 'upsell',
|
216 |
+
),
|
217 |
+
),
|
218 |
+
array(
|
219 |
+
'name' => __( 'Downsell', 'cartflows' ),
|
220 |
+
'args' => array(
|
221 |
+
'slug' => 'downsell',
|
222 |
+
),
|
223 |
+
),
|
224 |
+
);
|
225 |
+
|
226 |
+
$this->add_terms( $taxonomy, $terms );
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Add WordPress templates.
|
231 |
+
*
|
232 |
+
* Adds Cartflows templates to steps
|
233 |
+
*
|
234 |
+
* @since 1.0.0
|
235 |
+
* @access public
|
236 |
+
*/
|
237 |
+
function add_wp_templates_support() {
|
238 |
+
add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 );
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Add page templates.
|
243 |
+
*
|
244 |
+
* @since 1.0.0
|
245 |
+
* @access public
|
246 |
+
*
|
247 |
+
* @param array $page_templates Array of page templates.
|
248 |
+
*
|
249 |
+
* @param object $wp_theme wp theme.
|
250 |
+
* @param object $post post.
|
251 |
+
*
|
252 |
+
* @return array Page templates.
|
253 |
+
*/
|
254 |
+
function add_page_templates( $page_templates, $wp_theme, $post ) {
|
255 |
+
|
256 |
+
$page_templates = array(
|
257 |
+
'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ),
|
258 |
+
);
|
259 |
+
|
260 |
+
return $page_templates;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Have WordPress match postname to any of our public post types.
|
265 |
+
* All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts.
|
266 |
+
* By default, WordPress only accounts for posts and pages where the slug is /post-name/.
|
267 |
+
*
|
268 |
+
* @param string $query query statement.
|
269 |
+
*/
|
270 |
+
function add_cpt_post_names_to_main_query( $query ) {
|
271 |
+
|
272 |
+
// Bail if this is not the main query.
|
273 |
+
if ( ! $query->is_main_query() ) {
|
274 |
+
return;
|
275 |
+
}
|
276 |
+
// Bail if this query doesn't match our very specific rewrite rule.
|
277 |
+
if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
|
278 |
+
return;
|
279 |
+
}
|
280 |
+
// Bail if we're not querying based on the post name.
|
281 |
+
if ( empty( $query->query['name'] ) ) {
|
282 |
+
return;
|
283 |
+
}
|
284 |
+
// Add CPT to the list of post types WP will include when it queries based on the post name.
|
285 |
+
$query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) );
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Modify permalink
|
290 |
+
*
|
291 |
+
* @param string $post_link post link.
|
292 |
+
* @param array $post post data.
|
293 |
+
* @param string $leavename leave name.
|
294 |
+
* @return string
|
295 |
+
*/
|
296 |
+
function post_type_permalinks( $post_link, $post, $leavename ) {
|
297 |
+
|
298 |
+
// If elementor page preview, return post link as it is.
|
299 |
+
if ( isset( $_REQUEST['elementor-preview'] ) ) {
|
300 |
+
return $post_link;
|
301 |
+
}
|
302 |
+
|
303 |
+
$structure = get_option( 'permalink_structure' );
|
304 |
+
|
305 |
+
if ( '/%postname%/' === $structure ) {
|
306 |
+
|
307 |
+
if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) {
|
308 |
+
|
309 |
+
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
return $post_link;
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Prevent slug duplicated
|
318 |
+
*
|
319 |
+
* @param string $slug post slug.
|
320 |
+
* @param int $post_ID post id.
|
321 |
+
* @param string $post_status post status.
|
322 |
+
* @param string $post_type post type.
|
323 |
+
* @param int $post_parent post parent id.
|
324 |
+
* @param string $original_slug original slug.
|
325 |
+
* @return string
|
326 |
+
*/
|
327 |
+
function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
|
328 |
+
|
329 |
+
$check_post_types = array(
|
330 |
+
'post',
|
331 |
+
'page',
|
332 |
+
CARTFLOWS_STEP_POST_TYPE,
|
333 |
+
);
|
334 |
+
|
335 |
+
if ( ! in_array( $post_type, $check_post_types ) ) {
|
336 |
+
return $slug;
|
337 |
+
}
|
338 |
+
|
339 |
+
if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) {
|
340 |
+
// Saving a post, check for duplicates in POST or PAGE post types.
|
341 |
+
$post_match = get_page_by_path( $slug, 'OBJECT', 'post' );
|
342 |
+
$page_match = get_page_by_path( $slug, 'OBJECT', 'page' );
|
343 |
+
|
344 |
+
if ( $post_match || $page_match ) {
|
345 |
+
$slug .= '-2';
|
346 |
+
}
|
347 |
+
} else {
|
348 |
+
|
349 |
+
// Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type.
|
350 |
+
$custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE );
|
351 |
+
|
352 |
+
if ( $custom_post_type_match ) {
|
353 |
+
$slug .= '-2';
|
354 |
+
}
|
355 |
+
}
|
356 |
+
|
357 |
+
return $slug;
|
358 |
+
}
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Add Update messages for any custom post type
|
362 |
+
*
|
363 |
+
* @param array $messages Array of default messages.
|
364 |
+
*/
|
365 |
+
function post_update_messages( $messages ) {
|
366 |
+
|
367 |
+
$custom_post_type = get_post_type( get_the_ID() );
|
368 |
+
|
369 |
+
if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) {
|
370 |
+
|
371 |
+
$obj = get_post_type_object( $custom_post_type );
|
372 |
+
$singular_name = $obj->labels->singular_name;
|
373 |
+
$messages[ $custom_post_type ] = array(
|
374 |
+
0 => '', // Unused. Messages start at index 1.
|
375 |
+
/* translators: %s: singular custom post type name */
|
376 |
+
1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
|
377 |
+
/* translators: %s: singular custom post type name */
|
378 |
+
2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ),
|
379 |
+
/* translators: %s: singular custom post type name */
|
380 |
+
3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ),
|
381 |
+
/* translators: %s: singular custom post type name */
|
382 |
+
4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ),
|
383 |
+
/* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */
|
384 |
+
5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
385 |
+
/* translators: %s: singular custom post type name */
|
386 |
+
6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ),
|
387 |
+
/* translators: %s: singular custom post type name */
|
388 |
+
7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ),
|
389 |
+
/* translators: %s: singular custom post type name */
|
390 |
+
8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ),
|
391 |
+
/* translators: %s: singular custom post type name */
|
392 |
+
9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ),
|
393 |
+
/* translators: %s: singular custom post type name */
|
394 |
+
10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ),
|
395 |
+
);
|
396 |
+
}
|
397 |
+
|
398 |
+
return $messages;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Add Terms for Taxonomy.
|
403 |
+
*
|
404 |
+
* => Example.
|
405 |
+
*
|
406 |
+
* $taxonomy = '{taxonomy}';
|
407 |
+
* $terms = array(
|
408 |
+
* array(
|
409 |
+
* 'name' => 'Free',
|
410 |
+
* ),
|
411 |
+
* array(
|
412 |
+
* 'name' => 'Premium',
|
413 |
+
* ),
|
414 |
+
* );
|
415 |
+
*
|
416 |
+
* self::add_terms( $taxonomy, $terms );
|
417 |
+
*
|
418 |
+
* @since 1.0.0
|
419 |
+
* @param string $taxonomy Taxonomy Name.
|
420 |
+
* @param array $terms Terms list.
|
421 |
+
* @return void
|
422 |
+
*/
|
423 |
+
function add_terms( $taxonomy = '', $terms = array() ) {
|
424 |
+
|
425 |
+
foreach ( $terms as $key => $term ) {
|
426 |
+
|
427 |
+
$term_exist = term_exists( $term['name'], $taxonomy );
|
428 |
+
|
429 |
+
if ( empty( $term_exist ) ) {
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Add additional args if passed from request.
|
433 |
+
*
|
434 |
+
* @see https://codex.wordpress.org/Function_Reference/wp_insert_term
|
435 |
+
*/
|
436 |
+
if ( array_key_exists( 'args', $term ) ) {
|
437 |
+
wp_insert_term( $term['name'], $taxonomy, $term['args'] );
|
438 |
+
} else {
|
439 |
+
wp_insert_term( $term['name'], $taxonomy );
|
440 |
+
}
|
441 |
+
}
|
442 |
+
}
|
443 |
+
}
|
444 |
+
}
|
445 |
+
|
446 |
+
/**
|
447 |
+
* Kicking this off by calling 'get_instance()' method
|
448 |
+
*/
|
449 |
+
Cartflows_Step_Post_Type::get_instance();
|
modules/flow/view/meta-flow-steps.php
CHANGED
@@ -1,168 +1,168 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* View Flow steps
|
4 |
-
*
|
5 |
-
* @package CartFlows
|
6 |
-
*/
|
7 |
-
|
8 |
-
$get_steps = array(
|
9 |
-
'landing' => __( 'Landing', 'cartflows' ),
|
10 |
-
'checkout' => __( 'Checkout', 'cartflows' ),
|
11 |
-
'thankyou' => __( 'Thank You', 'cartflows' ),
|
12 |
-
'upsell' => __( 'Upsell', 'cartflows' ),
|
13 |
-
'downsell' => __( 'Downsell', 'cartflows' ),
|
14 |
-
|
15 |
-
);
|
16 |
-
|
17 |
-
?>
|
18 |
-
<div class="wcf-flow-steps-meta-box">
|
19 |
-
<div class="wcf-flow-settings">
|
20 |
-
<?php do_action( 'cartflows_above_flow_steps' ); ?>
|
21 |
-
<div class="wcf-flow-steps-wrap">
|
22 |
-
<div class="wcf-flow-steps-container">
|
23 |
-
<?php if ( is_array( $options['steps'] ) ) { ?>
|
24 |
-
<?php foreach ( $options['steps'] as $index => $data ) { ?>
|
25 |
-
<?php
|
26 |
-
$term_slug = '';
|
27 |
-
$term_name = '';
|
28 |
-
$step_wrap_class = '';
|
29 |
-
$has_product_assigned = true;
|
30 |
-
$is_global_checkout = '';
|
31 |
-
$common = '';
|
32 |
-
|
33 |
-
if ( isset( $data['type'] ) ) {
|
34 |
-
$term_slug = $data['type'];
|
35 |
-
$term_name = $get_steps[ $data['type'] ];
|
36 |
-
}
|
37 |
-
|
38 |
-
if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
|
39 |
-
$step_wrap_class .= ' invalid-step';
|
40 |
-
}
|
41 |
-
|
42 |
-
if ( isset( $_GET['highlight-step-id'] ) && $_GET['highlight-step-id'] == $data['id'] ) {
|
43 |
-
$step_wrap_class .= ' wcf-new-step-highlight';
|
44 |
-
}
|
45 |
-
|
46 |
-
if ( 'checkout' === $term_slug ) {
|
47 |
-
|
48 |
-
$common = Cartflows_Helper::get_common_settings();
|
49 |
-
|
50 |
-
$is_global_checkout = (int) $common['global_checkout'];
|
51 |
-
|
52 |
-
if ( $data['id'] === $is_global_checkout ) {
|
53 |
-
$step_wrap_class .= ' wcf-global-checkout';
|
54 |
-
}
|
55 |
-
}
|
56 |
-
|
57 |
-
if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
|
58 |
-
|
59 |
-
$has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
|
60 |
-
|
61 |
-
if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
|
62 |
-
$step_wrap_class .= ' wcf-no-product-step';
|
63 |
-
}
|
64 |
-
}
|
65 |
-
|
66 |
-
?>
|
67 |
-
<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 ); ?>">
|
68 |
-
<div class="wcf-step">
|
69 |
-
<div class="wcf-step-left-content">
|
70 |
-
<span class="dashicons dashicons-menu"></span>
|
71 |
-
<span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
|
72 |
-
<span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
|
73 |
-
|
74 |
-
<?php
|
75 |
-
if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
|
76 |
-
?>
|
77 |
-
<span class="wcf-no-product-badge"><?php _e( 'No Product Assigned', 'cartflows' ); ?></span>
|
78 |
-
<?php
|
79 |
-
} elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
|
80 |
-
?>
|
81 |
-
<span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
|
82 |
-
<?php
|
83 |
-
} elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
|
84 |
-
?>
|
85 |
-
<span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout', 'cartflows' ); ?></span>
|
86 |
-
<?php
|
87 |
-
}
|
88 |
-
?>
|
89 |
-
|
90 |
-
<input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
|
91 |
-
</div>
|
92 |
-
<div class="wcf-steps-action-buttons">
|
93 |
-
<a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'View Step', 'cartflows' ); ?>" >
|
94 |
-
<span class="dashicons dashicons-visibility"></span>
|
95 |
-
<span class="wcf-step-act-btn-text">View</span>
|
96 |
-
</a>
|
97 |
-
<a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Edit Step', 'cartflows' ); ?>" >
|
98 |
-
<span class="dashicons dashicons-edit"></span>
|
99 |
-
<span class="wcf-step-act-btn-text">Edit</span>
|
100 |
-
</a>
|
101 |
-
<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 __( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
|
102 |
-
<span class="dashicons dashicons-admin-page"></span>
|
103 |
-
<span class="wcf-step-act-btn-text">Clone</span>
|
104 |
-
</a>
|
105 |
-
<a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
|
106 |
-
<span class="dashicons dashicons-trash"></span>
|
107 |
-
<span class="wcf-step-act-btn-text">Delete</span>
|
108 |
-
</a>
|
109 |
-
</div>
|
110 |
-
</div>
|
111 |
-
</div><!-- .wcf-step-wrap -->
|
112 |
-
<?php } ?>
|
113 |
-
<?php } ?>
|
114 |
-
</div><!-- .wcf-flow-steps-container -->
|
115 |
-
</div> <!-- .wcf-flow-steps-wrap -->
|
116 |
-
<div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
|
117 |
-
<?php do_action( 'cartflows_bellow_flow_steps' ); ?>
|
118 |
-
<div class='wcf-add-new-step-btn-wrap'>
|
119 |
-
<button class='wcf-trigger-popup button button-primary'>
|
120 |
-
<?php echo __( 'Add New Step', 'cartflows' ); ?>
|
121 |
-
</button>
|
122 |
-
</div>
|
123 |
-
</div><!-- .wcf-flow-buttons-wrap -->
|
124 |
-
</div><!-- .wcf-flow-settings -->
|
125 |
-
|
126 |
-
<div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
|
127 |
-
<div class="wcf-templates-popup-content">
|
128 |
-
<div class="spinner"></div>
|
129 |
-
<div class="wcf-templates-wrap wcf-templates-wrap-flows">
|
130 |
-
|
131 |
-
<div id="wcf-remote-step-actions" class="wcf-template-header">
|
132 |
-
<div class="wcf-template-logo-wrap">
|
133 |
-
<span class="wcf-cartflows-logo-img">
|
134 |
-
<span class="cartflows-icon"></span>
|
135 |
-
</span>
|
136 |
-
<span class="wcf-cartflows-title"><?php _e( 'Templates', 'cartflows' ); ?></span>
|
137 |
-
</div>
|
138 |
-
<div class="wcf-tab-wrapper">
|
139 |
-
<div id="wcf-page-builders">
|
140 |
-
<ul class="wcf-page-builder-links filter-links">
|
141 |
-
<li><a href="#" class="current" data-id="elementor"><?php _e( 'Elementor', 'cartflows' ); ?></a></li>
|
142 |
-
<li><a href="#" data-id="divi"><?php _e( 'Divi', 'cartflows' ); ?></a></li>
|
143 |
-
<li><a href="#" data-id="bb"><?php _e( 'Beaver Builder', 'cartflows' ); ?></a></li>
|
144 |
-
</ul>
|
145 |
-
</div>
|
146 |
-
</div>
|
147 |
-
<div class="wcf-popup-close-wrap">
|
148 |
-
<span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
|
149 |
-
</div>
|
150 |
-
</div>
|
151 |
-
|
152 |
-
<!--<div class="wcf-search-form">
|
153 |
-
<label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
|
154 |
-
<input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
|
155 |
-
</div>-->
|
156 |
-
<?php if ( ! _is_cartflows_pro() ) { ?>
|
157 |
-
<div class="wcf-template-notice"><p><?php echo __( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
|
158 |
-
<?php } ?>
|
159 |
-
<div id="wcf-remote-content">
|
160 |
-
<div id="wcf-remote-step-filters"></div>
|
161 |
-
<div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"></div>
|
162 |
-
<div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
|
163 |
-
</div>
|
164 |
-
</div>
|
165 |
-
</div>
|
166 |
-
</div><!-- .wcf-templates-popup-overlay -->
|
167 |
-
</div>
|
168 |
-
<?php
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* View Flow steps
|
4 |
+
*
|
5 |
+
* @package CartFlows
|
6 |
+
*/
|
7 |
+
|
8 |
+
$get_steps = array(
|
9 |
+
'landing' => __( 'Landing', 'cartflows' ),
|
10 |
+
'checkout' => __( 'Checkout', 'cartflows' ),
|
11 |
+
'thankyou' => __( 'Thank You', 'cartflows' ),
|
12 |
+
'upsell' => __( 'Upsell', 'cartflows' ),
|
13 |
+
'downsell' => __( 'Downsell', 'cartflows' ),
|
14 |
+
|
15 |
+
);
|
16 |
+
|
17 |
+
?>
|
18 |
+
<div class="wcf-flow-steps-meta-box">
|
19 |
+
<div class="wcf-flow-settings">
|
20 |
+
<?php do_action( 'cartflows_above_flow_steps' ); ?>
|
21 |
+
<div class="wcf-flow-steps-wrap">
|
22 |
+
<div class="wcf-flow-steps-container">
|
23 |
+
<?php if ( is_array( $options['steps'] ) ) { ?>
|
24 |
+
<?php foreach ( $options['steps'] as $index => $data ) { ?>
|
25 |
+
<?php
|
26 |
+
$term_slug = '';
|
27 |
+
$term_name = '';
|
28 |
+
$step_wrap_class = '';
|
29 |
+
$has_product_assigned = true;
|
30 |
+
$is_global_checkout = '';
|
31 |
+
$common = '';
|
32 |
+
|
33 |
+
if ( isset( $data['type'] ) ) {
|
34 |
+
$term_slug = $data['type'];
|
35 |
+
$term_name = $get_steps[ $data['type'] ];
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( ! _is_cartflows_pro() && ( 'upsell' === $term_slug || 'downsell' === $term_slug ) ) {
|
39 |
+
$step_wrap_class .= ' invalid-step';
|
40 |
+
}
|
41 |
+
|
42 |
+
if ( isset( $_GET['highlight-step-id'] ) && $_GET['highlight-step-id'] == $data['id'] ) {
|
43 |
+
$step_wrap_class .= ' wcf-new-step-highlight';
|
44 |
+
}
|
45 |
+
|
46 |
+
if ( 'checkout' === $term_slug ) {
|
47 |
+
|
48 |
+
$common = Cartflows_Helper::get_common_settings();
|
49 |
+
|
50 |
+
$is_global_checkout = (int) $common['global_checkout'];
|
51 |
+
|
52 |
+
if ( $data['id'] === $is_global_checkout ) {
|
53 |
+
$step_wrap_class .= ' wcf-global-checkout';
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
if ( 'upsell' === $term_slug || 'downsell' === $term_slug || 'checkout' === $term_slug ) {
|
58 |
+
|
59 |
+
$has_product_assigned = Cartflows_Helper::has_product_assigned( $data['id'] );
|
60 |
+
|
61 |
+
if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
|
62 |
+
$step_wrap_class .= ' wcf-no-product-step';
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
?>
|
67 |
+
<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 ); ?>">
|
68 |
+
<div class="wcf-step">
|
69 |
+
<div class="wcf-step-left-content">
|
70 |
+
<span class="dashicons dashicons-menu"></span>
|
71 |
+
<span><?php echo wp_trim_words( get_the_title( $data['id'] ), 3 ); ?></span>
|
72 |
+
<span class="wcf-flow-badge"><?php echo esc_attr( $term_name ); ?></span>
|
73 |
+
|
74 |
+
<?php
|
75 |
+
if ( ( ! $has_product_assigned ) && ( $data['id'] != $is_global_checkout ) ) {
|
76 |
+
?>
|
77 |
+
<span class="wcf-no-product-badge"><?php _e( 'No Product Assigned', 'cartflows' ); ?></span>
|
78 |
+
<?php
|
79 |
+
} elseif ( ( $has_product_assigned ) && ( $data['id'] === $is_global_checkout ) ) {
|
80 |
+
?>
|
81 |
+
<span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout - Remove selected checkout product', 'cartflows' ); ?></span>
|
82 |
+
<?php
|
83 |
+
} elseif ( ( ! $has_product_assigned ) && $data['id'] === $is_global_checkout ) {
|
84 |
+
?>
|
85 |
+
<span class="wcf-global-checkout-badge"><?php _e( 'Global Checkout', 'cartflows' ); ?></span>
|
86 |
+
<?php
|
87 |
+
}
|
88 |
+
?>
|
89 |
+
|
90 |
+
<input type="hidden" class="wcf-steps-hidden" name="wcf-steps[]" value="<?php echo $data['id']; ?>">
|
91 |
+
</div>
|
92 |
+
<div class="wcf-steps-action-buttons">
|
93 |
+
<a href="<?php echo get_permalink( $data['id'] ); ?>" target="_blank" class="wcf-step-view wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'View Step', 'cartflows' ); ?>" >
|
94 |
+
<span class="dashicons dashicons-visibility"></span>
|
95 |
+
<span class="wcf-step-act-btn-text">View</span>
|
96 |
+
</a>
|
97 |
+
<a href="<?php echo get_edit_post_link( $data['id'] ); ?>" class="wcf-step-edit wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Edit Step', 'cartflows' ); ?>" >
|
98 |
+
<span class="dashicons dashicons-edit"></span>
|
99 |
+
<span class="wcf-step-act-btn-text">Edit</span>
|
100 |
+
</a>
|
101 |
+
<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 __( 'Clone Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
|
102 |
+
<span class="dashicons dashicons-admin-page"></span>
|
103 |
+
<span class="wcf-step-act-btn-text">Clone</span>
|
104 |
+
</a>
|
105 |
+
<a href="#" class="wcf-step-delete wcf-action-button wp-ui-text-highlight" title="<?php echo __( 'Delete Step', 'cartflows' ); ?>" data-id="<?php echo $data['id']; ?>">
|
106 |
+
<span class="dashicons dashicons-trash"></span>
|
107 |
+
<span class="wcf-step-act-btn-text">Delete</span>
|
108 |
+
</a>
|
109 |
+
</div>
|
110 |
+
</div>
|
111 |
+
</div><!-- .wcf-step-wrap -->
|
112 |
+
<?php } ?>
|
113 |
+
<?php } ?>
|
114 |
+
</div><!-- .wcf-flow-steps-container -->
|
115 |
+
</div> <!-- .wcf-flow-steps-wrap -->
|
116 |
+
<div class="wcf-flow-buttons-wrap"> <!-- .wcf-flow-buttons-wrap -->
|
117 |
+
<?php do_action( 'cartflows_bellow_flow_steps' ); ?>
|
118 |
+
<div class='wcf-add-new-step-btn-wrap'>
|
119 |
+
<button class='wcf-trigger-popup button button-primary'>
|
120 |
+
<?php echo __( 'Add New Step', 'cartflows' ); ?>
|
121 |
+
</button>
|
122 |
+
</div>
|
123 |
+
</div><!-- .wcf-flow-buttons-wrap -->
|
124 |
+
</div><!-- .wcf-flow-settings -->
|
125 |
+
|
126 |
+
<div id="wcf-remote-step-importer" class="wcf-templates-popup-overlay">
|
127 |
+
<div class="wcf-templates-popup-content">
|
128 |
+
<div class="spinner"></div>
|
129 |
+
<div class="wcf-templates-wrap wcf-templates-wrap-flows">
|
130 |
+
|
131 |
+
<div id="wcf-remote-step-actions" class="wcf-template-header">
|
132 |
+
<div class="wcf-template-logo-wrap">
|
133 |
+
<span class="wcf-cartflows-logo-img">
|
134 |
+
<span class="cartflows-icon"></span>
|
135 |
+
</span>
|
136 |
+
<span class="wcf-cartflows-title"><?php _e( 'Templates', 'cartflows' ); ?></span>
|
137 |
+
</div>
|
138 |
+
<div class="wcf-tab-wrapper">
|
139 |
+
<div id="wcf-page-builders">
|
140 |
+
<ul class="wcf-page-builder-links filter-links">
|
141 |
+
<li><a href="#" class="current" data-id="elementor"><?php _e( 'Elementor', 'cartflows' ); ?></a></li>
|
142 |
+
<li><a href="#" data-id="divi"><?php _e( 'Divi', 'cartflows' ); ?></a></li>
|
143 |
+
<li><a href="#" data-id="bb"><?php _e( 'Beaver Builder', 'cartflows' ); ?></a></li>
|
144 |
+
</ul>
|
145 |
+
</div>
|
146 |
+
</div>
|
147 |
+
<div class="wcf-popup-close-wrap">
|
148 |
+
<span class="close-icon"><span class="wcf-cartflow-icons dashicons dashicons-no"></span></span>
|
149 |
+
</div>
|
150 |
+
</div>
|
151 |
+
|
152 |
+
<!--<div class="wcf-search-form">
|
153 |
+
<label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'cartflows' ); ?> </label>
|
154 |
+
<input placeholder="<?php _e( 'Search Flow...', 'cartflows' ); ?>" type="text" aria-describedby="live-search-desc" class="wcf-flow-search-input">
|
155 |
+
</div>-->
|
156 |
+
<?php if ( ! _is_cartflows_pro() ) { ?>
|
157 |
+
<div class="wcf-template-notice"><p><?php echo __( 'You need a Cartflows Pro version to import Upsell / Downsell', 'cartflows' ); ?></p></div>
|
158 |
+
<?php } ?>
|
159 |
+
<div id="wcf-remote-content">
|
160 |
+
<div id="wcf-remote-step-filters"></div>
|
161 |
+
<div id="wcf-remote-step-list" class="wcf-remote-list wcf-template-list-wrap"></div>
|
162 |
+
<div id="wcf-upcoming-page-builders" style="display: none;" class="wcf-remote-list wcf-template-list-wrap"></div>
|
163 |
+
</div>
|
164 |
+
</div>
|
165 |
+
</div>
|
166 |
+
</div><!-- .wcf-templates-popup-overlay -->
|
167 |
+
</div>
|
168 |
+
<?php
|
modules/thankyou/classes/class-cartflows-thankyou-markup.php
CHANGED
@@ -1,260 +1,260 @@
|
|
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 |
-
* 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 |
-
/* Downsell Shortcode */
|
38 |
-
add_shortcode( 'cartflows_order_details', array( $this, 'cartflows_order_details_shortcode_markup' ) );
|
39 |
-
|
40 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'thank_you_scripts' ), 21 );
|
41 |
-
|
42 |
-
add_action( 'woocommerce_is_order_received_page', array( $this, 'set_order_received_page' ) );
|
43 |
-
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Order shortcode markup
|
48 |
-
*
|
49 |
-
* @param array $atts attributes.
|
50 |
-
* @since 1.0.0
|
51 |
-
*/
|
52 |
-
function cartflows_order_details_shortcode_markup( $atts ) {
|
53 |
-
|
54 |
-
$output = '';
|
55 |
-
|
56 |
-
if ( _is_wcf_thankyou_type() ) {
|
57 |
-
|
58 |
-
/* Remove order item link */
|
59 |
-
add_filter( 'woocommerce_order_item_permalink', '__return_false' );
|
60 |
-
|
61 |
-
if ( ! function_exists( 'wc_print_notices' ) ) {
|
62 |
-
return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
|
63 |
-
}
|
64 |
-
|
65 |
-
wc_print_notices();
|
66 |
-
|
67 |
-
$order = false;
|
68 |
-
|
69 |
-
if ( ! isset( $_GET['wcf-order'] ) && wcf()->flow->is_flow_testmode() ) {
|
70 |
-
|
71 |
-
$args = array(
|
72 |
-
'limit' => 1,
|
73 |
-
'order' => 'DESC',
|
74 |
-
'status' => array( 'completed', 'processing' ),
|
75 |
-
);
|
76 |
-
|
77 |
-
$latest_order = wc_get_orders( $args );
|
78 |
-
|
79 |
-
$order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
|
80 |
-
|
81 |
-
if ( $order_id > 0 ) {
|
82 |
-
|
83 |
-
$order = wc_get_order( $order_id );
|
84 |
-
|
85 |
-
if ( ! $order ) {
|
86 |
-
$order = false;
|
87 |
-
}
|
88 |
-
}
|
89 |
-
} else {
|
90 |
-
if ( ! isset( $_GET['wcf-order'] ) ) {
|
91 |
-
return '<p class="woocommerce-notice">Order not found. You cannot access this page directly.</p>';
|
92 |
-
}
|
93 |
-
|
94 |
-
// Get the order.
|
95 |
-
$order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET['wcf-order'] ) ? 0 : intval( $_GET['wcf-order'] ) );
|
96 |
-
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['wcf-key'] ) ? '' : wc_clean( wp_unslash( $_GET['wcf-key'] ) ) ); // WPCS: input var ok, CSRF ok.
|
97 |
-
|
98 |
-
if ( $order_id > 0 ) {
|
99 |
-
|
100 |
-
$order = wc_get_order( $order_id );
|
101 |
-
|
102 |
-
if ( ! $order || $order->get_order_key() !== $order_key ) {
|
103 |
-
$order = false;
|
104 |
-
}
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
// Empty awaiting payment session.
|
109 |
-
unset( WC()->session->order_awaiting_payment );
|
110 |
-
|
111 |
-
// Empty current cart.
|
112 |
-
wc_empty_cart();
|
113 |
-
|
114 |
-
ob_start();
|
115 |
-
echo "<div class='wcf-thankyou-wrap'>";
|
116 |
-
wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
|
117 |
-
echo '</div>';
|
118 |
-
$output = ob_get_clean();
|
119 |
-
}
|
120 |
-
|
121 |
-
return $output;
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Load Thank You scripts.
|
126 |
-
*
|
127 |
-
* @return void
|
128 |
-
*/
|
129 |
-
function thank_you_scripts() {
|
130 |
-
|
131 |
-
if ( _is_wcf_thankyou_type() ) {
|
132 |
-
|
133 |
-
do_action( 'cartflows_thank_you_scripts' );
|
134 |
-
|
135 |
-
$style = $this->generate_thank_you_style();
|
136 |
-
|
137 |
-
wp_add_inline_style( 'wcf-frontend-global', $style );
|
138 |
-
}
|
139 |
-
}
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Set thank you as a order received page.
|
143 |
-
*
|
144 |
-
* @param boolean $is_order_page order page.
|
145 |
-
* @return boolean
|
146 |
-
*/
|
147 |
-
function set_order_received_page( $is_order_page ) {
|
148 |
-
|
149 |
-
if ( _is_wcf_thankyou_type() ) {
|
150 |
-
|
151 |
-
$is_order_page = true;
|
152 |
-
}
|
153 |
-
|
154 |
-
return $is_order_page;
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Generate Thank You Styles.
|
159 |
-
*
|
160 |
-
* @return string
|
161 |
-
*/
|
162 |
-
function generate_thank_you_style() {
|
163 |
-
|
164 |
-
global $post;
|
165 |
-
|
166 |
-
if ( _is_wcf_thankyou_type() ) {
|
167 |
-
$thank_you_id = $post->ID;
|
168 |
-
} else {
|
169 |
-
$thank_you_id = _get_wcf_thankyou_id( $post->post_content );
|
170 |
-
}
|
171 |
-
|
172 |
-
CartFlows_Font_Families::render_fonts( $thank_you_id );
|
173 |
-
|
174 |
-
$text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text-color' );
|
175 |
-
$text_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-family' );
|
176 |
-
$heading_text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-color' );
|
177 |
-
$heading_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-family' );
|
178 |
-
$heading_font_weight = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-wt' );
|
179 |
-
$container_width = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-container-width' );
|
180 |
-
$section_bg_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-section-bg-color' );
|
181 |
-
|
182 |
-
$show_order_review = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-overview-section' );
|
183 |
-
|
184 |
-
$show_order_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-details-section' );
|
185 |
-
|
186 |
-
$show_billing_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-billing-section' );
|
187 |
-
|
188 |
-
$show_shipping_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-shipping-section' );
|
189 |
-
|
190 |
-
$output = "
|
191 |
-
.wcf-thankyou-wrap{
|
192 |
-
color: {$text_color};
|
193 |
-
font-family: {$text_font_family};
|
194 |
-
max-width:{$container_width}px;
|
195 |
-
}
|
196 |
-
|
197 |
-
.woocommerce-order h2.woocommerce-column__title,
|
198 |
-
.woocommerce-order h2.woocommerce-order-details__title,
|
199 |
-
.woocommerce-order .woocommerce-thankyou-order-received,
|
200 |
-
.woocommerce-order-details h2 {
|
201 |
-
color: {$heading_text_color};
|
202 |
-
font-family: {$heading_font_family};
|
203 |
-
font-weight: {$heading_font_weight};
|
204 |
-
}
|
205 |
-
|
206 |
-
.woocommerce-order ul.order_details,
|
207 |
-
.woocommerce-order .woocommerce-order-details,
|
208 |
-
.woocommerce-order .woocommerce-customer-details{
|
209 |
-
background-color: {$section_bg_color}
|
210 |
-
}
|
211 |
-
";
|
212 |
-
|
213 |
-
if ( 'no' == $show_order_review ) {
|
214 |
-
$output .= '
|
215 |
-
.woocommerce-order ul.order_details{
|
216 |
-
display: none;
|
217 |
-
}
|
218 |
-
';
|
219 |
-
}
|
220 |
-
|
221 |
-
if ( 'no' == $show_order_details ) {
|
222 |
-
$output .= '
|
223 |
-
.woocommerce-order .woocommerce-order-details{
|
224 |
-
display: none;
|
225 |
-
}
|
226 |
-
';
|
227 |
-
}
|
228 |
-
|
229 |
-
if ( 'no' == $show_billing_details ) {
|
230 |
-
$output .= '
|
231 |
-
.woocommerce-order .woocommerce-customer-details .woocommerce-column--billing-address{
|
232 |
-
display: none;
|
233 |
-
}
|
234 |
-
';
|
235 |
-
}
|
236 |
-
|
237 |
-
if ( 'no' == $show_shipping_details ) {
|
238 |
-
$output .= '
|
239 |
-
.woocommerce-order .woocommerce-customer-details .woocommerce-column--shipping-address{
|
240 |
-
display: none;
|
241 |
-
}
|
242 |
-
';
|
243 |
-
}
|
244 |
-
|
245 |
-
if ( 'no' == $show_billing_details && 'no' == $show_shipping_details ) {
|
246 |
-
$output .= '
|
247 |
-
.woocommerce-order .woocommerce-customer-details{
|
248 |
-
display: none;
|
249 |
-
}
|
250 |
-
';
|
251 |
-
}
|
252 |
-
|
253 |
-
return $output;
|
254 |
-
}
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* Kicking this off by calling 'get_instance()' method
|
259 |
-
*/
|
260 |
-
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 |
+
* 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 |
+
/* Downsell Shortcode */
|
38 |
+
add_shortcode( 'cartflows_order_details', array( $this, 'cartflows_order_details_shortcode_markup' ) );
|
39 |
+
|
40 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'thank_you_scripts' ), 21 );
|
41 |
+
|
42 |
+
add_action( 'woocommerce_is_order_received_page', array( $this, 'set_order_received_page' ) );
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Order shortcode markup
|
48 |
+
*
|
49 |
+
* @param array $atts attributes.
|
50 |
+
* @since 1.0.0
|
51 |
+
*/
|
52 |
+
function cartflows_order_details_shortcode_markup( $atts ) {
|
53 |
+
|
54 |
+
$output = '';
|
55 |
+
|
56 |
+
if ( _is_wcf_thankyou_type() ) {
|
57 |
+
|
58 |
+
/* Remove order item link */
|
59 |
+
add_filter( 'woocommerce_order_item_permalink', '__return_false' );
|
60 |
+
|
61 |
+
if ( ! function_exists( 'wc_print_notices' ) ) {
|
62 |
+
return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
|
63 |
+
}
|
64 |
+
|
65 |
+
wc_print_notices();
|
66 |
+
|
67 |
+
$order = false;
|
68 |
+
|
69 |
+
if ( ! isset( $_GET['wcf-order'] ) && wcf()->flow->is_flow_testmode() ) {
|
70 |
+
|
71 |
+
$args = array(
|
72 |
+
'limit' => 1,
|
73 |
+
'order' => 'DESC',
|
74 |
+
'status' => array( 'completed', 'processing' ),
|
75 |
+
);
|
76 |
+
|
77 |
+
$latest_order = wc_get_orders( $args );
|
78 |
+
|
79 |
+
$order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
|
80 |
+
|
81 |
+
if ( $order_id > 0 ) {
|
82 |
+
|
83 |
+
$order = wc_get_order( $order_id );
|
84 |
+
|
85 |
+
if ( ! $order ) {
|
86 |
+
$order = false;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
} else {
|
90 |
+
if ( ! isset( $_GET['wcf-order'] ) ) {
|
91 |
+
return '<p class="woocommerce-notice">Order not found. You cannot access this page directly.</p>';
|
92 |
+
}
|
93 |
+
|
94 |
+
// Get the order.
|
95 |
+
$order_id = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET['wcf-order'] ) ? 0 : intval( $_GET['wcf-order'] ) );
|
96 |
+
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['wcf-key'] ) ? '' : wc_clean( wp_unslash( $_GET['wcf-key'] ) ) ); // WPCS: input var ok, CSRF ok.
|
97 |
+
|
98 |
+
if ( $order_id > 0 ) {
|
99 |
+
|
100 |
+
$order = wc_get_order( $order_id );
|
101 |
+
|
102 |
+
if ( ! $order || $order->get_order_key() !== $order_key ) {
|
103 |
+
$order = false;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
// Empty awaiting payment session.
|
109 |
+
unset( WC()->session->order_awaiting_payment );
|
110 |
+
|
111 |
+
// Empty current cart.
|
112 |
+
wc_empty_cart();
|
113 |
+
|
114 |
+
ob_start();
|
115 |
+
echo "<div class='wcf-thankyou-wrap'>";
|
116 |
+
wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
|
117 |
+
echo '</div>';
|
118 |
+
$output = ob_get_clean();
|
119 |
+
}
|
120 |
+
|
121 |
+
return $output;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Load Thank You scripts.
|
126 |
+
*
|
127 |
+
* @return void
|
128 |
+
*/
|
129 |
+
function thank_you_scripts() {
|
130 |
+
|
131 |
+
if ( _is_wcf_thankyou_type() ) {
|
132 |
+
|
133 |
+
do_action( 'cartflows_thank_you_scripts' );
|
134 |
+
|
135 |
+
$style = $this->generate_thank_you_style();
|
136 |
+
|
137 |
+
wp_add_inline_style( 'wcf-frontend-global', $style );
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Set thank you as a order received page.
|
143 |
+
*
|
144 |
+
* @param boolean $is_order_page order page.
|
145 |
+
* @return boolean
|
146 |
+
*/
|
147 |
+
function set_order_received_page( $is_order_page ) {
|
148 |
+
|
149 |
+
if ( _is_wcf_thankyou_type() ) {
|
150 |
+
|
151 |
+
$is_order_page = true;
|
152 |
+
}
|
153 |
+
|
154 |
+
return $is_order_page;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Generate Thank You Styles.
|
159 |
+
*
|
160 |
+
* @return string
|
161 |
+
*/
|
162 |
+
function generate_thank_you_style() {
|
163 |
+
|
164 |
+
global $post;
|
165 |
+
|
166 |
+
if ( _is_wcf_thankyou_type() ) {
|
167 |
+
$thank_you_id = $post->ID;
|
168 |
+
} else {
|
169 |
+
$thank_you_id = _get_wcf_thankyou_id( $post->post_content );
|
170 |
+
}
|
171 |
+
|
172 |
+
CartFlows_Font_Families::render_fonts( $thank_you_id );
|
173 |
+
|
174 |
+
$text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-text-color' );
|
175 |
+
$text_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-font-family' );
|
176 |
+
$heading_text_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-color' );
|
177 |
+
$heading_font_family = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-family' );
|
178 |
+
$heading_font_weight = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-heading-font-wt' );
|
179 |
+
$container_width = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-container-width' );
|
180 |
+
$section_bg_color = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-tq-section-bg-color' );
|
181 |
+
|
182 |
+
$show_order_review = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-overview-section' );
|
183 |
+
|
184 |
+
$show_order_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-details-section' );
|
185 |
+
|
186 |
+
$show_billing_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-billing-section' );
|
187 |
+
|
188 |
+
$show_shipping_details = wcf()->options->get_thankyou_meta_value( $thank_you_id, 'wcf-show-shipping-section' );
|
189 |
+
|
190 |
+
$output = "
|
191 |
+
.wcf-thankyou-wrap{
|
192 |
+
color: {$text_color};
|
193 |
+
font-family: {$text_font_family};
|
194 |
+
max-width:{$container_width}px;
|
195 |
+
}
|
196 |
+
|
197 |
+
.woocommerce-order h2.woocommerce-column__title,
|
198 |
+
.woocommerce-order h2.woocommerce-order-details__title,
|
199 |
+
.woocommerce-order .woocommerce-thankyou-order-received,
|
200 |
+
.woocommerce-order-details h2 {
|
201 |
+
color: {$heading_text_color};
|
202 |
+
font-family: {$heading_font_family};
|
203 |
+
font-weight: {$heading_font_weight};
|
204 |
+
}
|
205 |
+
|
206 |
+
.woocommerce-order ul.order_details,
|
207 |
+
.woocommerce-order .woocommerce-order-details,
|
208 |
+
.woocommerce-order .woocommerce-customer-details{
|
209 |
+
background-color: {$section_bg_color}
|
210 |
+
}
|
211 |
+
";
|
212 |
+
|
213 |
+
if ( 'no' == $show_order_review ) {
|
214 |
+
$output .= '
|
215 |
+
.woocommerce-order ul.order_details{
|
216 |
+
display: none;
|
217 |
+
}
|
218 |
+
';
|
219 |
+
}
|
220 |
+
|
221 |
+
if ( 'no' == $show_order_details ) {
|
222 |
+
$output .= '
|
223 |
+
.woocommerce-order .woocommerce-order-details{
|
224 |
+
display: none;
|
225 |
+
}
|
226 |
+
';
|
227 |
+
}
|
228 |
+
|
229 |
+
if ( 'no' == $show_billing_details ) {
|
230 |
+
$output .= '
|
231 |
+
.woocommerce-order .woocommerce-customer-details .woocommerce-column--billing-address{
|
232 |
+
display: none;
|
233 |
+
}
|
234 |
+
';
|
235 |
+
}
|
236 |
+
|
237 |
+
if ( 'no' == $show_shipping_details ) {
|
238 |
+
$output .= '
|
239 |
+
.woocommerce-order .woocommerce-customer-details .woocommerce-column--shipping-address{
|
240 |
+
display: none;
|
241 |
+
}
|
242 |
+
';
|
243 |
+
}
|
244 |
+
|
245 |
+
if ( 'no' == $show_billing_details && 'no' == $show_shipping_details ) {
|
246 |
+
$output .= '
|
247 |
+
.woocommerce-order .woocommerce-customer-details{
|
248 |
+
display: none;
|
249 |
+
}
|
250 |
+
';
|
251 |
+
}
|
252 |
+
|
253 |
+
return $output;
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Kicking this off by calling 'get_instance()' method
|
259 |
+
*/
|
260 |
+
Cartflows_Thankyou_Markup::get_instance();
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, cart
|
|
5 |
Requires at least: 4.4
|
6 |
Requires PHP: 5.6
|
7 |
Tested up to: 5.0
|
8 |
-
Stable tag: 1.1.0
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -13,7 +13,79 @@ Create beautiful checkout pages & sales flows for WooCommerce.
|
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
== Installation ==
|
19 |
|
@@ -21,6 +93,8 @@ Create beautiful checkout pages & sales flows for WooCommerce.
|
|
21 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
22 |
|
23 |
== Changelog ==
|
|
|
|
|
24 |
|
25 |
Version 1.1.0 - Wednesday, 5th December 2018
|
26 |
* New: Ready for Order Bump Positions.
|
5 |
Requires at least: 4.4
|
6 |
Requires PHP: 5.6
|
7 |
Tested up to: 5.0
|
8 |
+
Stable tag: 1.1.0.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
+
**#1 Funnel Builder For WordPress**
|
17 |
+
★★★★★<br>
|
18 |
+
|
19 |
+
**Funnels are the most effective way to sell products & services.** We created <a href="https://cartflows.com" target="_blank">**CartFlows, a WordPress Funnel Builder**</a>, to help every website owner start using funnels to grow their business, generate more reveue, and have full control over their buyers journey.
|
20 |
+
## <center><a href="https://demos.cartflows.com/" target="_blank">Try The Demo</a></center> ##
|
21 |
+
|
22 |
+
[youtube https://www.youtube.com/watch?v=SlE0moPKjMY]
|
23 |
+
|
24 |
+
Turn your WooCommerce website into a selling machine using one-click sales funnels with frictionless checkout, custom thank you pages, global checkout replacement, and more…
|
25 |
+
|
26 |
+
CartFlows is the best and easiest way to sell product and services on your website. With our library of done for you, one-click sales funnels, that literally sell your products and services for you.
|
27 |
+
|
28 |
+
## CARTFLOWS IS PERFECT FOR ##
|
29 |
+
|
30 |
+
* **Selling Online Courses**
|
31 |
+
* **Selling Event Tickets**
|
32 |
+
* **Selling Services**
|
33 |
+
* **Selling Info Product**
|
34 |
+
* **Selling Physical Products**
|
35 |
+
* **Selling Via Dropshipping**
|
36 |
+
* **Selling Anything Really**
|
37 |
+
|
38 |
+
CartFlows is the perfect <a href="https://cartflows.com/clickfunnels-alternative" target="_blank">ClickFunnels Alternative</a> because its built on the worlds most open platform, WordPress.
|
39 |
+
|
40 |
+
### CARTFLOWS GAME-CHANGING FEATURES ###
|
41 |
+
|
42 |
+
See the features that make CartFlows the **Best Funnel Builder for WordPress**.
|
43 |
+
|
44 |
+
* **Ready to Import Templates:**
|
45 |
+
Choose from a wide variety of high converting templates. You can add a professionally crafted, multistep funnel, with one mouse click or you can build your own funnel and choose individual templates.
|
46 |
+
|
47 |
+
* **Use Your Page Builder Or Gutenberg:**
|
48 |
+
CartFlows will work with all popular page builders including Gutenberg. Initially we will offer templates for Beaver Builder, Elementor with Brizy and Divi coming soon. However you can use CartFlows with your own templates.
|
49 |
+
|
50 |
+
* **Conversion Tested Checkout:**
|
51 |
+
CartFlows replaces your complicated checkout process with our optimized checkout that instantly increases conversions, making you more money.
|
52 |
+
|
53 |
+
* **Custom Next Step Thank You Pages:**
|
54 |
+
Your buyers journey doesnt end after checkout. With CartFlows and our custom thank you page feautre, you can guild your new customer on their next steps.
|
55 |
+
|
56 |
+
* **WooCommerce Checkout Page Replacement**
|
57 |
+
Say goodby to using the same ridgid checkout page that everyone else is using. Create the perfect WooCommerce checkout page and assign it to be the default WooCommerce checkout template.
|
58 |
+
|
59 |
+
### Why is CartFlows such a game-changer? ###
|
60 |
+
|
61 |
+
* **Sales Funnel Tools Are Expensive** — Most sales funnel tools carry a hefty monthly fee from $97 - $297 per month and they are worth every penny because funnels work. With CartFlows you can unleash the power of funnels for free.
|
62 |
+
|
63 |
+
* **Sales Funnel Tools Are Complicated** — Most sales funnel tools are frustrating to use. You are stuck using their clunky page builer and have to go through an entirely new learnign curve. Who has time for that? With CartFlows you will feel right at home.
|
64 |
+
|
65 |
+
* **Sales Funnel Tools Are Closed** — Perhaps the worst part of using other funnel builder tools is they are based on a closed platform which limits you in every way. CartFlows is open and sits on top of WordPress and WooCommerce.
|
66 |
+
|
67 |
+
* **Sales Funnel Tools Lock You In** — We believe in using a platform where everything is on your domain and you control all your data. CartFlows puts you in control and in the drivers seat.
|
68 |
+
|
69 |
+
### Who Can Benefit From CartFlows? ###
|
70 |
+
|
71 |
+
#### CartFlows Funnel Builder Plugin is perfect for: ####
|
72 |
+
✔ Bloggers
|
73 |
+
✔ Course Creators
|
74 |
+
✔ Coaches / Trainers
|
75 |
+
✔ Dropshippers
|
76 |
+
✔ eCommerce Store Owners
|
77 |
+
✔ Niche Sites
|
78 |
+
✔ Businesses
|
79 |
+
✔ Local Businesses
|
80 |
+
✔ Startups
|
81 |
+
✔ Personal Brands
|
82 |
+
✔ Real Estate Agents
|
83 |
+
✔ Artists & Photographers
|
84 |
+
✔ All WordPress Websites
|
85 |
+
|
86 |
+
## JOIN THE CARTFLOWS INNER CIRCLE ##
|
87 |
+
|
88 |
+
**<a href="https://www.facebook.com/groups/cartflows/" target="_blank">JOIN OUR FACEBOOK GROUP COMMUNITY</a>**: Learn the tactics and techniques that other CartFlows users are doing to grow their businesses. Also get exciting insider information on upcoming feature releases.
|
89 |
|
90 |
== Installation ==
|
91 |
|
93 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
94 |
|
95 |
== Changelog ==
|
96 |
+
Version 1.1.0.1 - Friday, 7th December 2018
|
97 |
+
* Fix: Checkout breaking issue.
|
98 |
|
99 |
Version 1.1.0 - Wednesday, 5th December 2018
|
100 |
* New: Ready for Order Bump Positions.
|