PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / NonLoggedInUsers / Wholesale / Emails / AbstractApplicationEmail.php

AbstractApplicationEmail.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Wholesale/Emails/AbstractApplicationEmail.php

135 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Emails;
2
3 use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Models\WholesaleApplication;
4 use WC_Email;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Shared plumbing of the wholesale application e-mails: templates, the application object,
12 * and the standard WooCommerce e-mail settings.
13 */
14 abstract class AbstractApplicationEmail extends WC_Email {
15
16 /** @var WholesaleApplication|null */
17 public $object;
18
19 /** The action that sends this e-mail; receives the application id. */
20 abstract protected function getTriggerAction(): string;
21
22 public function __construct() {
23 $this->template_base = dirname( __DIR__ ) . '/views/';
24
25 parent::__construct();
26
27 // the "_notification" variant fired by WC_Emails::send_transactional_email() (see EmailsManager)
28 add_action( $this->getTriggerAction() . '_notification', array( $this, 'trigger' ), 10, 1 );
29 }
30
31 public function trigger( $applicationId ) {
32 $this->object = WholesaleApplication::get( (int) $applicationId );
33
34 if ( ! $this->object || ! $this->is_enabled() ) {
35 return;
36 }
37
38 $this->setup_locale();
39
40 if ( $this->customer_email ) {
41 $this->recipient = $this->object->getEmail();
42 }
43
44 $this->placeholders['{applicant_name}'] = $this->object->getName();
45 $this->placeholders['{company}'] = $this->object->getCompany();
46
47 if ( $this->get_recipient() ) {
48 $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
49 }
50
51 $this->restore_locale();
52 }
53
54 protected function getTemplateArgs( bool $plain ): array {
55 return array(
56 'application' => $this->object,
57 'emailHeading' => $this->get_heading(),
58 'sent_to_admin' => ! $this->customer_email,
59 'plain_text' => $plain,
60 'email' => $this,
61 );
62 }
63
64 public function get_content_html() {
65 return wc_get_template_html( $this->template_html, $this->getTemplateArgs( false ), '', $this->template_base );
66 }
67
68 public function get_content_plain() {
69 return wc_get_template_html( $this->template_plain, $this->getTemplateArgs( true ), '', $this->template_base );
70 }
71
72 public function init_form_fields() {
73 $fields = array(
74 'enabled' => array(
75 'title' => __( 'Enable/Disable', 'tier-pricing-table' ),
76 'type' => 'checkbox',
77 'label' => __( 'Enable this email notification', 'tier-pricing-table' ),
78 'default' => 'yes',
79 ),
80 );
81
82 if ( ! $this->customer_email ) {
83 $fields['recipient'] = array(
84 'title' => __( 'Recipient(s)', 'tier-pricing-table' ),
85 'type' => 'text',
86 /* translators: %s: admin e-mail */
87 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'tier-pricing-table' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
88 'placeholder' => '',
89 'default' => '',
90 'desc_tip' => true,
91 );
92 }
93
94 $fields['subject'] = array(
95 'title' => __( 'Subject', 'tier-pricing-table' ),
96 'type' => 'text',
97 'desc_tip' => true,
98 'description' => __( 'Available placeholders: {site_title}, {applicant_name}, {company}', 'tier-pricing-table' ),
99 'placeholder' => $this->get_default_subject(),
100 'default' => '',
101 );
102
103 $fields['heading'] = array(
104 'title' => __( 'Email heading', 'tier-pricing-table' ),
105 'type' => 'text',
106 'desc_tip' => true,
107 'description' => __( 'Available placeholders: {site_title}, {applicant_name}, {company}', 'tier-pricing-table' ),
108 'placeholder' => $this->get_default_heading(),
109 'default' => '',
110 );
111
112 $fields['additional_content'] = array(
113 'title' => __( 'Additional content', 'tier-pricing-table' ),
114 'description' => __( 'Text to appear below the main email content.', 'tier-pricing-table' ),
115 'css' => 'width:400px; height: 75px;',
116 'placeholder' => __( 'N/A', 'tier-pricing-table' ),
117 'type' => 'textarea',
118 'default' => $this->get_default_additional_content(),
119 'desc_tip' => true,
120 );
121
122 $fields['email_type'] = array(
123 'title' => __( 'Email type', 'tier-pricing-table' ),
124 'type' => 'select',
125 'description' => __( 'Choose which format of email to send.', 'tier-pricing-table' ),
126 'default' => 'html',
127 'class' => 'email_type wc-enhanced-select',
128 'options' => $this->get_email_type_options(),
129 'desc_tip' => true,
130 );
131
132 $this->form_fields = $fields;
133 }
134 }
135