PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.7
YayMail – WooCommerce Email Customizer v4.4.7
4.4.7 4.4.6 4.4.5 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 All 58 releases
yaymail / src / Shortcodes / FulfillmentShortcodes.php

FulfillmentShortcodes.php in YayMail – WooCommerce Email Customizer 4.4.7, at src/Shortcodes/FulfillmentShortcodes.php

99 lines 3.7 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 * Shortcodes for WC core fulfillment emails (WC 10.1, `fulfillments` feature).
11 *
12 * @since 4.4.7
13 * @method: static FulfillmentShortcodes get_instance()
14 */
15 class FulfillmentShortcodes extends BaseShortcode {
16 use SingletonTrait;
17
18 protected function __construct() {
19 $this->available_email_ids = [ 'customer_fulfillment_created', 'customer_fulfillment_updated', 'customer_fulfillment_deleted' ];
20 parent::__construct();
21 }
22
23 public function get_shortcodes() {
24 $shortcodes = [];
25 $shortcodes[] = [
26 'name' => 'yaymail_fulfillment_details',
27 'description' => __( 'Fulfillment Details', 'yaymail' ),
28 'group' => 'fulfillments',
29 'callback' => [ $this, 'yaymail_fulfillment_details' ],
30 ];
31 $shortcodes[] = [
32 'name' => 'yaymail_fulfillment_note',
33 'description' => __( 'Fulfillment Note From The Store', 'yaymail' ),
34 'group' => 'fulfillments',
35 'callback' => [ $this, 'yaymail_fulfillment_note' ],
36 ];
37 return $shortcodes;
38 }
39
40 /**
41 * Render WC's own fulfillment details (tracking info + items) and fulfillment meta,
42 * via the same hooks the WC template fires.
43 */
44 public function yaymail_fulfillment_details( $data ) {
45 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
46 $order = Helpers::get_order_from_shortcode_data( $render_data );
47 $fulfillment = $render_data['fulfillment'] ?? null;
48
49 if ( ! empty( $render_data['is_sample'] ) || empty( $order ) || empty( $fulfillment ) ) {
50 return $this->get_sample_fulfillment_details();
51 }
52
53 $email = $render_data['email'] ?? '';
54
55 ob_start();
56 do_action( 'woocommerce_email_fulfillment_details', $order, $fulfillment, false, false, $email );
57 do_action( 'woocommerce_email_fulfillment_meta', $order, $fulfillment, false, false, $email );
58 return ob_get_clean();
59 }
60
61 /**
62 * Store note passed to the fulfillment updated email. Empty when no note was given.
63 */
64 public function yaymail_fulfillment_note( $data ) {
65 $render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
66
67 if ( ! empty( $render_data['is_sample'] ) ) {
68 $note = __( 'This is a sample note from the store. Your order has been updated with new tracking information.', 'woocommerce' );
69 } else {
70 $note = is_scalar( $render_data['customer_note'] ?? null ) ? trim( (string) $render_data['customer_note'] ) : '';
71 }
72
73 if ( '' === $note ) {
74 return '';
75 }
76
77 return '<p><strong>' . esc_html__( 'Note from the store:', 'woocommerce' ) . '</strong></p><blockquote>' . wp_kses_post( wpautop( wptexturize( $note ) ) ) . '</blockquote>';
78 }
79
80 /**
81 * Static preview for the editor, where no real fulfillment exists.
82 */
83 private function get_sample_fulfillment_details() {
84 $rows = [
85 __( 'Tracking number', 'yaymail' ) => '1Z999AA10123456784',
86 __( 'Shipping provider', 'yaymail' ) => 'UPS',
87 __( 'Items', 'yaymail' ) => __( 'Sample product × 1', 'yaymail' ),
88 ];
89
90 $html = '<table cellspacing="0" cellpadding="6" border="1" style="width: 100%; border-collapse: collapse;">';
91 foreach ( $rows as $label => $value ) {
92 $html .= '<tr><th scope="row" style="text-align: left;">' . esc_html( $label ) . '</th><td>' . esc_html( $value ) . '</td></tr>';
93 }
94 $html .= '</table>';
95
96 return $html;
97 }
98 }
99