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