| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Funnel\Steps; |
| 4 |
|
| 5 |
use Sellkit_Funnel; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || die(); |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Decision. |
| 11 |
* |
| 12 |
* @since 1.5.0 |
| 13 |
*/ |
| 14 |
class Decision { |
| 15 |
/** |
| 16 |
* Current funnel. |
| 17 |
* |
| 18 |
* @since 1.8.6 |
| 19 |
* @var Sellkit_Funnel |
| 20 |
*/ |
| 21 |
public $funnel; |
| 22 |
|
| 23 |
/** |
| 24 |
* Decision constructor. |
| 25 |
* |
| 26 |
* @since 1.5.0 |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
$this->funnel = Sellkit_Funnel::get_instance(); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Upsell actions. |
| 35 |
* |
| 36 |
* @since 1.1.0 |
| 37 |
* @SuppressWarnings(PHPMD.NPathComplexity) |
| 38 |
*/ |
| 39 |
public function do_actions() { |
| 40 |
$conditions = ! empty( $this->funnel->current_step_data['data']['conditions'] ) ? $this->funnel->current_step_data['data']['conditions'] : []; |
| 41 |
|
| 42 |
$is_valid = sellkit_conditions_validation( $conditions ); |
| 43 |
|
| 44 |
$args = []; |
| 45 |
|
| 46 |
if ( ! empty( $_GET['order-key'] ) ) { // phpcs:ignore |
| 47 |
$args['order-key'] = $_GET['order-key']; // phpcs:ignore |
| 48 |
} |
| 49 |
|
| 50 |
if ( $is_valid && ! empty( $this->funnel->next_step_data['page_id'] ) ) { |
| 51 |
wp_safe_redirect( add_query_arg( $args, get_permalink( $this->funnel->next_step_data['page_id'] ) ) ); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! $is_valid && ! empty( $this->funnel->next_no_step_data['page_id'] ) ) { |
| 56 |
wp_safe_redirect( add_query_arg( $args, get_permalink( $this->funnel->next_no_step_data['page_id'] ) ) ); |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
if ( ! empty( $this->funnel->end_node_step_data['page_id'] ) ) { |
| 61 |
wp_safe_redirect( add_query_arg( $args, get_permalink( $this->funnel->end_node_step_data['page_id'] ) ) ); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|