These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Class WC_Email_Cancelled_Order file. |
||
4 | * |
||
5 | * @package WooCommerce\Emails |
||
6 | */ |
||
7 | |||
8 | 1 | if ( ! defined( 'ABSPATH' ) ) { |
|
9 | exit; |
||
10 | } |
||
11 | |||
12 | 1 | if ( ! class_exists( 'WC_Email_Cancelled_Order', false ) ) : |
|
13 | |||
14 | /** |
||
15 | * Cancelled Order Email. |
||
16 | * |
||
17 | * An email sent to the admin when an order is cancelled. |
||
18 | * |
||
19 | * @class WC_Email_Cancelled_Order |
||
20 | * @version 2.2.7 |
||
21 | * @package WooCommerce/Classes/Emails |
||
22 | * @extends WC_Email |
||
23 | */ |
||
24 | class WC_Email_Cancelled_Order extends WC_Email { |
||
25 | |||
26 | /** |
||
27 | * Constructor. |
||
28 | */ |
||
29 | 1 | View Code Duplication | public function __construct() { |
0 ignored issues
–
show
|
|||
30 | 1 | $this->id = 'cancelled_order'; |
|
31 | 1 | $this->title = __( 'Cancelled order', 'woocommerce' ); |
|
32 | 1 | $this->description = __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' ); |
|
33 | 1 | $this->template_html = 'emails/admin-cancelled-order.php'; |
|
34 | 1 | $this->template_plain = 'emails/plain/admin-cancelled-order.php'; |
|
35 | 1 | $this->placeholders = array( |
|
36 | '{order_date}' => '', |
||
37 | '{order_number}' => '', |
||
38 | '{order_billing_full_name}' => '', |
||
39 | ); |
||
40 | |||
41 | // Triggers for this email. |
||
42 | 1 | add_action( 'woocommerce_order_status_processing_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 ); |
|
43 | 1 | add_action( 'woocommerce_order_status_on-hold_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 ); |
|
44 | |||
45 | // Call parent constructor. |
||
46 | 1 | parent::__construct(); |
|
47 | |||
48 | // Other settings. |
||
49 | 1 | $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get email subject. |
||
54 | * |
||
55 | * @since 3.1.0 |
||
56 | * @return string |
||
57 | */ |
||
58 | 1 | public function get_default_subject() { |
|
59 | 1 | return __( '[{site_title}]: Order #{order_number} has been cancelled', 'woocommerce' ); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get email heading. |
||
64 | * |
||
65 | * @since 3.1.0 |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | public function get_default_heading() { |
|
69 | 1 | return __( 'Order Cancelled: #{order_number}', 'woocommerce' ); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Trigger the sending of this email. |
||
74 | * |
||
75 | * @param int $order_id The order ID. |
||
76 | * @param WC_Order|false $order Order object. |
||
77 | */ |
||
78 | View Code Duplication | public function trigger( $order_id, $order = false ) { |
|
79 | $this->setup_locale(); |
||
80 | |||
81 | if ( $order_id && ! is_a( $order, 'WC_Order' ) ) { |
||
82 | $order = wc_get_order( $order_id ); |
||
83 | } |
||
84 | |||
85 | if ( is_a( $order, 'WC_Order' ) ) { |
||
86 | $this->object = $order; |
||
87 | $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() ); |
||
88 | $this->placeholders['{order_number}'] = $this->object->get_order_number(); |
||
89 | $this->placeholders['{order_billing_full_name}'] = $this->object->get_formatted_billing_full_name(); |
||
90 | } |
||
91 | |||
92 | if ( $this->is_enabled() && $this->get_recipient() ) { |
||
93 | $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
||
94 | } |
||
95 | |||
96 | $this->restore_locale(); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get content html. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function get_content_html() { |
||
105 | return wc_get_template_html( |
||
106 | $this->template_html, |
||
107 | array( |
||
108 | 'order' => $this->object, |
||
109 | 'email_heading' => $this->get_heading(), |
||
110 | 'additional_content' => $this->get_additional_content(), |
||
111 | 'sent_to_admin' => true, |
||
112 | 'plain_text' => false, |
||
113 | 'email' => $this, |
||
114 | ) |
||
115 | ); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Get content plain. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | public function get_content_plain() { |
||
124 | return wc_get_template_html( |
||
125 | $this->template_plain, |
||
126 | array( |
||
127 | 'order' => $this->object, |
||
128 | 'email_heading' => $this->get_heading(), |
||
129 | 'additional_content' => $this->get_additional_content(), |
||
130 | 'sent_to_admin' => true, |
||
131 | 'plain_text' => true, |
||
132 | 'email' => $this, |
||
133 | ) |
||
134 | ); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Default content to show below main email content. |
||
139 | * |
||
140 | * @since 3.7.0 |
||
141 | * @return string |
||
142 | */ |
||
143 | 1 | public function get_default_additional_content() { |
|
144 | 1 | return __( 'Thanks for reading.', 'woocommerce' ); |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Initialise settings form fields. |
||
149 | */ |
||
150 | 1 | View Code Duplication | public function init_form_fields() { |
151 | /* translators: %s: list of placeholders */ |
||
152 | 1 | $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' ); |
|
153 | 1 | $this->form_fields = array( |
|
154 | 'enabled' => array( |
||
155 | 1 | 'title' => __( 'Enable/Disable', 'woocommerce' ), |
|
156 | 1 | 'type' => 'checkbox', |
|
157 | 1 | 'label' => __( 'Enable this email notification', 'woocommerce' ), |
|
158 | 1 | 'default' => 'yes', |
|
159 | ), |
||
160 | 'recipient' => array( |
||
161 | 1 | 'title' => __( 'Recipient(s)', 'woocommerce' ), |
|
162 | 1 | 'type' => 'text', |
|
163 | /* translators: %s: admin email */ |
||
164 | 1 | 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ), |
|
165 | 1 | 'placeholder' => '', |
|
166 | 1 | 'default' => '', |
|
167 | 'desc_tip' => true, |
||
168 | ), |
||
169 | 'subject' => array( |
||
170 | 1 | 'title' => __( 'Subject', 'woocommerce' ), |
|
171 | 1 | 'type' => 'text', |
|
172 | 'desc_tip' => true, |
||
173 | 1 | 'description' => $placeholder_text, |
|
174 | 1 | 'placeholder' => $this->get_default_subject(), |
|
175 | 1 | 'default' => '', |
|
176 | ), |
||
177 | 'heading' => array( |
||
178 | 1 | 'title' => __( 'Email heading', 'woocommerce' ), |
|
179 | 1 | 'type' => 'text', |
|
180 | 'desc_tip' => true, |
||
181 | 1 | 'description' => $placeholder_text, |
|
182 | 1 | 'placeholder' => $this->get_default_heading(), |
|
183 | 1 | 'default' => '', |
|
184 | ), |
||
185 | 'additional_content' => array( |
||
186 | 1 | 'title' => __( 'Additional content', 'woocommerce' ), |
|
187 | 1 | 'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text, |
|
188 | 1 | 'css' => 'width:400px; height: 75px;', |
|
189 | 1 | 'placeholder' => __( 'N/A', 'woocommerce' ), |
|
190 | 1 | 'type' => 'textarea', |
|
191 | 1 | 'default' => $this->get_default_additional_content(), |
|
192 | 'desc_tip' => true, |
||
193 | ), |
||
194 | 'email_type' => array( |
||
195 | 1 | 'title' => __( 'Email type', 'woocommerce' ), |
|
196 | 1 | 'type' => 'select', |
|
197 | 1 | 'description' => __( 'Choose which format of email to send.', 'woocommerce' ), |
|
198 | 1 | 'default' => 'html', |
|
199 | 1 | 'class' => 'email_type wc-enhanced-select', |
|
200 | 1 | 'options' => $this->get_email_type_options(), |
|
201 | 'desc_tip' => true, |
||
202 | ), |
||
203 | ); |
||
204 | } |
||
205 | } |
||
206 | |||
207 | endif; |
||
208 | |||
209 | return new WC_Email_Cancelled_Order(); |
||
210 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.