PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.4
YayMail – WooCommerce Email Customizer v4.3.4
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Shortcodes / BillingShortcodes.php

BillingShortcodes.php in YayMail – WooCommerce Email Customizer 4.3.4, at src/Shortcodes/BillingShortcodes.php

425 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Shortcodes;
4
5 use YayMail\Utils\Helpers;
6 use YayMail\Utils\SingletonTrait;
7 use YayMail\Abstracts\BaseShortcode;
8
9 /**
10 * @method: static BillingShortcodes get_instance()
11 */
12 class BillingShortcodes extends BaseShortcode {
13 use SingletonTrait;
14
15 public function get_shortcodes() {
16 $shortcodes = [];
17 $shortcodes[] = [
18 'name' => 'yaymail_billing_address',
19 'description' => __( 'Billing Address', 'yaymail' ),
20 'group' => 'billings',
21 'callback' => [ $this, 'yaymail_billing_address' ],
22 ];
23 $shortcodes[] = [
24 'name' => 'yaymail_billing_address_1',
25 'description' => __( 'Billing Address 1', 'yaymail' ),
26 'group' => 'billings',
27 'callback' => [ $this, 'yaymail_billing_address_1' ],
28 ];
29 $shortcodes[] = [
30 'name' => 'yaymail_billing_address_2',
31 'description' => __( 'Billing Address 2', 'yaymail' ),
32 'group' => 'billings',
33 'callback' => [ $this, 'yaymail_billing_address_2' ],
34 ];
35 $shortcodes[] = [
36 'name' => 'yaymail_billing_first_name',
37 'description' => __( 'Billing First Name', 'yaymail' ),
38 'group' => 'billings',
39 'callback' => [ $this, 'yaymail_billing_first_name' ],
40 ];
41 $shortcodes[] = [
42 'name' => 'yaymail_billing_last_name',
43 'description' => __( 'Billing Last Name', 'yaymail' ),
44 'group' => 'billings',
45 'callback' => [ $this, 'yaymail_billing_last_name' ],
46 ];
47 $shortcodes[] = [
48 'name' => 'yaymail_billing_company',
49 'description' => __( 'Billing Company', 'yaymail' ),
50 'group' => 'billings',
51 'callback' => [ $this, 'yaymail_billing_company' ],
52 ];
53 $shortcodes[] = [
54 'name' => 'yaymail_billing_city',
55 'description' => __( 'Billing City', 'yaymail' ),
56 'group' => 'billings',
57 'callback' => [ $this, 'yaymail_billing_city' ],
58 ];
59 $shortcodes[] = [
60 'name' => 'yaymail_billing_country',
61 'description' => __( 'Billing Country', 'yaymail' ),
62 'group' => 'billings',
63 'callback' => [ $this, 'yaymail_billing_country' ],
64 ];
65 $shortcodes[] = [
66 'name' => 'yaymail_billing_state',
67 'description' => __( 'Billing State', 'yaymail' ),
68 'group' => 'billings',
69 'callback' => [ $this, 'yaymail_billing_state' ],
70 ];
71 $shortcodes[] = [
72 'name' => 'yaymail_billing_postcode',
73 'description' => __( 'Billing Postal Code', 'yaymail' ),
74 'group' => 'billings',
75 'callback' => [ $this, 'yaymail_billing_postcode' ],
76 ];
77 $shortcodes[] = [
78 'name' => 'yaymail_billing_phone',
79 'description' => __( 'Billing Phone', 'yaymail' ),
80 'group' => 'billings',
81 'callback' => [ $this, 'yaymail_billing_phone' ],
82 ];
83 $shortcodes[] = [
84 'name' => 'yaymail_billing_email',
85 'description' => __( 'Billing Email', 'yaymail' ),
86 'group' => 'billings',
87 'callback' => [ $this, 'yaymail_billing_email' ],
88 ];
89 $shortcodes[] = [
90 'name' => 'yaymail_billing_shipping_address',
91 'description' => __( 'Billing Shipping Address', 'yaymail' ),
92 'group' => 'billings',
93 'callback' => [ $this, 'yaymail_billing_shipping_address' ],
94 ];
95 return $shortcodes;
96 }
97
98 /**
99 * Render order billing shortcode
100 *
101 * @param $args includes
102 * $render_data
103 * $element
104 * $settings
105 * $is_placeholder
106 */
107 public function yaymail_billing_shipping_address( $data ) {
108
109 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
110
111 $template = ! empty( $data['template'] ) ? $data['template'] : null;
112 if ( empty( $template ) ) {
113 $text_link_color = YAYMAIL_COLOR_WC_DEFAULT;
114 } else {
115 $text_link_color = $template->get_text_link_color();
116 }
117
118 if ( ! empty( $render_data['is_sample'] ) ) {
119 /**
120 * Is sample order
121 */
122 $args = [
123 'text_link_color' => $text_link_color,
124 ];
125 $html = yaymail_get_content( 'templates/shortcodes/billing-shipping-address/sample.php', $args );
126 return $html;
127 }
128
129 $order = Helpers::get_order_from_shortcode_data( $render_data );
130
131 if ( empty( $order ) ) {
132 /**
133 * Not having order/order_id
134 */
135 return '';
136 }
137
138 $args = [
139 'order' => $order,
140 'text_link_color' => $text_link_color,
141 ];
142 $html = yaymail_get_content( 'templates/shortcodes/billing-shipping-address/main.php', $args );
143 return $html;
144 }
145
146 public function yaymail_billing_address( $data ) {
147
148 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
149
150 if ( ! empty( $render_data['is_sample'] ) ) {
151 /**
152 * Is sample order
153 */
154 $html = yaymail_get_content( 'templates/shortcodes/billing-address/sample.php' );
155 return $html;
156 }
157
158 $order = Helpers::get_order_from_shortcode_data( $render_data );
159
160 if ( empty( $order ) ) {
161 /**
162 * Not having order/order_id
163 */
164 return '';
165 }
166
167 $args = [
168 'order' => $order,
169 ];
170 $html = yaymail_get_content( 'templates/shortcodes/billing-address/main.php', $args );
171 return $html;
172 }
173
174 public function yaymail_billing_address_1( $data ) {
175 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
176
177 if ( ! empty( $render_data['is_sample'] ) ) {
178 /**
179 * Is sample order
180 */
181 return __( '7400 Edwards Rd', 'yaymail' );
182 }
183
184 $order = Helpers::get_order_from_shortcode_data( $render_data );
185
186 if ( empty( $order ) || empty( $order->get_billing_address_1() ) ) {
187 /**
188 * Not having order_id
189 */
190 return '';
191 }
192
193 return $order->get_billing_address_1();
194 }
195
196 public function yaymail_billing_address_2( $data ) {
197 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
198
199 if ( ! empty( $render_data['is_sample'] ) ) {
200 /**
201 * Is sample order
202 */
203 return __( '7400 Edwards Rd', 'yaymail' );
204 }
205
206 $order = Helpers::get_order_from_shortcode_data( $render_data );
207
208 if ( empty( $order ) || empty( $order->get_billing_address_2() ) ) {
209 /**
210 * Not having order_id
211 */
212 return '';
213 }
214
215 return $order->get_billing_address_2();
216 }
217
218 public function yaymail_billing_first_name( $data ) {
219 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
220
221 if ( ! empty( $render_data['is_sample'] ) ) {
222 /**
223 * Is sample order
224 */
225 return __( 'John', 'yaymail' );
226 }
227
228 $order = Helpers::get_order_from_shortcode_data( $render_data );
229
230 if ( empty( $order ) || empty( $order->get_billing_first_name() ) ) {
231 /**
232 * Not having order_id
233 */
234 return '';
235 }
236
237 return $order->get_billing_first_name();
238 }
239
240 public function yaymail_billing_last_name( $data ) {
241 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
242
243 if ( ! empty( $render_data['is_sample'] ) ) {
244 /**
245 * Is sample order
246 */
247 return __( 'Doe', 'yaymail' );
248 }
249
250 $order = Helpers::get_order_from_shortcode_data( $render_data );
251
252 if ( empty( $order ) || empty( $order->get_billing_last_name() ) ) {
253 /**
254 * Not having order_id
255 */
256 return '';
257 }
258
259 return $order->get_billing_last_name();
260 }
261
262 public function yaymail_billing_company( $data ) {
263 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
264
265 if ( ! empty( $render_data['is_sample'] ) ) {
266 /**
267 * Is sample order
268 */
269 return __( 'YayCommerce', 'yaymail' );
270 }
271
272 $order = Helpers::get_order_from_shortcode_data( $render_data );
273
274 if ( empty( $order ) || empty( $order->get_billing_company() ) ) {
275 /**
276 * Not having order_id
277 */
278 return '';
279 }
280
281 return $order->get_billing_company();
282 }
283
284 public function yaymail_billing_city( $data ) {
285 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
286
287 if ( ! empty( $render_data['is_sample'] ) ) {
288 /**
289 * Is sample order
290 */
291 return __( 'Edwards Rd', 'yaymail' );
292 }
293
294 $order = Helpers::get_order_from_shortcode_data( $render_data );
295
296 if ( empty( $order ) || empty( $order->get_billing_city() ) ) {
297 /**
298 * Not having order_id
299 */
300 return '';
301 }
302
303 return $order->get_billing_city();
304 }
305
306 public function yaymail_billing_country( $data ) {
307 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
308
309 if ( ! empty( $render_data['is_sample'] ) ) {
310 /**
311 * Is sample order
312 */
313 return __( 'United States', 'yaymail' );
314 }
315
316 $order = Helpers::get_order_from_shortcode_data( $render_data );
317
318 if ( empty( $order ) || empty( $order->get_billing_country() ) ) {
319 /**
320 * Not having order_id
321 */
322 return '';
323 }
324 $order_billing_country_code = $order->get_billing_country();
325 $wc_countries = \WC()->countries;
326 return $wc_countries->countries[ $order_billing_country_code ];
327 }
328
329 public function yaymail_billing_state( $data ) {
330 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
331
332 if ( ! empty( $render_data['is_sample'] ) ) {
333 /**
334 * Is sample order
335 */
336 return __( 'Random', 'yaymail' );
337 }
338
339 $order = Helpers::get_order_from_shortcode_data( $render_data );
340
341 if ( empty( $order ) || empty( $order->get_billing_state() ) ) {
342 /**
343 * Not having order_id
344 */
345 return '';
346 }
347
348 return $order->get_billing_state();
349 }
350
351 public function yaymail_billing_postcode( $data ) {
352 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
353
354 if ( ! empty( $render_data['is_sample'] ) ) {
355 /**
356 * Is sample order
357 */
358 return __( '48744', 'yaymail' );
359 }
360
361 $order = Helpers::get_order_from_shortcode_data( $render_data );
362
363 if ( empty( $order ) || empty( $order->get_billing_postcode() ) ) {
364 /**
365 * Not having order_id
366 */
367 return '';
368 }
369
370 return $order->get_billing_postcode();
371 }
372
373 public function yaymail_billing_phone( $data ) {
374 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
375
376 if ( ! empty( $render_data['is_sample'] ) ) {
377 /**
378 * Is sample order
379 */
380 return __( '(910) 529-1147', 'yaymail' );
381 }
382
383 $order = Helpers::get_order_from_shortcode_data( $render_data );
384
385 if ( empty( $order ) || empty( $order->get_billing_phone() ) ) {
386 /**
387 * Not having order_id
388 */
389 return '';
390 }
391
392 return $order->get_billing_phone();
393 }
394
395 public function yaymail_billing_email( $data ) {
396 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
397
398 $template = ! empty( $data['template'] ) ? $data['template'] : null;
399 if ( empty( $template ) ) {
400 $text_link_color = YAYMAIL_COLOR_WC_DEFAULT;
401 } else {
402 $text_link_color = $template->get_text_link_color();
403 }
404
405 if ( ! empty( $render_data['is_sample'] ) ) {
406 /**
407 * Is sample order
408 */
409 return '<a href="#">' . __( 'johndoe@gmail.com', 'yaymail' ) . '</a>';
410
411 }
412
413 $order = Helpers::get_order_from_shortcode_data( $render_data );
414
415 if ( empty( $order ) || empty( $order->get_billing_email() ) ) {
416 /**
417 * Not having order_id
418 */
419 return '';
420 }
421
422 return '<a href="mailto:' . esc_url( $order->get_billing_email() ) . '">' . $order->get_billing_email() . '</a>';
423 }
424 }
425