PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.7.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.7.0
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
← All changes | includes/funnel/steps/upsell.php +41 -36 1.2.32.7.0 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace Sellkit\Funnel\Steps;
4 4
5 5 use Sellkit\Funnel\Analytics\Data_Updater;
6 +use Sellkit\Funnel\Contacts\Base_Contacts;
6 7 use Sellkit_Funnel;
7 8
8 9 defined( 'ABSPATH' ) || die();
9 10
@@ -13,8 +14,16 @@
13 14 * @since 1.1.0
14 15 */
15 16 class Upsell {
16 17 /**
18 + * Current funnel.
19 + *
20 + * @since 1.8.6
21 + * @var Sellkit_Funnel
22 + */
23 + public $funnel;
24 +
25 + /**
17 26 * Upsell constructor.
18 27 *
19 28 * @since 1.1.0
20 29 */
@@ -31,8 +40,10 @@
31 40 * @since 1.1.0
32 41 * @SuppressWarnings(PHPMD.NPathComplexity)
33 42 */
34 43 public function upsell_handler() {
44 + check_ajax_referer( 'sellkit_elementor', 'nonce' );
45 +
35 46 $order_key = sellkit_htmlspecialchars( INPUT_POST, 'order_key' );
36 47 $offer_type = sellkit_htmlspecialchars( INPUT_POST, 'offer_type' );
37 48
38 49 if ( empty( $order_key ) ) {
@@ -41,18 +52,26 @@
41 52
42 53 $order_id = wc_get_order_id_by_order_key( $order_key );
43 54 $main_order = new \WC_Order( $order_id );
44 55
45 - if ( empty( $this->funnel->next_step_data['page_id'] ) ) {
46 - wp_send_json_error( __( 'Please add thank you page step', 'sellkit' ) );
56 + if (
57 + empty( $this->funnel->next_no_step_data['page_id'] ) &&
58 + empty( $this->funnel->next_step_data['page_id'] ) &&
59 + ! empty( $this->funnel->end_node_step_data['page_id'] )
60 + ) {
61 + $next_step_link = add_query_arg( [ 'order-key' => $main_order->get_order_key() ], get_permalink( $this->funnel->end_node_step_data['page_id'] ) );
62 +
63 + wp_send_json_success( $next_step_link );
47 64 }
48 65
49 - if ( 'reject' === $offer_type && ! empty( $this->funnel->next_step_data['page_id'] ) ) {
50 - $next_step_link = add_query_arg( [ 'order-key' => $main_order->get_order_key() ], get_permalink( $this->funnel->next_step_data['page_id'] ) );
66 + if ( 'reject' === $offer_type && ! empty( $this->funnel->next_no_step_data['page_id'] ) ) {
67 + $next_step_link = add_query_arg( [ 'order-key' => $main_order->get_order_key() ], get_permalink( $this->funnel->next_no_step_data['page_id'] ) );
51 68
52 69 wp_send_json_success( $next_step_link );
53 70 }
54 71
72 + Base_Contacts::step_is_passed();
73 +
55 74 $billing_address = $main_order->get_address();
56 75 $shipping_address = $main_order->get_address( 'shipping' );
57 76 $products = $this->funnel->current_step_data['data']['products']['list'];
58 77
@@ -75,8 +94,10 @@
75 94 $order->set_address( $billing_address );
76 95 $order->set_address( $shipping_address, 'shipping' );
77 96 $order->set_payment_method( $main_order->get_payment_method() );
78 97 $order->set_total( $order_total );
98 + $order->set_customer_id( get_current_user_id() );
99 + $order->update_meta_data( 'sellkit_funnel_id', $this->funnel->funnel_id );
79 100 $order->update_meta_data( 'sellkit_main_order_id', $main_order->get_id() );
80 101
81 102 if ( ! empty( $this->funnel->next_step_data ) ) {
82 103 $order->update_meta_data( 'sellkit_funnel_next_step_data', $this->funnel->next_step_data );
@@ -81,8 +102,17 @@
81 102 if ( ! empty( $this->funnel->next_step_data ) ) {
82 103 $order->update_meta_data( 'sellkit_funnel_next_step_data', $this->funnel->next_step_data );
83 104 }
84 105
106 + if (
107 + empty( $this->funnel->next_step_data ) &&
108 + ! empty( $this->funnel->current_step_data['targets'][0]['nodeId'] ) &&
109 + 'none' === $this->funnel->current_step_data['targets'][0]['nodeId'] &&
110 + ! empty( $this->funnel->end_node_step_data )
111 + ) {
112 + $order->update_meta_data( 'sellkit_funnel_next_step_data', $this->funnel->end_node_step_data );
113 + }
114 +
85 115 $order->save();
86 116
87 117 $analytics_updater = new Data_Updater();
88 118
@@ -137,45 +167,20 @@
137 167 * @since 1.1.0
138 168 * @SuppressWarnings(PHPMD.NPathComplexity)
139 169 */
140 170 public function do_actions() {
141 - $conditions = ! empty( $this->funnel->current_step_data['data']['conditions'] ) ? $this->funnel->current_step_data['data']['conditions'] : [];
142 - $is_valid = true;
143 - $condition_type = ! empty( $condition[1]['type'] ) ? $condition[1]['type'] : 'and';
171 + $conditions = ! empty( $this->funnel->current_step_data['data']['conditions'] ) ? $this->funnel->current_step_data['data']['conditions'] : [];
172 + $is_valid = sellkit_conditions_validation( $conditions );
144 173
145 - if ( 'or' === $condition_type ) {
146 - $is_valid = false;
147 - }
174 + $args = [];
148 175
149 - foreach ( $conditions as $condition ) {
150 - if ( is_array( $condition['condition_value'] ) ) {
151 - $condition['condition_value'] = sellkit_get_multi_select_values( $condition['condition_value'] );
152 - }
153 -
154 - $result = sellkit_condition_match( $condition['condition_subject'], $condition['condition_operator'], $condition['condition_value'] );
155 -
156 - if ( is_wp_error( $result ) ) {
157 - continue;
158 - }
159 -
160 - if ( ! $result ) {
161 - $is_valid = false;
162 - }
163 -
164 - if ( $result && 'or' === $condition_type ) {
165 - $is_valid = true;
166 - break;
167 - }
176 + if ( ! empty( $_GET['order-key'] ) ) { // phpcs:ignore
177 + $args['order-key'] = $_GET['order-key']; // phpcs:ignore
168 178 }
169 179
170 - if ( ! $is_valid ) {
171 - $args = [];
172 -
173 - if ( ! empty( $_GET['order-key'] ) ) { // phpcs:ignore
174 - $args['order-key'] = $_GET['order-key']; // phpcs:ignore
175 - }
176 -
180 + if ( ! $is_valid && ! empty( $this->funnel->next_step_data['page_id'] ) ) {
177 181 wp_safe_redirect( add_query_arg( $args, get_permalink( $this->funnel->next_step_data['page_id'] ) ) );
182 + exit;
178 183 }
179 184 }
180 185
181 186 /**