| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Illuminate\Emails; |
| 4 |
|
| 5 |
use SpringDevs\Subscription\Traits\Email; |
| 6 |
use WC_Email; |
| 7 |
|
| 8 |
/** |
| 9 |
* Subscription Expired Mail to Customer. |
| 10 |
*/ |
| 11 |
class SubscriptionExpired extends WC_Email { |
| 12 |
|
| 13 |
use Email; |
| 14 |
|
| 15 |
/** |
| 16 |
* |
| 17 |
* Initialize the class. |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
$this->customer_email = true; |
| 21 |
|
| 22 |
$this->id = 'subscrpt_subscription_expired_email'; |
| 23 |
$this->title = __( 'Subscription expired', 'wp_subscription' ); |
| 24 |
$this->description = __( 'This email is sent to customer when a subscription expired.', 'wp_subscription' ); |
| 25 |
|
| 26 |
// email template path. |
| 27 |
$this->set_template( $this->id ); |
| 28 |
|
| 29 |
// Triggers for this email. |
| 30 |
add_action( 'subscrpt_subscription_expired_email_notification', array( $this, 'trigger' ) ); |
| 31 |
|
| 32 |
// Call parent constructor. |
| 33 |
parent::__construct(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get default subject. |
| 38 |
* |
| 39 |
* @return string |
| 40 |
*/ |
| 41 |
public function get_default_subject(): string { |
| 42 |
return __( '#{subscription_id} subscription expired!', 'wp_subscription' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get the customer email. |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public function get_recipient(): string { |
| 51 |
return get_the_author_meta( 'email', get_post_field( 'post_author', $this->subscription_id ) ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Trigger the mail. |
| 56 |
* |
| 57 |
* @param int $subscription_id Subscription id. |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function trigger( int $subscription_id ) { |
| 62 |
if ( 'no' === $this->enabled ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
$this->placeholders['{subscription_id}'] = $subscription_id; |
| 66 |
$this->subscription_id = $subscription_id; |
| 67 |
|
| 68 |
$this->set_table_data(); |
| 69 |
|
| 70 |
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Initialize form fields for settings. |
| 75 |
* |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
public function init_form_fields() { |
| 79 |
parent::init_form_fields(); |
| 80 |
unset( $this->form_fields['additional_content'] ); |
| 81 |
} |
| 82 |
} |
| 83 |
|