WC_Email_Customer_Invoice::init_form_fields()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 45
rs 8.8571
c 0
b 0
f 0
eloc 38
nc 1
nop 0
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit; // Exit if accessed directly
5
}
6
7
if ( ! class_exists( 'WC_Email_Customer_Invoice' ) ) :
8
9
/**
10
 * Customer Invoice.
11
 *
12
 * An email sent to the customer via admin.
13
 *
14
 * @class       WC_Email_Customer_Invoice
15
 * @version     2.3.0
16
 * @package     WooCommerce/Classes/Emails
17
 * @author      WooThemes
18
 * @extends     WC_Email
19
 */
20
class WC_Email_Customer_Invoice extends WC_Email {
21
22
	/**
23
	 * Strings to find in subjects/headings.
24
	 *
25
	 * @var array
26
	 */
27
	public $find;
28
29
	/**
30
	 * Strings to replace in subjects/headings.
31
	 *
32
	 * @var array
33
	 */
34
	public $replace;
35
36
	/**
37
	 * Constructor.
38
	 */
39
	public function __construct() {
40
41
		$this->id             = 'customer_invoice';
42
		$this->title          = __( 'Customer invoice', 'woocommerce' );
43
		$this->description    = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
44
45
		$this->template_html  = 'emails/customer-invoice.php';
46
		$this->template_plain = 'emails/plain/customer-invoice.php';
47
48
		$this->subject        = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce');
49
		$this->heading        = __( 'Invoice for order {order_number}', 'woocommerce');
50
51
		$this->subject_paid   = __( 'Your {site_title} order from {order_date}', 'woocommerce');
52
		$this->heading_paid   = __( 'Order {order_number} details', 'woocommerce');
53
54
		// Call parent constructor
55
		parent::__construct();
56
57
		$this->customer_email = true;
58
		$this->manual         = true;
59
		$this->heading_paid   = $this->get_option( 'heading_paid', $this->heading_paid );
60
		$this->subject_paid   = $this->get_option( 'subject_paid', $this->subject_paid );
61
	}
62
63
	/**
64
	 * Trigger.
65
	 *
66
	 * @param int|WC_Order $order
67
	 */
68
	public function trigger( $order ) {
69
70
		if ( ! is_object( $order ) ) {
71
			$order = wc_get_order( absint( $order ) );
72
		}
73
74
		if ( $order ) {
75
			$this->object                  = $order;
76
			$this->recipient               = $this->object->billing_email;
77
78
			$this->find['order-date']      = '{order_date}';
79
			$this->find['order-number']    = '{order_number}';
80
81
			$this->replace['order-date']   = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
82
			$this->replace['order-number'] = $this->object->get_order_number();
83
		}
84
85
		if ( ! $this->get_recipient() ) {
86
			return;
87
		}
88
89
		$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
90
	}
91
92
	/**
93
	 * Get email subject.
94
	 *
95
	 * @access public
96
	 * @return string
97
	 */
98 View Code Duplication
	public function get_subject() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
99
		if ( $this->object->has_status( array( 'processing', 'completed' ) ) ) {
100
			return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $this->subject_paid ), $this->object );
101
		} else {
102
			return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $this->subject ), $this->object );
103
		}
104
	}
105
106
	/**
107
	 * Get email heading.
108
	 *
109
	 * @access public
110
	 * @return string
111
	 */
112 View Code Duplication
	public function get_heading() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
113
		if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
114
			return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $this->heading_paid ), $this->object );
115
		} else {
116
			return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $this->heading ), $this->object );
117
		}
118
	}
119
120
	/**
121
	 * Get content html.
122
	 *
123
	 * @access public
124
	 * @return string
125
	 */
126
	public function get_content_html() {
127
		return wc_get_template_html( $this->template_html, array(
128
			'order'         => $this->object,
129
			'email_heading' => $this->get_heading(),
130
			'sent_to_admin' => false,
131
			'plain_text'    => false,
132
			'email'			=> $this
133
		) );
134
	}
135
136
	/**
137
	 * Get content plain.
138
	 *
139
	 * @access public
140
	 * @return string
141
	 */
142
	public function get_content_plain() {
143
		return wc_get_template_html( $this->template_plain, array(
144
			'order'         => $this->object,
145
			'email_heading' => $this->get_heading(),
146
			'sent_to_admin' => false,
147
			'plain_text'    => true,
148
			'email'			=> $this
149
		) );
150
	}
151
152
	/**
153
	 * Initialise settings form fields.
154
	 */
155
	public function init_form_fields() {
156
		$this->form_fields = array(
157
			'subject' => array(
158
				'title'         => __( 'Email Subject', 'woocommerce' ),
159
				'type'          => 'text',
160
				'description'   => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
161
				'placeholder'   => '',
162
				'default'       => '',
163
				'desc_tip'      => true
164
			),
165
			'heading' => array(
166
				'title'         => __( 'Email Heading', 'woocommerce' ),
167
				'type'          => 'text',
168
				'description'   => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
169
				'placeholder'   => '',
170
				'default'       => '',
171
				'desc_tip'      => true
172
			),
173
			'subject_paid' => array(
174
				'title'         => __( 'Email Subject (paid)', 'woocommerce' ),
175
				'type'          => 'text',
176
				'description'   => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_paid ),
177
				'placeholder'   => '',
178
				'default'       => '',
179
				'desc_tip'      => true
180
			),
181
			'heading_paid' => array(
182
				'title'         => __( 'Email Heading (paid)', 'woocommerce' ),
183
				'type'          => 'text',
184
				'description'   => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_paid ),
185
				'placeholder'   => '',
186
				'default'       => '',
187
				'desc_tip'      => true
188
			),
189
			'email_type' => array(
190
				'title'         => __( 'Email Type', 'woocommerce' ),
191
				'type'          => 'select',
192
				'description'   => __( 'Choose which format of email to send.', 'woocommerce' ),
193
				'default'       => 'html',
194
				'class'         => 'email_type wc-enhanced-select',
195
				'options'       => $this->get_email_type_options(),
196
				'desc_tip'      => true
197
			)
198
		);
199
	}
200
}
201
202
endif;
203
204
return new WC_Email_Customer_Invoice();
205