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/functions.php +75 -2 1.2.12.7.0 View file →
@@ -1,5 +1,7 @@
1 1 <?php
2 +defined( 'ABSPATH' ) || exit;
3 +
2 4 if ( ! function_exists( 'sellkit_update_option' ) ) {
3 5 /**
4 6 * Update option from options storage.
5 7 *
@@ -70,8 +72,24 @@
70 72 return $value;
71 73 }
72 74 }
73 75
76 +if ( ! function_exists( 'sellkit_decode_entity_title' ) ) {
77 + /**
78 + * Decode HTML entities in titles for JSON/React (fixes literal &#8211; etc. in chart headers).
79 + *
80 + * @param string $title Title string.
81 + * @return string
82 + */
83 + function sellkit_decode_entity_title( $title ) {
84 + if ( ! is_string( $title ) || '' === $title ) {
85 + return $title;
86 + }
87 +
88 + return html_entity_decode( $title, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
89 + }
90 +}
91 +
74 92 /**
75 93 * Delete option from options storage.
76 94 *
77 95 * @param string $option Option name.
@@ -117,11 +135,17 @@
117 135 * @SuppressWarnings(PHPMD.NPathComplexity)
118 136 * @param array $conditions Conditions data.
119 137 */
120 138 function sellkit_conditions_validation( $conditions ) {
121 - $is_valid = true;
122 - $condition_type = ! empty( $conditions[1]['type'] ) ? $conditions[1]['type'] : 'and';
139 + $is_valid = true;
123 140
141 + if ( empty( $conditions ) ) {
142 + return true;
143 + }
144 +
145 + $first_condition = reset( $conditions );
146 + $condition_type = ! empty( $first_condition['type'] ) ? $first_condition['type'] : 'and';
147 +
124 148 if ( 'or' === $condition_type ) {
125 149 $is_valid = false;
126 150 }
127 151
@@ -150,5 +174,54 @@
150 174 return true;
151 175 }
152 176
153 177 return false;
178 +}
179 +
180 +if ( ! function_exists( 'array_key_last' ) ) {
181 + /**
182 + * Adds support for array_key_last function for lower php than 7.3.0 & WP lower than 5.9.0.
183 + *
184 + * @param array $array array.
185 + */
186 + function array_key_last( $array ) {
187 + if ( empty( $array ) ) {
188 + return null;
189 + }
190 +
191 + end( $array );
192 + return key( $array );
193 + }
194 +}
195 +
196 +add_action( 'woocommerce_removed_coupon', 'sellkit_set_cookie_after_auto_apply_coupon_removed', 10, 1 );
197 +
198 +/**
199 + * Create cookie for deleted auto apply coupon.
200 + *
201 + * @param string $coupon_code coupon code.
202 + */
203 +function sellkit_set_cookie_after_auto_apply_coupon_removed( $coupon_code ) {
204 + $cookie_value = null;
205 + $parsed_url = wp_parse_url( site_url() );
206 + $domain = $parsed_url['host'];
207 +
208 + if ( isset( $_COOKIE['sellkit_rejected_coupon'] ) ) {
209 + $cookie_value = sanitize_text_field( wp_unslash( $_COOKIE['sellkit_rejected_coupon'] ) );
210 + }
211 +
212 + $cookie_value = $cookie_value . ',' . $coupon_code;
213 + setcookie( 'sellkit_rejected_coupon', $cookie_value, time() + 600, '/', $domain );
214 +}
215 +
216 +add_action( 'woocommerce_checkout_order_processed', 'sellkit_remove_rejected_auto_apply_coupon_cookie' );
217 +
218 +/**
219 + * Remove cookie after make an order.
220 + */
221 +function sellkit_remove_rejected_auto_apply_coupon_cookie() {
222 + if ( isset( $_COOKIE['sellkit_rejected_coupon'] ) ) {
223 + $parsed_url = wp_parse_url( site_url() );
224 + $domain = $parsed_url['host'];
225 + setcookie( 'sellkit_rejected_coupon', '', time() - 600, '/', $domain );
226 + }
154 227 }