| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Dynamic_Keywords\Contact_Segmentation; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Remaining subtoal amount. |
| 7 |
* |
| 8 |
* @package Sellkit\Dynamic_Keywords\Contact_Segmentation |
| 9 |
* @since 1.1.0 |
| 10 |
*/ |
| 11 |
class Remaining_Subtotal_Amount extends Contact_Segmentation_Base { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor. |
| 15 |
* |
| 16 |
* @since 1.1.0 |
| 17 |
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
parent::__construct(); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Get class id. |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public function get_id() { |
| 29 |
return '_remaining_subtotal_amount'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get class title. |
| 34 |
* |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public function get_title() { |
| 38 |
return esc_html__( 'Remaining subtotal amount', 'sellkit' ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Render content. |
| 43 |
* |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function render_content() { |
| 47 |
if ( empty( self::$contact_segmentation ) ) { |
| 48 |
$this->get_data(); |
| 49 |
} |
| 50 |
|
| 51 |
if ( ! isset( self::$contact_segmentation['id'] ) || empty( WC()->session->cart_totals ) ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$cart_total = WC()->session->cart_totals; |
| 56 |
$id = self::$contact_segmentation['id']; |
| 57 |
$value = $this->get_content_meta( $id, 'cart-subtotal' ); |
| 58 |
|
| 59 |
if ( ! is_array( $value ) ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
$theshold = 0; |
| 64 |
|
| 65 |
if ( ! isset( $value['threshold_range'] ) || ! isset( $value['target_subtotal_amount'] ) ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
if ( $cart_total['subtotal'] > $value['threshold_range'] && $cart_total['subtotal'] < $value['target_subtotal_amount'] ) { |
| 70 |
$theshold = $value['target_subtotal_amount'] - $cart_total['subtotal']; |
| 71 |
} |
| 72 |
|
| 73 |
return $theshold; |
| 74 |
} |
| 75 |
} |
| 76 |
|