| 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 |
|