| @@ -1,388 +1,765 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * CartFlows Functions. | |
| 4 | - * | |
| 5 | - * @package CARTFLOWS | |
| 6 | - */ | |
| 7 | - | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | - exit; // Exit if accessed directly. | |
| 10 | -} | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * Check if cartflows pro activated. | |
| 14 | - * | |
| 15 | - * @since 1.0.0 | |
| 16 | - */ | |
| 17 | -function _is_cartflows_pro() { | |
| 18 | - | |
| 19 | - if ( defined( 'CARTFLOWS_PRO_FILE' ) ) { | |
| 20 | - return true; | |
| 21 | - } | |
| 22 | - | |
| 23 | - return false; | |
| 24 | - | |
| 25 | -} | |
| 26 | - | |
| 27 | -/** | |
| 28 | - * Returns step id. | |
| 29 | - * | |
| 30 | - * @since 1.0.0 | |
| 31 | - */ | |
| 32 | -function _get_wcf_post_id() { | |
| 33 | - | |
| 34 | - global $post; | |
| 35 | - | |
| 36 | - if ( isset( $post->ID ) ) { | |
| 37 | - return $post->ID; | |
| 38 | - } | |
| 39 | - | |
| 40 | - return 0; | |
| 41 | -} | |
| 42 | - | |
| 43 | -/** | |
| 44 | - * Returns step id. | |
| 45 | - * | |
| 46 | - * @since 1.0.0 | |
| 47 | - */ | |
| 48 | -function _get_wcf_step_id() { | |
| 49 | - | |
| 50 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 51 | - | |
| 52 | - global $post; | |
| 53 | - | |
| 54 | - return $post->ID; | |
| 55 | - } | |
| 56 | - | |
| 57 | - return false; | |
| 58 | -} | |
| 59 | - | |
| 60 | -/** | |
| 61 | - * Check if it is a landing page? | |
| 62 | - * | |
| 63 | - * @since 1.0.0 | |
| 64 | - */ | |
| 65 | -function _is_wcf_landing_type() { | |
| 66 | - | |
| 67 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 68 | - | |
| 69 | - global $post; | |
| 70 | - | |
| 71 | - if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 72 | - | |
| 73 | - return true; | |
| 74 | - } | |
| 75 | - } | |
| 76 | - | |
| 77 | - return false; | |
| 78 | -} | |
| 79 | - | |
| 80 | -/** | |
| 81 | - * Returns landing id. | |
| 82 | - * | |
| 83 | - * @since 1.0.0 | |
| 84 | - */ | |
| 85 | -function _get_wcf_landing_id() { | |
| 86 | - | |
| 87 | - if ( _is_wcf_landing_type() ) { | |
| 88 | - | |
| 89 | - global $post; | |
| 90 | - | |
| 91 | - return $post->ID; | |
| 92 | - } | |
| 93 | - | |
| 94 | - return false; | |
| 95 | -} | |
| 96 | - | |
| 97 | -/** | |
| 98 | - * Is custom checkout? | |
| 99 | - * | |
| 100 | - * @param int $checkout_id checkout ID. | |
| 101 | - * @since 1.0.0 | |
| 102 | - */ | |
| 103 | -function _is_wcf_meta_custom_checkout( $checkout_id ) { | |
| 104 | - | |
| 105 | - $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' ); | |
| 106 | - | |
| 107 | - if ( 'yes' === $is_custom ) { | |
| 108 | - | |
| 109 | - return true; | |
| 110 | - } | |
| 111 | - | |
| 112 | - return false; | |
| 113 | -} | |
| 114 | - | |
| 115 | -/** | |
| 116 | - * Check if page is cartflow checkout. | |
| 117 | - * | |
| 118 | - * @since 1.0.0 | |
| 119 | - * @return bool | |
| 120 | - */ | |
| 121 | -function _is_wcf_checkout_type() { | |
| 122 | - | |
| 123 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 124 | - | |
| 125 | - global $post; | |
| 126 | - | |
| 127 | - if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 128 | - | |
| 129 | - return true; | |
| 130 | - } | |
| 131 | - } | |
| 132 | - | |
| 133 | - return false; | |
| 134 | -} | |
| 135 | - | |
| 136 | -/** | |
| 137 | - * Check if AJAX call is in progress. | |
| 138 | - * | |
| 139 | - * @since 1.0.0 | |
| 140 | - * @return bool | |
| 141 | - */ | |
| 142 | -function _is_wcf_doing_checkout_ajax() { | |
| 143 | - | |
| 144 | - if ( wp_doing_ajax() ) { | |
| 145 | - | |
| 146 | - if ( isset( $_GET['wc-ajax'] ) && | |
| 147 | - 'checkout' === $_GET['wc-ajax'] && | |
| 148 | - isset( $_POST['_wcf_checkout_id'] ) | |
| 149 | - ) { | |
| 150 | - return true; | |
| 151 | - } | |
| 152 | - } | |
| 153 | - | |
| 154 | - return false; | |
| 155 | -} | |
| 156 | - | |
| 157 | - | |
| 158 | -/** | |
| 159 | - * Returns checkout ID. | |
| 160 | - * | |
| 161 | - * @since 1.0.0 | |
| 162 | - * @return int/bool | |
| 163 | - */ | |
| 164 | -function _get_wcf_checkout_id() { | |
| 165 | - | |
| 166 | - if ( _is_wcf_checkout_type() ) { | |
| 167 | - | |
| 168 | - global $post; | |
| 169 | - | |
| 170 | - return $post->ID; | |
| 171 | - } | |
| 172 | - | |
| 173 | - return false; | |
| 174 | -} | |
| 175 | - | |
| 176 | -/** | |
| 177 | - * Check if it is checkout shortcode. | |
| 178 | - * | |
| 179 | - * @since 1.0.0 | |
| 180 | - * @return bool | |
| 181 | - */ | |
| 182 | -function _is_wcf_checkout_shortcode() { | |
| 183 | - | |
| 184 | - global $post; | |
| 185 | - | |
| 186 | - if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) { | |
| 187 | - | |
| 188 | - return true; | |
| 189 | - } | |
| 190 | - | |
| 191 | - return false; | |
| 192 | -} | |
| 193 | - | |
| 194 | -/** | |
| 195 | - * Check if it is checkout shortcode. | |
| 196 | - * | |
| 197 | - * @since 1.0.0 | |
| 198 | - * @param string $content shortcode content. | |
| 199 | - * @return bool | |
| 200 | - */ | |
| 201 | -function _get_wcf_checkout_id_from_shortcode( $content = '' ) { | |
| 202 | - | |
| 203 | - $checkout_id = 0; | |
| 204 | - | |
| 205 | - if ( ! empty( $content ) ) { | |
| 206 | - | |
| 207 | - $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) ); | |
| 208 | - | |
| 209 | - preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches ); | |
| 210 | - | |
| 211 | - if ( ! empty( $regex_matches ) ) { | |
| 212 | - | |
| 213 | - if ( 'cartflows_checkout' == $regex_matches[2] ) { | |
| 214 | - | |
| 215 | - $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) ); | |
| 216 | - $attribure_str = str_replace( '"', '', $attribure_str ); | |
| 217 | - | |
| 218 | - $attributes = wp_parse_args( $attribure_str ); | |
| 219 | - | |
| 220 | - if ( isset( $attributes['id'] ) ) { | |
| 221 | - $checkout_id = $attributes['id']; | |
| 222 | - } | |
| 223 | - } | |
| 224 | - } | |
| 225 | - } | |
| 226 | - | |
| 227 | - return $checkout_id; | |
| 228 | -} | |
| 229 | - | |
| 230 | -/** | |
| 231 | - * Check if post type is upsell. | |
| 232 | - * | |
| 233 | - * @since 1.0.0 | |
| 234 | - * @return bool | |
| 235 | - */ | |
| 236 | -function _is_wcf_upsell_type() { | |
| 237 | - | |
| 238 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 239 | - | |
| 240 | - global $post; | |
| 241 | - | |
| 242 | - if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 243 | - | |
| 244 | - return true; | |
| 245 | - } | |
| 246 | - } | |
| 247 | - | |
| 248 | - return false; | |
| 249 | -} | |
| 250 | - | |
| 251 | -/** | |
| 252 | - * Returns upsell ID. | |
| 253 | - * | |
| 254 | - * @since 1.0.0 | |
| 255 | - * @return int/bool | |
| 256 | - */ | |
| 257 | -function _get_wcf_upsell_id() { | |
| 258 | - | |
| 259 | - if ( _is_wcf_upsell_type() ) { | |
| 260 | - | |
| 261 | - global $post; | |
| 262 | - | |
| 263 | - return $post->ID; | |
| 264 | - } | |
| 265 | - | |
| 266 | - return false; | |
| 267 | -} | |
| 268 | - | |
| 269 | -/** | |
| 270 | - * Check if post is of type downsell. | |
| 271 | - * | |
| 272 | - * @since 1.0.0 | |
| 273 | - * @return int/bool | |
| 274 | - */ | |
| 275 | -function _is_wcf_downsell_type() { | |
| 276 | - | |
| 277 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 278 | - | |
| 279 | - global $post; | |
| 280 | - | |
| 281 | - if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 282 | - | |
| 283 | - return true; | |
| 284 | - } | |
| 285 | - } | |
| 286 | - | |
| 287 | - return false; | |
| 288 | -} | |
| 289 | - | |
| 290 | -/** | |
| 291 | - * Get downsell page ID. | |
| 292 | - * | |
| 293 | - * @since 1.0.0 | |
| 294 | - * @return int/bool | |
| 295 | - */ | |
| 296 | -function _get_wcf_downsell_id() { | |
| 297 | - | |
| 298 | - if ( _is_wcf_downsell_type() ) { | |
| 299 | - | |
| 300 | - global $post; | |
| 301 | - | |
| 302 | - return $post->ID; | |
| 303 | - } | |
| 304 | - | |
| 305 | - return false; | |
| 306 | -} | |
| 307 | - | |
| 308 | -/** | |
| 309 | - * Check if page is of thank you type. | |
| 310 | - * | |
| 311 | - * @since 1.0.0 | |
| 312 | - * @return int/bool | |
| 313 | - */ | |
| 314 | -function _is_wcf_thankyou_type() { | |
| 315 | - | |
| 316 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 317 | - | |
| 318 | - global $post; | |
| 319 | - | |
| 320 | - if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 321 | - | |
| 322 | - return true; | |
| 323 | - } | |
| 324 | - } | |
| 325 | - | |
| 326 | - return false; | |
| 327 | -} | |
| 328 | - | |
| 329 | -/** | |
| 330 | - * Get thank you page ID. | |
| 331 | - * | |
| 332 | - * @since 1.0.0 | |
| 333 | - * @return int/bool | |
| 334 | - */ | |
| 335 | -function _get_wcf_thankyou_id() { | |
| 336 | - | |
| 337 | - if ( _is_wcf_thankyou_type() ) { | |
| 338 | - | |
| 339 | - global $post; | |
| 340 | - | |
| 341 | - return $post->ID; | |
| 342 | - } | |
| 343 | - | |
| 344 | - return false; | |
| 345 | -} | |
| 346 | - | |
| 347 | - | |
| 348 | -/** | |
| 349 | - * Check if post type is upsell. | |
| 350 | - * | |
| 351 | - * @since 1.0.0 | |
| 352 | - * @return bool | |
| 353 | - */ | |
| 354 | -function _is_wcf_base_offer_type() { | |
| 355 | - | |
| 356 | - if ( wcf()->utils->is_step_post_type() ) { | |
| 357 | - | |
| 358 | - global $post; | |
| 359 | - | |
| 360 | - $step_type = get_post_meta( $post->ID, 'wcf-step-type', true ); | |
| 361 | - | |
| 362 | - if ( 'upsell' === $step_type || 'downsell' === $step_type ) { | |
| 363 | - | |
| 364 | - return true; | |
| 365 | - } | |
| 366 | - } | |
| 367 | - | |
| 368 | - return false; | |
| 369 | -} | |
| 370 | - | |
| 371 | -/** | |
| 372 | - * Returns upsell ID. | |
| 373 | - * | |
| 374 | - * @since 1.0.0 | |
| 375 | - * @return int/bool | |
| 376 | - */ | |
| 377 | -function _get_wcf_base_offer_id() { | |
| 378 | - | |
| 379 | - if ( _is_wcf_base_offer_type() ) { | |
| 380 | - | |
| 381 | - global $post; | |
| 382 | - | |
| 383 | - return $post->ID; | |
| 384 | - } | |
| 385 | - | |
| 386 | - return false; | |
| 387 | -} | |
| 388 | - | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * CartFlows Functions. | |
| 4 | + * | |
| 5 | + * @package CARTFLOWS | |
| 6 | + */ | |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit; // Exit if accessed directly. | |
| 10 | +} | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Fatal error mb_strpos fallback. | |
| 14 | + * | |
| 15 | + * @param string $string string where to find. | |
| 16 | + * @param string $search string to search. | |
| 17 | + * @since 1.0.0 | |
| 18 | + */ | |
| 19 | +function wcf_mb_strpos( $string, $search ) { | |
| 20 | + | |
| 21 | + if ( function_exists( 'mb_strpos' ) ) { | |
| 22 | + return mb_strpos( $string, $search, 0, 'utf-8' ); | |
| 23 | + } else { | |
| 24 | + return strpos( $string, $search ); | |
| 25 | + } | |
| 26 | +} | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * Check if cartflows pro activated. | |
| 30 | + * | |
| 31 | + * @since 1.0.0 | |
| 32 | + */ | |
| 33 | +function _is_cartflows_pro() { | |
| 34 | + | |
| 35 | + if ( defined( 'CARTFLOWS_PRO_FILE' ) ) { | |
| 36 | + return true; | |
| 37 | + } | |
| 38 | + | |
| 39 | + return false; | |
| 40 | +} | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Check if cartflows pro's license is been activated. | |
| 44 | + * | |
| 45 | + * @since 1.11.8 | |
| 46 | + */ | |
| 47 | +function _is_cartflows_pro_license_activated() { | |
| 48 | + | |
| 49 | + if ( _is_cartflows_pro() && class_exists( 'CartFlows_Pro_Licence' ) ) { | |
| 50 | + return CartFlows_Pro_Licence::get_instance()->activate_status; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return false; | |
| 54 | +} | |
| 55 | + | |
| 56 | +/** | |
| 57 | + * Returns pro version number. | |
| 58 | + * | |
| 59 | + * @param int $version version number. | |
| 60 | + * @since 1.0.0 | |
| 61 | + */ | |
| 62 | +function _is_cartflows_pro_ver_less_than( $version ) { | |
| 63 | + | |
| 64 | + if ( defined( 'CARTFLOWS_PRO_VER' ) && version_compare( CARTFLOWS_PRO_VER, $version, '<' ) ) { | |
| 65 | + return true; | |
| 66 | + } | |
| 67 | + | |
| 68 | + return false; | |
| 69 | +} | |
| 70 | + | |
| 71 | +/** | |
| 72 | + * Returns step id. | |
| 73 | + * | |
| 74 | + * @since 1.0.0 | |
| 75 | + */ | |
| 76 | +function _get_wcf_post_id() { | |
| 77 | + | |
| 78 | + global $post; | |
| 79 | + | |
| 80 | + if ( isset( $post->ID ) ) { | |
| 81 | + return $post->ID; | |
| 82 | + } | |
| 83 | + | |
| 84 | + return 0; | |
| 85 | +} | |
| 86 | + | |
| 87 | +/** | |
| 88 | + * Returns step id. | |
| 89 | + * | |
| 90 | + * @since 1.0.0 | |
| 91 | + */ | |
| 92 | +function _get_wcf_step_id() { | |
| 93 | + | |
| 94 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 95 | + | |
| 96 | + global $post; | |
| 97 | + | |
| 98 | + return $post->ID; | |
| 99 | + } | |
| 100 | + | |
| 101 | + return false; | |
| 102 | +} | |
| 103 | + | |
| 104 | +/** | |
| 105 | + * Check if it is a landing page? | |
| 106 | + * | |
| 107 | + * @since 1.0.0 | |
| 108 | + */ | |
| 109 | +function _is_wcf_landing_type() { | |
| 110 | + | |
| 111 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 112 | + | |
| 113 | + global $post; | |
| 114 | + | |
| 115 | + if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 116 | + | |
| 117 | + return true; | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 121 | + return false; | |
| 122 | +} | |
| 123 | + | |
| 124 | +/** | |
| 125 | + * Returns landing id. | |
| 126 | + * | |
| 127 | + * @since 1.0.0 | |
| 128 | + */ | |
| 129 | +function _get_wcf_landing_id() { | |
| 130 | + | |
| 131 | + if ( _is_wcf_landing_type() ) { | |
| 132 | + | |
| 133 | + global $post; | |
| 134 | + | |
| 135 | + return $post->ID; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return false; | |
| 139 | +} | |
| 140 | + | |
| 141 | +/** | |
| 142 | + * Is custom checkout? | |
| 143 | + * | |
| 144 | + * @param int $checkout_id checkout ID. | |
| 145 | + * @since 1.0.0 | |
| 146 | + */ | |
| 147 | +function _is_wcf_meta_custom_checkout( $checkout_id ) { | |
| 148 | + | |
| 149 | + $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' ); | |
| 150 | + | |
| 151 | + if ( 'yes' === $is_custom ) { | |
| 152 | + | |
| 153 | + return true; | |
| 154 | + } | |
| 155 | + | |
| 156 | + return false; | |
| 157 | +} | |
| 158 | + | |
| 159 | +/** | |
| 160 | + * Check if page is cartflow checkout. | |
| 161 | + * | |
| 162 | + * @since 1.0.0 | |
| 163 | + * @return bool | |
| 164 | + */ | |
| 165 | +function _is_wcf_checkout_type() { | |
| 166 | + | |
| 167 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 168 | + | |
| 169 | + global $post; | |
| 170 | + | |
| 171 | + if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 172 | + | |
| 173 | + return true; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + return false; | |
| 178 | +} | |
| 179 | + | |
| 180 | +/** | |
| 181 | + * Check if AJAX call is in progress. | |
| 182 | + * | |
| 183 | + * @since 1.0.0 | |
| 184 | + * @return bool | |
| 185 | + */ | |
| 186 | +function _is_wcf_doing_checkout_ajax() { | |
| 187 | + | |
| 188 | + //phpcs:disable WordPress.Security.NonceVerification | |
| 189 | + if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { | |
| 190 | + | |
| 191 | + if ( ( isset( $_GET['wc-ajax'] ) && isset( $_POST['_wcf_checkout_id'] ) ) || isset( $_GET['wcf_checkout_id'] ) | |
| 192 | + ) { | |
| 193 | + return true; | |
| 194 | + } | |
| 195 | + } | |
| 196 | + //phpcs:enable WordPress.Security.NonceVerification | |
| 197 | + | |
| 198 | + return false; | |
| 199 | +} | |
| 200 | + | |
| 201 | +/** | |
| 202 | + * Check if optin AJAX call is in progress. | |
| 203 | + * | |
| 204 | + * @since 1.0.0 | |
| 205 | + * @return bool | |
| 206 | + */ | |
| 207 | +function _is_wcf_doing_optin_ajax() { | |
| 208 | + | |
| 209 | + //phpcs:disable WordPress.Security.NonceVerification | |
| 210 | + if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) { | |
| 211 | + | |
| 212 | + if ( isset( $_GET['wc-ajax'] ) && | |
| 213 | + isset( $_POST['_wcf_optin_id'] ) | |
| 214 | + ) { | |
| 215 | + return true; | |
| 216 | + } | |
| 217 | + } | |
| 218 | + //phpcs:enable WordPress.Security.NonceVerification | |
| 219 | + | |
| 220 | + return false; | |
| 221 | +} | |
| 222 | + | |
| 223 | +/** | |
| 224 | + * Returns checkout ID. | |
| 225 | + * | |
| 226 | + * @since 1.0.0 | |
| 227 | + * @return int/bool | |
| 228 | + */ | |
| 229 | +function _get_wcf_checkout_id() { | |
| 230 | + | |
| 231 | + if ( _is_wcf_checkout_type() ) { | |
| 232 | + | |
| 233 | + global $post; | |
| 234 | + | |
| 235 | + return $post->ID; | |
| 236 | + } | |
| 237 | + | |
| 238 | + return false; | |
| 239 | +} | |
| 240 | + | |
| 241 | +/** | |
| 242 | + * Check if it is checkout shortcode. | |
| 243 | + * | |
| 244 | + * @since 1.0.0 | |
| 245 | + * @return bool | |
| 246 | + */ | |
| 247 | +function _is_wcf_checkout_shortcode() { | |
| 248 | + | |
| 249 | + global $post; | |
| 250 | + | |
| 251 | + if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) { | |
| 252 | + | |
| 253 | + return true; | |
| 254 | + } | |
| 255 | + | |
| 256 | + return false; | |
| 257 | +} | |
| 258 | + | |
| 259 | +/** | |
| 260 | + * Check if it is checkout shortcode. | |
| 261 | + * | |
| 262 | + * @since 1.0.0 | |
| 263 | + * @param string $content shortcode content. | |
| 264 | + * @return bool | |
| 265 | + */ | |
| 266 | +function _get_wcf_checkout_id_from_shortcode( $content = '' ) { | |
| 267 | + | |
| 268 | + $checkout_id = 0; | |
| 269 | + | |
| 270 | + if ( ! empty( $content ) ) { | |
| 271 | + | |
| 272 | + $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) ); | |
| 273 | + | |
| 274 | + preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches ); | |
| 275 | + | |
| 276 | + if ( ! empty( $regex_matches ) ) { | |
| 277 | + | |
| 278 | + if ( 'cartflows_checkout' == $regex_matches[2] ) { | |
| 279 | + | |
| 280 | + $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) ); | |
| 281 | + $attribure_str = str_replace( '"', '', $attribure_str ); | |
| 282 | + | |
| 283 | + $attributes = wp_parse_args( $attribure_str ); | |
| 284 | + | |
| 285 | + if ( isset( $attributes['id'] ) ) { | |
| 286 | + $checkout_id = $attributes['id']; | |
| 287 | + } | |
| 288 | + } | |
| 289 | + } | |
| 290 | + } | |
| 291 | + | |
| 292 | + return $checkout_id; | |
| 293 | +} | |
| 294 | + | |
| 295 | +/** | |
| 296 | + * Check if post type is upsell. | |
| 297 | + * | |
| 298 | + * @since 1.0.0 | |
| 299 | + * @return bool | |
| 300 | + */ | |
| 301 | +function _is_wcf_upsell_type() { | |
| 302 | + | |
| 303 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 304 | + | |
| 305 | + global $post; | |
| 306 | + | |
| 307 | + if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 308 | + | |
| 309 | + return true; | |
| 310 | + } | |
| 311 | + } | |
| 312 | + | |
| 313 | + return false; | |
| 314 | +} | |
| 315 | + | |
| 316 | +/** | |
| 317 | + * Returns upsell ID. | |
| 318 | + * | |
| 319 | + * @since 1.0.0 | |
| 320 | + * @return int/bool | |
| 321 | + */ | |
| 322 | +function _get_wcf_upsell_id() { | |
| 323 | + | |
| 324 | + if ( _is_wcf_upsell_type() ) { | |
| 325 | + | |
| 326 | + global $post; | |
| 327 | + | |
| 328 | + return $post->ID; | |
| 329 | + } | |
| 330 | + | |
| 331 | + return false; | |
| 332 | +} | |
| 333 | + | |
| 334 | +/** | |
| 335 | + * Check if post is of type downsell. | |
| 336 | + * | |
| 337 | + * @since 1.0.0 | |
| 338 | + * @return int/bool | |
| 339 | + */ | |
| 340 | +function _is_wcf_downsell_type() { | |
| 341 | + | |
| 342 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 343 | + | |
| 344 | + global $post; | |
| 345 | + | |
| 346 | + if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 347 | + | |
| 348 | + return true; | |
| 349 | + } | |
| 350 | + } | |
| 351 | + | |
| 352 | + return false; | |
| 353 | +} | |
| 354 | + | |
| 355 | +/** | |
| 356 | + * Get downsell page ID. | |
| 357 | + * | |
| 358 | + * @since 1.0.0 | |
| 359 | + * @return int/bool | |
| 360 | + */ | |
| 361 | +function _get_wcf_downsell_id() { | |
| 362 | + | |
| 363 | + if ( _is_wcf_downsell_type() ) { | |
| 364 | + | |
| 365 | + global $post; | |
| 366 | + | |
| 367 | + return $post->ID; | |
| 368 | + } | |
| 369 | + | |
| 370 | + return false; | |
| 371 | +} | |
| 372 | + | |
| 373 | +/** | |
| 374 | + * Check if page is of thank you type. | |
| 375 | + * | |
| 376 | + * @since 1.0.0 | |
| 377 | + * @return int/bool | |
| 378 | + */ | |
| 379 | +function _is_wcf_thankyou_type() { | |
| 380 | + | |
| 381 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 382 | + | |
| 383 | + global $post; | |
| 384 | + | |
| 385 | + if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 386 | + | |
| 387 | + return true; | |
| 388 | + } | |
| 389 | + } | |
| 390 | + | |
| 391 | + return false; | |
| 392 | +} | |
| 393 | + | |
| 394 | +/** | |
| 395 | + * Get thank you page ID. | |
| 396 | + * | |
| 397 | + * @since 1.0.0 | |
| 398 | + * @return int/bool | |
| 399 | + */ | |
| 400 | +function _get_wcf_thankyou_id() { | |
| 401 | + | |
| 402 | + if ( _is_wcf_thankyou_type() ) { | |
| 403 | + | |
| 404 | + global $post; | |
| 405 | + | |
| 406 | + return $post->ID; | |
| 407 | + } | |
| 408 | + | |
| 409 | + return false; | |
| 410 | +} | |
| 411 | + | |
| 412 | + | |
| 413 | +/** | |
| 414 | + * Check if post type is upsell. | |
| 415 | + * | |
| 416 | + * @since 1.0.0 | |
| 417 | + * @return bool | |
| 418 | + */ | |
| 419 | +function _is_wcf_base_offer_type() { | |
| 420 | + | |
| 421 | + $result = false; | |
| 422 | + | |
| 423 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 424 | + | |
| 425 | + global $post; | |
| 426 | + | |
| 427 | + $step_type = get_post_meta( $post->ID, 'wcf-step-type', true ); | |
| 428 | + | |
| 429 | + if ( 'upsell' === $step_type || 'downsell' === $step_type ) { | |
| 430 | + | |
| 431 | + $result = true; | |
| 432 | + } | |
| 433 | + } | |
| 434 | + | |
| 435 | + return apply_filters( 'cartflows_is_offer_type', $result ); | |
| 436 | +} | |
| 437 | + | |
| 438 | +/** | |
| 439 | + * Returns upsell ID. | |
| 440 | + * | |
| 441 | + * @since 1.0.0 | |
| 442 | + * @return int/bool | |
| 443 | + */ | |
| 444 | +function _get_wcf_base_offer_id() { | |
| 445 | + | |
| 446 | + if ( _is_wcf_base_offer_type() ) { | |
| 447 | + | |
| 448 | + global $post; | |
| 449 | + | |
| 450 | + return $post->ID; | |
| 451 | + } | |
| 452 | + | |
| 453 | + return false; | |
| 454 | +} | |
| 455 | + | |
| 456 | +/** | |
| 457 | + * Check if page is of optin type. | |
| 458 | + * | |
| 459 | + * @since 1.0.0 | |
| 460 | + * @return int/bool | |
| 461 | + */ | |
| 462 | +function _is_wcf_optin_type() { | |
| 463 | + | |
| 464 | + if ( wcf()->utils->is_step_post_type() ) { | |
| 465 | + | |
| 466 | + global $post; | |
| 467 | + | |
| 468 | + if ( 'optin' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) { | |
| 469 | + | |
| 470 | + return true; | |
| 471 | + } | |
| 472 | + } | |
| 473 | + | |
| 474 | + return false; | |
| 475 | +} | |
| 476 | + | |
| 477 | +/** | |
| 478 | + * Get optin page ID. | |
| 479 | + * | |
| 480 | + * @since 1.0.0 | |
| 481 | + * @return int/bool | |
| 482 | + */ | |
| 483 | +function _get_wcf_optin_id() { | |
| 484 | + | |
| 485 | + if ( _is_wcf_optin_type() ) { | |
| 486 | + | |
| 487 | + global $post; | |
| 488 | + | |
| 489 | + return $post->ID; | |
| 490 | + } | |
| 491 | + | |
| 492 | + return false; | |
| 493 | +} | |
| 494 | + | |
| 495 | +/** | |
| 496 | + * Define a constant if it is not already defined. | |
| 497 | + * | |
| 498 | + * @since 3.0.0 | |
| 499 | + * @param string $name Constant name. | |
| 500 | + * @param mixed $value Value. | |
| 501 | + */ | |
| 502 | +function wcf_maybe_define_constant( $name, $value ) { | |
| 503 | + if ( ! defined( $name ) ) { | |
| 504 | + define( $name, $value ); | |
| 505 | + } | |
| 506 | +} | |
| 507 | + | |
| 508 | + | |
| 509 | +if ( ! function_exists( 'wp_body_open' ) ) { | |
| 510 | + /** | |
| 511 | + * Fire the wp_body_open action. | |
| 512 | + * | |
| 513 | + * Added for backwards compatibility to support WordPress versions prior to 5.2.0. | |
| 514 | + */ | |
| 515 | + function wp_body_open() { | |
| 516 | + /** | |
| 517 | + * Triggered after the opening <body> tag. | |
| 518 | + */ | |
| 519 | + do_action( 'wp_body_open' ); | |
| 520 | + } | |
| 521 | +} | |
| 522 | + | |
| 523 | +/** | |
| 524 | + * Check if type is optin by id. | |
| 525 | + * | |
| 526 | + * @param int $post_id post id. | |
| 527 | + * | |
| 528 | + * @return int/bool | |
| 529 | + * @since 1.0.0 | |
| 530 | + */ | |
| 531 | +function _wcf_check_is_optin_by_id( $post_id ) { | |
| 532 | + | |
| 533 | + if ( 'optin' === get_post_meta( $post_id, 'wcf-step-type', true ) ) { | |
| 534 | + | |
| 535 | + return true; | |
| 536 | + } | |
| 537 | + | |
| 538 | + return false; | |
| 539 | +} | |
| 540 | + | |
| 541 | +/** | |
| 542 | + * Supported Page Template | |
| 543 | + * | |
| 544 | + * @param string $page_template current page template. | |
| 545 | + * | |
| 546 | + * @return int/bool | |
| 547 | + * @since 1.5.7 | |
| 548 | + */ | |
| 549 | +function _wcf_supported_template( $page_template ) { | |
| 550 | + | |
| 551 | + if ( in_array( $page_template, array( 'cartflows-default', 'cartflows-canvas', 'instant-checkout' ), true ) ) { | |
| 552 | + | |
| 553 | + return true; | |
| 554 | + } | |
| 555 | + | |
| 556 | + return false; | |
| 557 | +} | |
| 558 | + | |
| 559 | +/** | |
| 560 | + * Display design Metabox Notice. | |
| 561 | + * | |
| 562 | + * @return string | |
| 563 | + * @since 1.6.15 | |
| 564 | + */ | |
| 565 | +function wcf_get_page_builder_notice() { | |
| 566 | + | |
| 567 | + $notice = ''; | |
| 568 | + $page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); | |
| 569 | + | |
| 570 | + $supported_page_builders = array( 'elementor', 'beaver-builder' ); | |
| 571 | + | |
| 572 | + $page_builder_data = array( | |
| 573 | + 'elementor' => array( | |
| 574 | + 'name' => 'Elementor', | |
| 575 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/elementor-widgets-of-cartflows/' ), | |
| 576 | + ), | |
| 577 | + 'beaver-builder' => array( | |
| 578 | + 'name' => 'Beaver Builder', | |
| 579 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/beaver-builder-modules-of-cartflows/' ), | |
| 580 | + ), | |
| 581 | + 'gutenberg' => array( | |
| 582 | + 'name' => 'Gutenebrg', | |
| 583 | + 'doc' => Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/cartflows-gutenberg-blocks/' ), | |
| 584 | + ), | |
| 585 | + ); | |
| 586 | + | |
| 587 | + if ( isset( $page_builder_data[ $page_builder ] ) ) { | |
| 588 | + | |
| 589 | + $page_builder_name = $page_builder_data[ $page_builder ]['name']; | |
| 590 | + $doc_link = $page_builder_data[ $page_builder ]['doc']; | |
| 591 | + | |
| 592 | + $notice = '<div class="wcf-metabox-notice-wrap"><p class="wcf-metabox-notice wcf-pb-modules-notice">'; | |
| 593 | + $notice .= '<span class="dashicons dashicons-info"></span> '; | |
| 594 | + /* translators: %1$s page builder name "string" */ | |
| 595 | + $notice .= sprintf( __( 'We have introduced %1$1s widgets for CartFlows shortcodes. Now, you can add/change/update design settings directly from the page builder as well.', 'cartflows' ), $page_builder_name ); | |
| 596 | + $notice .= ' <a href="' . $doc_link . '" target="_blank">' . __( 'Learn More »', 'cartflows' ) . '</span></a>'; | |
| 597 | + $notice .= '</p></div>'; | |
| 598 | + } | |
| 599 | + | |
| 600 | + return $notice; | |
| 601 | +} | |
| 602 | + | |
| 603 | +/** | |
| 604 | + * Get step type. | |
| 605 | + * | |
| 606 | + * @param int $post_id post id. | |
| 607 | + * | |
| 608 | + * @return bool|string | |
| 609 | + * @since 1.0.0 | |
| 610 | + */ | |
| 611 | +function wcf_get_step_type( $post_id ) { | |
| 612 | + | |
| 613 | + return get_post_meta( $post_id, 'wcf-step-type', true ); | |
| 614 | +} | |
| 615 | + | |
| 616 | +/** | |
| 617 | + * Get get step object. | |
| 618 | + * | |
| 619 | + * @param int $step_id current step ID. | |
| 620 | + * @since 1.5.9 | |
| 621 | + */ | |
| 622 | +function wcf_get_step( $step_id ) { | |
| 623 | + | |
| 624 | + if ( ! isset( wcf()->wcf_step_objs[ $step_id ] ) ) { | |
| 625 | + | |
| 626 | + wcf()->wcf_step_objs[ $step_id ] = new Cartflows_Step_Factory( $step_id ); | |
| 627 | + } | |
| 628 | + | |
| 629 | + return wcf()->wcf_step_objs[ $step_id ]; | |
| 630 | +} | |
| 631 | + | |
| 632 | +/** | |
| 633 | + * Check auto-prefill checkout fields feature is enabled or not. | |
| 634 | + * | |
| 635 | + * @return boolean | |
| 636 | + */ | |
| 637 | +function is_auto_prefill_checkout_fields_enabled() { | |
| 638 | + return apply_filters( 'cartflows_auto_prefill_checkout_fields', true ); | |
| 639 | +} | |
| 640 | + | |
| 641 | +/** | |
| 642 | + * Is starter plan. | |
| 643 | + * | |
| 644 | + * @return boolean | |
| 645 | + */ | |
| 646 | +function is_wcf_starter_plan() { | |
| 647 | + return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'starter'; | |
| 648 | +} | |
| 649 | + | |
| 650 | +/** | |
| 651 | + * Is PRO plan. | |
| 652 | + * | |
| 653 | + * @return boolean | |
| 654 | + */ | |
| 655 | +function is_wcf_pro_plan() { | |
| 656 | + return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'pro'; | |
| 657 | +} | |
| 658 | + | |
| 659 | +/** | |
| 660 | + * Show notice. | |
| 661 | + * | |
| 662 | + * @param string $title title. | |
| 663 | + * @param string $message description. | |
| 664 | + * @param string $classes classes. | |
| 665 | + */ | |
| 666 | +function wcf_feature_notice( $title, $message, $classes ) { | |
| 667 | + | |
| 668 | + $image_path = esc_url( CARTFLOWS_URL . 'assets/images/cartflows-logo-small.jpg' ); | |
| 669 | + | |
| 670 | + $output = '<div class="wcf-notice wcf-dismissible-notice notice notice-info is-dismissible ' . $classes . '">'; | |
| 671 | + $output .= '<div class="wcf-notice-container">'; | |
| 672 | + $output .= '<img src=' . $image_path . ' class="wcf-notice-custom-logo" alt="CartFlows Icon" itemprop="logo">'; | |
| 673 | + $output .= '<div class="wcf-notice-message"><p class="wcf-notice-heading">' . $title . '</p><p class="wcf-notice-description">' . $message . '</p></div>'; | |
| 674 | + $output .= '</div>'; | |
| 675 | + $output .= '</div>'; | |
| 676 | + | |
| 677 | + echo wp_kses_post( $output ); | |
| 678 | +} | |
| 679 | + | |
| 680 | +/** | |
| 681 | + * Get checkout layout type. | |
| 682 | + * | |
| 683 | + * @since 2.1.0 | |
| 684 | + * @return string | |
| 685 | + */ | |
| 686 | +function wcf_get_checkout_layout() { | |
| 687 | + | |
| 688 | + $checkout_id = _is_wcf_checkout_type(); | |
| 689 | + | |
| 690 | + if ( ! $checkout_id ) { | |
| 691 | + $checkout_id = isset( $_GET['wcf_checkout_id'] ) && ! empty( $_GET['wcf_checkout_id'] ) ? intval( wp_unslash( $_GET['wcf_checkout_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification | |
| 692 | + } | |
| 693 | + | |
| 694 | + $checkout_layout = 'modern-checkout'; | |
| 695 | + | |
| 696 | + if ( ! empty( $checkout_id ) ) { | |
| 697 | + // Get checkout layout skin. | |
| 698 | + $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' ); | |
| 699 | + } | |
| 700 | + | |
| 701 | + return $checkout_layout; | |
| 702 | +} | |
| 703 | + | |
| 704 | +/** Check weather the OttoKit is installed and Connected. | |
| 705 | + * | |
| 706 | + * @return bool | |
| 707 | + */ | |
| 708 | +function _is_suretriggers_connected() { | |
| 709 | + | |
| 710 | + // Check is the plugin installed. | |
| 711 | + if ( ! defined( 'SURE_TRIGGERS_VER' ) ) { | |
| 712 | + return false; | |
| 713 | + } | |
| 714 | + | |
| 715 | + // If installed then check is it connected or not. | |
| 716 | + return apply_filters( 'suretriggers_is_user_connected', '' ); | |
| 717 | +} | |
| 718 | + | |
| 719 | +/** | |
| 720 | + * Check if the current theme is a block theme OR a FSE Theme. | |
| 721 | + * | |
| 722 | + * @since 2.1.1 | |
| 723 | + * @return bool | |
| 724 | + */ | |
| 725 | +function wcf_is_current_theme_is_fse_theme() { | |
| 726 | + | |
| 727 | + if ( function_exists( 'wp_is_block_theme' ) ) { | |
| 728 | + return boolval( wp_is_block_theme() ); | |
| 729 | + } | |
| 730 | + | |
| 731 | + return false; | |
| 732 | +} | |
| 733 | + | |
| 734 | +/** | |
| 735 | + * Checks if deprecated step notes should be shown. | |
| 736 | + * | |
| 737 | + * This function applies a filter to determine if deprecated step notes should be displayed. | |
| 738 | + * | |
| 739 | + * @return bool Returns true if deprecated step notes should be shown, false otherwise. | |
| 740 | + */ | |
| 741 | +function wcf_show_deprecated_step_notes() { | |
| 742 | + return apply_filters( 'cartflows_show_deprecated_step_notes', false ); | |
| 743 | +} | |
| 744 | + | |
| 745 | +/** | |
| 746 | + * Checks if file modifications are disabled in WordPress. | |
| 747 | + * | |
| 748 | + * This function determines whether file modifications (such as updates and installations) | |
| 749 | + * are disabled by checking the DISALLOW_FILE_MODS constant. | |
| 750 | + * | |
| 751 | + * @since 2.2.0 | |
| 752 | + * @return bool True if file modifications are disabled, false otherwise. | |
| 753 | + */ | |
| 754 | +function wcf_file_mod_disabled() { | |
| 755 | + | |
| 756 | + $is_disabled = false; | |
| 757 | + | |
| 758 | + $disallow_file_mods = defined( 'DISALLOW_FILE_MODS' ) ? DISALLOW_FILE_MODS : false; | |
| 759 | + | |
| 760 | + if ( apply_filters( 'cartflows_file_mod_disabled', $disallow_file_mods ) ) { | |
| 761 | + $is_disabled = true; | |
| 762 | + } | |
| 763 | + | |
| 764 | + return $is_disabled; | |
| 765 | +} | |