| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Funnel\Steps; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || die(); |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Sellkit_Thankyou. |
| 9 |
* |
| 10 |
* @since 1.1.0 |
| 11 |
*/ |
| 12 |
class Thankyou { |
| 13 |
|
| 14 |
/** |
| 15 |
* Thankyou constructor. |
| 16 |
* |
| 17 |
* @since 1.1.0 |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
add_action( 'template_redirect', [ $this, 'redirect_after_purchase' ], 10 ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Redirects after purchasing. |
| 25 |
* |
| 26 |
* @since 1.1.0 |
| 27 |
*/ |
| 28 |
public function redirect_after_purchase() { |
| 29 |
if ( ! class_exists( 'woocommerce' ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
global $wp; |
| 34 |
|
| 35 |
$funnel = sellkit_funnel(); |
| 36 |
|
| 37 |
if ( ! empty( $funnel->funnel_id ) && 'thankyou' === $funnel->current_step_data['type']['key'] ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! function_exists( 'is_checkout' ) ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) { |
| 46 |
$order_id = absint( $wp->query_vars['order-received'] ); |
| 47 |
$order_key = sellkit_htmlspecialchars( INPUT_GET, 'key' ); |
| 48 |
$order = wc_get_order( $order_id ); |
| 49 |
$next_step = $order->get_meta( 'sellkit_funnel_next_step_data' ); |
| 50 |
|
| 51 |
if ( empty( $next_step ) ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$next_step_link = add_query_arg( [ 'order-key' => $order_key ], get_permalink( $next_step['page_id'] ) ); |
| 56 |
|
| 57 |
wp_safe_redirect( $next_step_link ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|