1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
4
|
|
|
exit; |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
if ( ! class_exists( 'WC_Email_Failed_Order' ) ) : |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Failed Order Email |
11
|
|
|
* |
12
|
|
|
* An email sent to the admin when payment fails to go through. |
13
|
|
|
* |
14
|
|
|
* @class WC_Email_Failed_Order |
15
|
|
|
* @version 2.5.0 |
16
|
|
|
* @package WooCommerce/Classes/Emails |
17
|
|
|
* @author WooThemes |
18
|
|
|
* @extends WC_Email |
19
|
|
|
*/ |
20
|
|
|
class WC_Email_Failed_Order extends WC_Email { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor |
24
|
|
|
*/ |
25
|
|
|
public function __construct() { |
26
|
|
|
$this->id = 'failed_order'; |
27
|
|
|
$this->title = __( 'Failed order', 'woocommerce' ); |
28
|
|
|
$this->description = __( 'Failed order emails are sent to chosen recipient(s) when orders have been marked failed (if they were previously processing or on-hold).', 'woocommerce' ); |
29
|
|
|
$this->heading = __( 'Failed order', 'woocommerce' ); |
30
|
|
|
$this->subject = __( '[{site_title}] Failed order ({order_number})', 'woocommerce' ); |
31
|
|
|
$this->template_html = 'emails/admin-failed-order.php'; |
32
|
|
|
$this->template_plain = 'emails/plain/admin-failed-order.php'; |
33
|
|
|
|
34
|
|
|
// Triggers for this email |
35
|
|
|
add_action( 'woocommerce_order_status_pending_to_failed_notification', array( $this, 'trigger' ) ); |
36
|
|
|
add_action( 'woocommerce_order_status_on-hold_to_failed_notification', array( $this, 'trigger' ) ); |
37
|
|
|
|
38
|
|
|
// Call parent constructor |
39
|
|
|
parent::__construct(); |
40
|
|
|
|
41
|
|
|
// Other settings |
42
|
|
|
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Trigger. |
47
|
|
|
* |
48
|
|
|
* @param int $order_id |
49
|
|
|
*/ |
50
|
|
|
public function trigger( $order_id ) { |
51
|
|
|
if ( $order_id ) { |
52
|
|
|
$this->object = wc_get_order( $order_id ); |
|
|
|
|
53
|
|
|
$this->find['order-date'] = '{order_date}'; |
54
|
|
|
$this->find['order-number'] = '{order_number}'; |
55
|
|
|
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) ); |
56
|
|
|
$this->replace['order-number'] = $this->object->get_order_number(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ( ! $this->is_enabled() || ! $this->get_recipient() ) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get content html. |
68
|
|
|
* |
69
|
|
|
* @access public |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function get_content_html() { |
73
|
|
|
return wc_get_template_html( $this->template_html, array( |
74
|
|
|
'order' => $this->object, |
75
|
|
|
'email_heading' => $this->get_heading(), |
76
|
|
|
'sent_to_admin' => true, |
77
|
|
|
'plain_text' => false, |
78
|
|
|
'email' => $this |
79
|
|
|
) ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get content plain. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function get_content_plain() { |
88
|
|
|
return wc_get_template_html( $this->template_plain, array( |
89
|
|
|
'order' => $this->object, |
90
|
|
|
'email_heading' => $this->get_heading(), |
91
|
|
|
'sent_to_admin' => true, |
92
|
|
|
'plain_text' => true, |
93
|
|
|
'email' => $this |
94
|
|
|
) ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Initialise settings form fields. |
99
|
|
|
*/ |
100
|
|
|
public function init_form_fields() { |
101
|
|
|
$this->form_fields = array( |
102
|
|
|
'enabled' => array( |
103
|
|
|
'title' => __( 'Enable/Disable', 'woocommerce' ), |
104
|
|
|
'type' => 'checkbox', |
105
|
|
|
'label' => __( 'Enable this email notification', 'woocommerce' ), |
106
|
|
|
'default' => 'yes' |
107
|
|
|
), |
108
|
|
|
'recipient' => array( |
109
|
|
|
'title' => __( 'Recipient(s)', 'woocommerce' ), |
110
|
|
|
'type' => 'text', |
111
|
|
|
'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to <code>%s</code>.', 'woocommerce' ), esc_attr( get_option('admin_email') ) ), |
112
|
|
|
'placeholder' => '', |
113
|
|
|
'default' => '', |
114
|
|
|
'desc_tip' => true |
115
|
|
|
), |
116
|
|
|
'subject' => array( |
117
|
|
|
'title' => __( 'Subject', 'woocommerce' ), |
118
|
|
|
'type' => 'text', |
119
|
|
|
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', 'woocommerce' ), $this->subject ), |
120
|
|
|
'placeholder' => '', |
121
|
|
|
'default' => '', |
122
|
|
|
'desc_tip' => true |
123
|
|
|
), |
124
|
|
|
'heading' => array( |
125
|
|
|
'title' => __( 'Email Heading', 'woocommerce' ), |
126
|
|
|
'type' => 'text', |
127
|
|
|
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.', 'woocommerce' ), $this->heading ), |
128
|
|
|
'placeholder' => '', |
129
|
|
|
'default' => '', |
130
|
|
|
'desc_tip' => true |
131
|
|
|
), |
132
|
|
|
'email_type' => array( |
133
|
|
|
'title' => __( 'Email type', 'woocommerce' ), |
134
|
|
|
'type' => 'select', |
135
|
|
|
'description' => __( 'Choose which format of email to send.', 'woocommerce' ), |
136
|
|
|
'default' => 'html', |
137
|
|
|
'class' => 'email_type wc-enhanced-select', |
138
|
|
|
'options' => $this->get_email_type_options(), |
139
|
|
|
'desc_tip' => true |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
endif; |
146
|
|
|
|
147
|
|
|
return new WC_Email_Failed_Order(); |
148
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.