1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class WC_Email_Customer_On_Hold_Order file. |
4
|
|
|
* |
5
|
|
|
* @package WooCommerce\Emails |
6
|
|
|
*/ |
7
|
|
|
|
8
|
1 |
|
if ( ! defined( 'ABSPATH' ) ) { |
9
|
|
|
exit; // Exit if accessed directly. |
10
|
|
|
} |
11
|
|
|
|
12
|
1 |
|
if ( ! class_exists( 'WC_Email_Customer_On_Hold_Order', false ) ) : |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Customer On-hold Order Email. |
16
|
|
|
* |
17
|
|
|
* An email sent to the customer when a new order is on-hold for. |
18
|
|
|
* |
19
|
|
|
* @class WC_Email_Customer_On_Hold_Order |
20
|
|
|
* @version 2.6.0 |
21
|
|
|
* @package WooCommerce/Classes/Emails |
22
|
|
|
* @extends WC_Email |
23
|
|
|
*/ |
24
|
|
|
class WC_Email_Customer_On_Hold_Order extends WC_Email { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Constructor. |
28
|
|
|
*/ |
29
|
1 |
View Code Duplication |
public function __construct() { |
|
|
|
|
30
|
1 |
|
$this->id = 'customer_on_hold_order'; |
31
|
1 |
|
$this->customer_email = true; |
32
|
1 |
|
$this->title = __( 'Order on-hold', 'woocommerce' ); |
33
|
1 |
|
$this->description = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' ); |
34
|
1 |
|
$this->template_html = 'emails/customer-on-hold-order.php'; |
35
|
1 |
|
$this->template_plain = 'emails/plain/customer-on-hold-order.php'; |
36
|
1 |
|
$this->placeholders = array( |
37
|
|
|
'{order_date}' => '', |
38
|
|
|
'{order_number}' => '', |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
// Triggers for this email. |
42
|
1 |
|
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); |
43
|
1 |
|
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); |
44
|
1 |
|
add_action( 'woocommerce_order_status_cancelled_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); |
45
|
|
|
|
46
|
|
|
// Call parent constructor. |
47
|
1 |
|
parent::__construct(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get email subject. |
52
|
|
|
* |
53
|
|
|
* @since 3.1.0 |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
1 |
|
public function get_default_subject() { |
57
|
1 |
|
return __( 'Your {site_title} order has been received!', 'woocommerce' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get email heading. |
62
|
|
|
* |
63
|
|
|
* @since 3.1.0 |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
1 |
|
public function get_default_heading() { |
67
|
1 |
|
return __( 'Thank you for your order', 'woocommerce' ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Trigger the sending of this email. |
72
|
|
|
* |
73
|
|
|
* @param int $order_id The order ID. |
74
|
|
|
* @param WC_Order|false $order Order object. |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function trigger( $order_id, $order = false ) { |
77
|
|
|
$this->setup_locale(); |
78
|
|
|
|
79
|
|
|
if ( $order_id && ! is_a( $order, 'WC_Order' ) ) { |
80
|
|
|
$order = wc_get_order( $order_id ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ( is_a( $order, 'WC_Order' ) ) { |
84
|
|
|
$this->object = $order; |
85
|
|
|
$this->recipient = $this->object->get_billing_email(); |
86
|
|
|
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() ); |
87
|
|
|
$this->placeholders['{order_number}'] = $this->object->get_order_number(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ( $this->is_enabled() && $this->get_recipient() ) { |
91
|
|
|
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->restore_locale(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get content html. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function get_content_html() { |
103
|
|
|
return wc_get_template_html( |
104
|
|
|
$this->template_html, |
105
|
|
|
array( |
106
|
|
|
'order' => $this->object, |
107
|
|
|
'email_heading' => $this->get_heading(), |
108
|
|
|
'additional_content' => $this->get_additional_content(), |
109
|
|
|
'sent_to_admin' => false, |
110
|
|
|
'plain_text' => false, |
111
|
|
|
'email' => $this, |
112
|
|
|
) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get content plain. |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function get_content_plain() { |
122
|
|
|
return wc_get_template_html( |
123
|
|
|
$this->template_plain, |
124
|
|
|
array( |
125
|
|
|
'order' => $this->object, |
126
|
|
|
'email_heading' => $this->get_heading(), |
127
|
|
|
'additional_content' => $this->get_additional_content(), |
128
|
|
|
'sent_to_admin' => false, |
129
|
|
|
'plain_text' => true, |
130
|
|
|
'email' => $this, |
131
|
|
|
) |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Default content to show below main email content. |
137
|
|
|
* |
138
|
|
|
* @since 3.7.0 |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
1 |
|
public function get_default_additional_content() { |
142
|
1 |
|
return __( 'We look forward to fulfilling your order soon.', 'woocommerce' ); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
endif; |
147
|
|
|
|
148
|
|
|
return new WC_Email_Customer_On_Hold_Order(); |
149
|
|
|
|
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.