| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || die(); |
| 4 |
|
| 5 |
/** |
| 6 |
* Sellkit Elementor Upsell Base Widget. |
| 7 |
* |
| 8 |
* @since 1.1.0 |
| 9 |
*/ |
| 10 |
abstract class Sellkit_Elementor_Upsell_Base_Widget extends Sellkit_Elementor_Base_Widget { |
| 11 |
|
| 12 |
/** |
| 13 |
* Step data which was sent from funnel. |
| 14 |
* |
| 15 |
* @var array |
| 16 |
*/ |
| 17 |
public $step_data; |
| 18 |
|
| 19 |
/** |
| 20 |
* Sellkit_Elementor_Upsell_Base_Widget constructor. |
| 21 |
* |
| 22 |
* @since 1.1.0 |
| 23 |
* @param array $data Data. |
| 24 |
* @param null $args Args. |
| 25 |
*/ |
| 26 |
public function __construct( $data = [], $args = null ) { |
| 27 |
parent::__construct( $data, $args ); |
| 28 |
|
| 29 |
global $post; |
| 30 |
|
| 31 |
if ( empty( $post->ID ) ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$this->step_data = get_post_meta( $post->ID, 'step_data', true ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* It's used for getting product object data which was defined in funnels panel. |
| 40 |
* |
| 41 |
* @return false|WC_Product |
| 42 |
*/ |
| 43 |
public function get_product_object() { |
| 44 |
if ( empty( $this->step_data['data']['products']['list'] ) || count( $this->step_data['data']['products']['list'] ) === 0 ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
$products = $this->step_data['data']['products']['list']; |
| 49 |
$product_id = key( $products ); |
| 50 |
|
| 51 |
return wc_get_product( $product_id ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Only show the widgets when the page is an upsell page. |
| 56 |
* |
| 57 |
* @return bool |
| 58 |
*/ |
| 59 |
public function show_in_panel() { |
| 60 |
if ( empty( $this->step_data['type']['key'] ) ) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
if ( 'upsell' !== $this->step_data['type']['key'] && 'downsell' !== $this->step_data['type']['key'] ) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
} |
| 71 |
|