PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 4.8.0
WooCommerce Square v4.8.0
5.5.0 5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Emails / Gift_Card_Sent.php
woocommerce-square / includes / Emails Last commit date
Access_Token_Email.php 2 years ago Base_Email.php 2 years ago Gift_Card_Sent.php 2 years ago Sync_Completed.php 2 years ago
Gift_Card_Sent.php
226 lines
1 <?php
2
3 namespace WooCommerce\Square\Emails;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * Gift card sent to recipient email.
11 *
12 * An email sent to the recipient of the gift card.
13 *
14 * @class Gift_Card_Sent
15 * @version 4.2.0
16 * @extends WC_Email
17 */
18 class Gift_Card_Sent extends \WC_Email {
19 /**
20 * Convenience object to retrieve email data
21 * related to gift card.
22 *
23 * @var null|object
24 */
25 public $gift_card_email_data = null;
26
27 /**
28 * Constructor.
29 */
30 public function __construct() {
31 $this->id = 'wc_square_gift_card_sent';
32 $this->title = __( 'Square Gift Card sent', 'woocommerce-square' );
33 $this->customer_email = true;
34 $this->description = __( 'This email is sent to the recipient of the Square Gift Card.', 'woocommerce-square' );
35 $this->template_html = 'emails/gift-card-sent.php';
36 $this->template_plain = 'emails/plain/gift-card-sent.php';
37 $this->placeholders = array(
38 '{square_gift_card_sender_name}' => '',
39 '{square_gift_card_number}' => '',
40 '{square_gift_card_balance}' => '',
41 '{square_gift_card_recipient_name}' => '',
42 '{square_gift_card_sender_message}' => '',
43 );
44
45 $this->gift_card_email_data = new \stdClass();
46
47 // Call parent constructor.
48 parent::__construct();
49 }
50
51 /**
52 * Get email subject.
53 *
54 * @since 4.2.0
55 *
56 * @return string
57 */
58 public function get_default_subject() {
59 return sprintf(
60 /* translators: %1$s - Store name */
61 __( '{square_gift_card_sender_name} sent you a %1$s Gift Card!', 'woocommerce-square' ),
62 esc_html( get_bloginfo( 'name' ) )
63 );
64 }
65
66 /**
67 * Get email heading.
68 *
69 * @since 4.2.0
70 *
71 * @return string
72 */
73 public function get_default_heading() {
74 return sprintf(
75 /* translators: %1$s - Store name */
76 __( '%1$s Gift Card received!', 'woocommerce-square' ),
77 esc_html( get_bloginfo( 'name' ) )
78 );
79 }
80
81 /**
82 * Trigger for the email.
83 *
84 * @since 4.2.0
85 *
86 * @param \WC_Order $order The WooCommerce order.
87 */
88 public function trigger( $order ) {
89 $this->setup_locale();
90
91 if ( ! $this->is_enabled() ) {
92 return;
93 }
94
95 if ( ! $this->does_order_contain_gift_card( $order ) ) {
96 return;
97 }
98
99 $this->object = wc_get_order( $order );
100 $items = $order->get_items();
101
102 /** @var WC_Order_Item_Product $item */
103 foreach ( $items as $item ) {
104 if ( 'new' !== $item->get_meta( '_square-gift-card-purchase-type' ) ) {
105 continue;
106 }
107
108 $recipient_email = $item->get_meta( 'square-gift-card-send-to-email' );
109
110 if ( ! $recipient_email ) {
111 continue;
112 }
113
114 $this->gift_card_email_data->sender_name = $item->get_meta( 'square-gift-card-sender-name' );
115 $this->gift_card_email_data->recipient_name = $item->get_meta( 'square-gift-card-sent-to-first-name' );
116 $this->gift_card_email_data->sender_message = $item->get_meta( 'square-gift-card-sent-to-message' );
117
118 $this->recipient = $recipient_email;
119 $this->placeholders['{square_gift_card_sender_name}'] = $this->gift_card_email_data->sender_name ? $this->gift_card_email_data->sender_name : $order->get_billing_first_name();
120 $this->placeholders['{square_gift_card_recipient_name}'] = $this->gift_card_email_data->recipient_name;
121 $this->placeholders['{square_gift_card_sender_message}'] = $this->gift_card_email_data->sender_message;
122 $this->placeholders['{square_gift_card_number}'] = $this->get_gift_card_gan( $order );
123 $this->placeholders['{square_gift_card_balance}'] = $this->get_gift_card_amount( $order );
124
125 $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
126 }
127
128 $this->restore_locale();
129 }
130
131 /**
132 * Returns the number of the gift card purchased.
133 *
134 * @since 4.2.0
135 *
136 * @param \WC_Order $order The Woo Order associated with the gift card purchase.
137 * @return string
138 */
139 private function get_gift_card_gan( $order ) {
140 return wc_square()->get_gateway( $order->get_payment_method() )->get_order_meta( $order, 'gift_card_number' );
141 }
142
143 /**
144 * Returns the amount loaded in the purchased gift card.
145 *
146 * @since 4.2.0
147 *
148 * @param \WC_Order $order The Woo Order associated with the gift card purchase.
149 * @return string
150 */
151 private function get_gift_card_amount( $order ) {
152 return wc_square()->get_gateway( $order->get_payment_method() )->get_order_meta( $order, 'gift_card_balance' );
153 }
154
155 /**
156 * Says if a Gift card was purchased in the order.
157 *
158 * @return boolean
159 */
160 private function does_order_contain_gift_card( $order ) {
161 return 'yes' === wc_square()->get_gateway( $order->get_payment_method() )->get_order_meta( $order, 'is_gift_card_purchased' );
162 }
163
164 /**
165 * Get content html.
166 *
167 * @since 4.2.0
168 *
169 * @return string
170 */
171 public function get_content_html() {
172 return wc_get_template_html(
173 $this->template_html,
174 array(
175 'order' => $this->object,
176 'gift_card_number' => $this->get_gift_card_gan( $this->object ),
177 'gift_card_balance' => $this->get_gift_card_amount( $this->object ),
178 'email_heading' => $this->get_heading(),
179 'additional_content' => $this->get_additional_content(),
180 'sent_to_admin' => false,
181 'plain_text' => false,
182 'email' => $this,
183 )
184 );
185 }
186
187 /**
188 * Get content plain.
189 *
190 * @since 4.2.0
191 *
192 * @return string
193 */
194 public function get_content_plain() {
195 return wc_get_template_html(
196 $this->template_plain,
197 array(
198 'order' => $this->object,
199 'gift_card_number' => $this->get_gift_card_gan( $this->object ),
200 'gift_card_balance' => $this->get_gift_card_amount( $this->object ),
201 'email_heading' => $this->get_heading(),
202 'additional_content' => $this->get_additional_content(),
203 'sent_to_admin' => false,
204 'plain_text' => true,
205 'email' => $this,
206 )
207 );
208 }
209
210 /**
211 * Default content to show below main email content.
212 *
213 * @since 4.2.0
214 *
215 * @return string
216 */
217 public function get_default_additional_content() {
218 return sprintf(
219 '%1$s <a href="%2$s">%3$s</a>',
220 esc_html__( 'We look forward to seeing you soon at', 'woocommerce-square' ),
221 esc_url( get_site_url() ),
222 esc_url( get_site_url() )
223 );
224 }
225 }
226