PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.0
YayMail – WooCommerce Email Customizer v4.4.0
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 / ShippingShortcodes.php

ShippingShortcodes.php in YayMail – WooCommerce Email Customizer 4.4.0, at src/Shortcodes/ShippingShortcodes.php

403 lines 12.5 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 ShippingShortcodes get_instance()
11 */
12 class ShippingShortcodes extends BaseShortcode {
13 use SingletonTrait;
14
15 public function get_shortcodes() {
16 $shortcodes = [];
17 $shortcodes[] = [
18 'name' => 'yaymail_shipping_address',
19 'description' => __( 'Shipping Address', 'yaymail' ),
20 'group' => 'shippings',
21 'callback' => [ $this, 'yaymail_shipping_address' ],
22 ];
23 $shortcodes[] = [
24 'name' => 'yaymail_shipping_address_1',
25 'description' => __( 'Shipping Address 1', 'yaymail' ),
26 'group' => 'shippings',
27 'callback' => [ $this, 'yaymail_shipping_address_1' ],
28 ];
29 $shortcodes[] = [
30 'name' => 'yaymail_shipping_address_2',
31 'description' => __( 'Shipping Address 2', 'yaymail' ),
32 'group' => 'shippings',
33 'callback' => [ $this, 'yaymail_shipping_address_2' ],
34 ];
35 $shortcodes[] = [
36 'name' => 'yaymail_shipping_first_name',
37 'description' => __( 'Shipping First Name', 'yaymail' ),
38 'group' => 'shippings',
39 'callback' => [ $this, 'yaymail_shipping_first_name' ],
40 ];
41 $shortcodes[] = [
42 'name' => 'yaymail_shipping_last_name',
43 'description' => __( 'Shipping Last Name', 'yaymail' ),
44 'group' => 'shippings',
45 'callback' => [ $this, 'yaymail_shipping_last_name' ],
46 ];
47
48 $shortcodes[] = [
49 'name' => 'yaymail_shipping_company',
50 'description' => __( 'Shipping Company', 'yaymail' ),
51 'group' => 'shippings',
52 'callback' => [ $this, 'yaymail_shipping_company' ],
53 ];
54 $shortcodes[] = [
55 'name' => 'yaymail_shipping_city',
56 'description' => __( 'Shipping City', 'yaymail' ),
57 'group' => 'shippings',
58 'callback' => [ $this, 'yaymail_shipping_city' ],
59 ];
60 $shortcodes[] = [
61 'name' => 'yaymail_shipping_country',
62 'description' => __( 'Shipping Country', 'yaymail' ),
63 'group' => 'shippings',
64 'callback' => [ $this, 'yaymail_shipping_country' ],
65 ];
66 $shortcodes[] = [
67 'name' => 'yaymail_shipping_state',
68 'description' => __( 'Shipping State', 'yaymail' ),
69 'group' => 'shippings',
70 'callback' => [ $this, 'yaymail_shipping_state' ],
71 ];
72 $shortcodes[] = [
73 'name' => 'yaymail_shipping_postcode',
74 'description' => __( 'Shipping Postal Code', 'yaymail' ),
75 'group' => 'shippings',
76 'callback' => [ $this, 'yaymail_shipping_postcode' ],
77 ];
78 $shortcodes[] = [
79 'name' => 'yaymail_shipping_phone',
80 'description' => __( 'Shipping Phone', 'yaymail' ),
81 'group' => 'shippings',
82 'callback' => [ $this, 'yaymail_shipping_phone' ],
83 ];
84 $shortcodes[] = [
85 'name' => 'yaymail_shipping_method',
86 'description' => __( 'Shipping Method', 'yaymail' ),
87 'group' => 'shippings',
88 'callback' => [ $this, 'yaymail_shipping_method' ],
89 ];
90 $shortcodes[] = [
91 'name' => 'yaymail_shipping_total',
92 'description' => __( 'Shipping Total', 'yaymail' ),
93 'group' => 'shippings',
94 'callback' => [ $this, 'yaymail_shipping_total' ],
95 ];
96 return $shortcodes;
97 }
98
99 /**
100 * Render order shipping shortcode
101 *
102 * @param $args includes
103 * $render_data
104 * $element
105 * $settings
106 * $is_placeholder
107 */
108 public function yaymail_shipping_address( $data ) {
109
110 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
111
112 if ( ! empty( $render_data['is_sample'] ) ) {
113 /**
114 * Is sample order
115 */
116 $html = yaymail_get_content( 'templates/shortcodes/shipping-address/sample.php' );
117 return $html;
118 }
119
120 $order = Helpers::get_order_from_shortcode_data( $render_data );
121
122 if ( empty( $order ) ) {
123 /**
124 * Not having order/order_id
125 */
126 return '';
127 }
128
129 $args = [
130 'order' => $order,
131 ];
132 $html = yaymail_get_content( 'templates/shortcodes/shipping-address/main.php', $args );
133 return $html;
134 }
135
136 public function yaymail_shipping_address_1( $data ) {
137 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
138
139 if ( ! empty( $render_data['is_sample'] ) ) {
140 /**
141 * Is sample order
142 */
143 return __( '755 E North Grove Rd', 'yaymail' );
144 }
145
146 $order = Helpers::get_order_from_shortcode_data( $render_data );
147
148 if ( empty( $order ) || empty( $order->get_shipping_address_1() ) ) {
149 /**
150 * Not having order_id
151 */
152 return '';
153 }
154
155 return $order->get_shipping_address_1();
156 }
157
158 public function yaymail_shipping_address_2( $data ) {
159 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
160
161 if ( ! empty( $render_data['is_sample'] ) ) {
162 /**
163 * Is sample order
164 */
165 return __( '755 E North Grove Rd', 'yaymail' );
166 }
167
168 $order = Helpers::get_order_from_shortcode_data( $render_data );
169
170 if ( empty( $order ) || empty( $order->get_shipping_address_2() ) ) {
171 /**
172 * Not having order_id
173 */
174 return '';
175 }
176
177 return $order->get_shipping_address_2();
178 }
179
180 public function yaymail_shipping_first_name( $data ) {
181 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
182
183 if ( ! empty( $render_data['is_sample'] ) ) {
184 /**
185 * Is sample order
186 */
187 return __( 'John', 'yaymail' );
188 }
189
190 $order = Helpers::get_order_from_shortcode_data( $render_data );
191
192 if ( empty( $order ) || empty( $order->get_shipping_first_name() ) ) {
193 /**
194 * Not having order_id
195 */
196 return '';
197 }
198
199 return $order->get_shipping_first_name();
200 }
201
202 public function yaymail_shipping_last_name( $data ) {
203 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
204
205 if ( ! empty( $render_data['is_sample'] ) ) {
206 /**
207 * Is sample order
208 */
209 return __( 'Doe', 'yaymail' );
210 }
211
212 $order = Helpers::get_order_from_shortcode_data( $render_data );
213
214 if ( empty( $order ) || empty( $order->get_shipping_last_name() ) ) {
215 /**
216 * Not having order_id
217 */
218 return '';
219 }
220
221 return $order->get_shipping_last_name();
222 }
223
224 public function yaymail_shipping_company( $data ) {
225 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
226
227 if ( ! empty( $render_data['is_sample'] ) ) {
228 /**
229 * Is sample order
230 */
231 return __( 'YayCommerce', 'yaymail' );
232 }
233
234 $order = Helpers::get_order_from_shortcode_data( $render_data );
235
236 if ( empty( $order ) || empty( $order->get_shipping_company() ) ) {
237 /**
238 * Not having order_id
239 */
240 return '';
241 }
242
243 return $order->get_shipping_company();
244 }
245
246 public function yaymail_shipping_city( $data ) {
247 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
248
249 if ( ! empty( $render_data['is_sample'] ) ) {
250 /**
251 * Is sample order
252 */
253 return __( 'Mayville, Michigan', 'yaymail' );
254 }
255
256 $order = Helpers::get_order_from_shortcode_data( $render_data );
257
258 if ( empty( $order ) || empty( $order->get_shipping_city() ) ) {
259 /**
260 * Not having order_id
261 */
262 return '';
263 }
264
265 return $order->get_shipping_city();
266 }
267
268 public function yaymail_shipping_country( $data ) {
269 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
270
271 if ( ! empty( $render_data['is_sample'] ) ) {
272 /**
273 * Is sample order
274 */
275 return __( 'United States', 'yaymail' );
276 }
277
278 $order = Helpers::get_order_from_shortcode_data( $render_data );
279
280 if ( empty( $order ) || empty( $order->get_shipping_country() ) ) {
281 /**
282 * Not having order_id
283 */
284 return '';
285 }
286 $order_shipping_country_code = $order->get_shipping_country();
287 $wc_countries = \WC()->countries;
288 return $wc_countries->countries[ $order_shipping_country_code ];
289 }
290
291 public function yaymail_shipping_state( $data ) {
292 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
293
294 if ( ! empty( $render_data['is_sample'] ) ) {
295 /**
296 * Is sample order
297 */
298 return __( 'Random', 'yaymail' );
299 }
300
301 $order = Helpers::get_order_from_shortcode_data( $render_data );
302
303 if ( empty( $order ) || empty( $order->get_shipping_state() ) ) {
304 /**
305 * Not having order_id
306 */
307 return '';
308 }
309
310 return $order->get_shipping_state();
311 }
312
313 public function yaymail_shipping_postcode( $data ) {
314 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
315
316 if ( ! empty( $render_data['is_sample'] ) ) {
317 /**
318 * Is sample order
319 */
320 return __( '48744', 'yaymail' );
321 }
322
323 $order = Helpers::get_order_from_shortcode_data( $render_data );
324
325 if ( empty( $order ) || empty( $order->get_shipping_postcode() ) ) {
326 /**
327 * Not having order_id
328 */
329 return '';
330 }
331
332 return $order->get_shipping_postcode();
333 }
334
335 public function yaymail_shipping_phone( $data ) {
336 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
337
338 if ( ! empty( $render_data['is_sample'] ) ) {
339 /**
340 * Is sample order
341 */
342 return __( '(910) 529-1147', 'yaymail' );
343 }
344
345 $order = Helpers::get_order_from_shortcode_data( $render_data );
346
347 if ( ! empty( $order ) && method_exists( $order, 'get_shipping_phone' ) && ! empty( $order->get_shipping_phone() ) ) {
348 return $order->get_shipping_phone();
349 }
350
351 // Not having order_id or empty shipping phone
352 return '';
353 }
354
355 public function yaymail_shipping_method( $data ) {
356 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
357
358 if ( ! empty( $render_data['is_sample'] ) ) {
359 /**
360 * Is sample order
361 */
362 return __( 'Free shipping', 'yaymail' );
363 }
364
365 $order = Helpers::get_order_from_shortcode_data( $render_data );
366
367 if ( empty( $order ) || empty( $order->get_shipping_method() ) ) {
368 /**
369 * Not having order_id
370 */
371 return '';
372 }
373
374 return $order->get_shipping_method();
375 }
376
377 public function yaymail_shipping_total( $data ) {
378 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
379
380 if ( ! empty( $render_data['is_sample'] ) ) {
381 /**
382 * Is sample order
383 */
384 return wc_price( 0 );
385 }
386
387 $order = Helpers::get_order_from_shortcode_data( $render_data );
388
389 if ( empty( $order ) || empty( $order->calculate_shipping() ) ) {
390 /**
391 * Not having order_id
392 */
393 return wc_price( 0 );
394 }
395
396 if ( isset( $order->get_data()['shipping_total'] ) && ! empty( $order->get_data()['shipping_total'] ) ) {
397 return wc_price( $order->get_data()['shipping_total'] + $order->get_data()['shipping_tax'], [ 'currency' => $order->get_currency() ] );
398 } else {
399 return wc_price( 0, [ 'currency' => $order->get_currency() ] );
400 }
401 }
402 }
403