1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
4
|
|
|
exit; // Exit if accessed directly |
5
|
|
|
} |
6
|
|
|
|
7
|
|
View Code Duplication |
if ( ! class_exists( 'WC_Email_Customer_Processing_Order' ) ) : |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Customer On-hold Order Email. |
11
|
|
|
* |
12
|
|
|
* An email sent to the customer when a new order is on-hold for. |
13
|
|
|
* |
14
|
|
|
* @class WC_Email_Customer_On_Hold_Order |
15
|
|
|
* @version 2.0.0 |
16
|
|
|
* @package WooCommerce/Classes/Emails |
17
|
|
|
* @author WooThemes |
18
|
|
|
* @extends WC_Email |
19
|
|
|
*/ |
20
|
|
|
class WC_Email_Customer_On_Hold_Order extends WC_Email { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
*/ |
25
|
|
|
function __construct() { |
|
|
|
|
26
|
|
|
$this->id = 'customer_on_hold_order'; |
27
|
|
|
$this->customer_email = true; |
28
|
|
|
$this->title = __( 'Order on-hold', 'woocommerce' ); |
29
|
|
|
$this->description = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' ); |
30
|
|
|
$this->heading = __( 'Thank you for your order', 'woocommerce' ); |
31
|
|
|
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' ); |
32
|
|
|
$this->template_html = 'emails/customer-on-hold-order.php'; |
33
|
|
|
$this->template_plain = 'emails/plain/customer-on-hold-order.php'; |
34
|
|
|
|
35
|
|
|
// Triggers for this email |
36
|
|
|
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ) ); |
37
|
|
|
|
38
|
|
|
// Call parent constructor |
39
|
|
|
parent::__construct(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Trigger. |
44
|
|
|
* |
45
|
|
|
* @param int $order_id |
46
|
|
|
*/ |
47
|
|
|
function trigger( $order_id ) { |
|
|
|
|
48
|
|
|
|
49
|
|
|
if ( $order_id ) { |
50
|
|
|
$this->object = wc_get_order( $order_id ); |
51
|
|
|
$this->recipient = $this->object->billing_email; |
52
|
|
|
|
53
|
|
|
$this->find['order-date'] = '{order_date}'; |
54
|
|
|
$this->find['order-number'] = '{order_number}'; |
55
|
|
|
|
56
|
|
|
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) ); |
57
|
|
|
$this->replace['order-number'] = $this->object->get_order_number(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ( ! $this->is_enabled() || ! $this->get_recipient() ) { |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get content html. |
69
|
|
|
* |
70
|
|
|
* @access public |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
function get_content_html() { |
|
|
|
|
74
|
|
|
return wc_get_template_html( $this->template_html, array( |
75
|
|
|
'order' => $this->object, |
76
|
|
|
'email_heading' => $this->get_heading(), |
77
|
|
|
'sent_to_admin' => false, |
78
|
|
|
'plain_text' => false, |
79
|
|
|
'email' => $this |
80
|
|
|
) ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get content plain. |
85
|
|
|
* |
86
|
|
|
* @access public |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
function get_content_plain() { |
|
|
|
|
90
|
|
|
return wc_get_template_html( $this->template_plain, array( |
91
|
|
|
'order' => $this->object, |
92
|
|
|
'email_heading' => $this->get_heading(), |
93
|
|
|
'sent_to_admin' => false, |
94
|
|
|
'plain_text' => true, |
95
|
|
|
'email' => $this |
96
|
|
|
) ); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
endif; |
101
|
|
|
|
102
|
|
|
return new WC_Email_Customer_On_Hold_Order(); |
103
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.