PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
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 / Emails / CustomerRefundedOrder.php

CustomerRefundedOrder.php in YayMail – WooCommerce Email Customizer trunk, at src/Emails/CustomerRefundedOrder.php

116 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Emails;
4
5 use YayMail\Abstracts\BaseEmail;
6 use YayMail\Elements\ElementsLoader;
7 use YayMail\Utils\SingletonTrait;
8 use YayMail\YayMailTemplate;
9
10 /**
11 * CustomerRefundedOrder Class
12 *
13 * @method static CustomerRefundedOrder get_instance()
14 */
15 class CustomerRefundedOrder extends BaseEmail {
16 use SingletonTrait;
17
18 protected function __construct() {
19 $emails = \WC_Emails::instance()->get_emails();
20 $email = $emails['WC_Email_Customer_Refunded_Order'];
21 if ( ! $email ) {
22 return;
23 }
24
25 $this->id = $email->id;
26 $this->title = $email->get_title();
27 $this->root_email = $email;
28 $this->recipient = function_exists( 'yaymail_get_email_recipient_zone' ) ? yaymail_get_email_recipient_zone( $email ) : '';
29
30 $this->render_priority = apply_filters( 'yaymail_email_render_priority', $this->render_priority, $this->id );
31 add_filter( 'wc_get_template', [ $this, 'get_template_file' ], $this->render_priority ?? 10, 3 );
32 $this->maybe_disable_block_email_editor();
33 }
34
35 public function get_default_elements() {
36 $email_title = '[yaymail_get_heading]';
37 // translators: customer name.
38 $email_hi = sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), '[yaymail_billing_first_name]' );
39 // translators: site name.
40 $email_text = sprintf( esc_html__( 'Your order on %s has been %s. There are more details below for your reference:', 'woocommerce' ), '[yaymail_site_name]', '[yaymail_refund_type]' );
41 $additional_text = __( 'We hope to see you again soon.', 'woocommerce' );
42
43 $default_elements = ElementsLoader::load_elements(
44 [
45 [
46 'type' => 'Logo',
47 ],
48 [
49 'type' => 'Heading',
50 'attributes' => [
51 'rich_text' => $email_title,
52 ],
53 ],
54 [
55 'type' => 'Text',
56 'attributes' => [
57 'rich_text' => '<p><span>' . $email_hi . '<br /></span></p><p><span>' . $email_text . '</span></p>',
58 ],
59 ],
60 [
61 'type' => 'OrderDetails',
62 ],
63 [
64 'type' => 'BillingShippingAddress',
65 ],
66 [
67 'type' => 'Text',
68 'attributes' => [
69 'rich_text' => '<p><span>' . $additional_text . '</span></p>',
70 'padding' => [
71 'top' => '0',
72 'right' => '50',
73 'bottom' => '38',
74 'left' => '50',
75 ],
76 ],
77 ],
78 [
79 'type' => 'Footer',
80 ],
81 ]
82 );
83
84 return $default_elements;
85 }
86
87 public function get_template_file( $located, $template_name, $args ) {
88 if ( ! isset( $args['email'] ) ) {
89 return $located;
90 }
91 if ( ! $args['email'] instanceof \WC_Email || ! $args['email'] instanceof \WC_Email_Customer_Refunded_Order ) {
92 return $located;
93 }
94 $template_path = $this->get_template_path();
95 if ( ! file_exists( $template_path ) ) {
96 return $located;
97 }
98
99 $order = apply_filters( 'yaymail_order_for_language', isset( $args['order'] ) ? $args['order'] : null, $args );
100
101 $language = $this->get_language( $order );
102
103 $this->template = new YayMailTemplate( $this->id, $language );
104
105 if ( ! $this->template->is_enabled() ) {
106 return $located;
107 }
108
109 return $template_path;
110 }
111
112 public function get_template_path() {
113 return yaymail_get_template( 'emails/customer-refunded-order.php', '', YAYMAIL_PLUGIN_PATH . 'templates/' );
114 }
115 }
116