1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 if ( ! class_exists( 'WC_Email_Customer_Invoice' ) ) :
6
7 8 9 10 11 12 13 14 15 16 17
18 class WC_Email_Customer_Invoice extends WC_Email {
19
20 var $find;
21 var $replace;
22
23 24 25
26 function __construct() {
27
28 $this->id = 'customer_invoice';
29 $this->title = __( 'Customer invoice', 'woocommerce' );
30 $this->description = __( 'Customer invoice emails can be sent to the user containing order info and payment links.', 'woocommerce' );
31
32 $this->template_html = 'emails/customer-invoice.php';
33 $this->template_plain = 'emails/plain/customer-invoice.php';
34
35 $this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce');
36 $this->heading = __( 'Invoice for order {order_number}', 'woocommerce');
37
38 $this->subject_paid = __( 'Your {site_title} order from {order_date}', 'woocommerce');
39 $this->heading_paid = __( 'Order {order_number} details', 'woocommerce');
40
41
42 parent::__construct();
43
44 $this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid );
45 $this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid );
46 }
47
48 49 50 51 52 53
54 function trigger( $order ) {
55
56 if ( ! is_object( $order ) ) {
57 $order = new WC_Order( absint( $order ) );
58 }
59
60 if ( $order ) {
61 $this->object = $order;
62 $this->recipient = $this->object->billing_email;
63
64 $this->find[] = '{order_date}';
65 $this->replace[] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
66
67 $this->find[] = '{order_number}';
68 $this->replace[] = $this->object->get_order_number();
69 }
70
71 if ( ! $this->get_recipient() )
72 return;
73
74 $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
75 }
76
77 78 79 80 81 82
83 function get_subject() {
84 if ( $this->object->status == 'processing' || $this->object->status == 'completed' )
85 return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $this->subject_paid ), $this->object );
86 else
87 return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $this->subject ), $this->object );
88 }
89
90 91 92 93 94 95
96 function get_heading() {
97 if ( $this->object->status == 'processing' || $this->object->status == 'completed' )
98 return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $this->heading_paid ), $this->object );
99 else
100 return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $this->heading ), $this->object );
101 }
102
103 104 105 106 107 108
109 function get_content_html() {
110 ob_start();
111 wc_get_template( $this->template_html, array(
112 'order' => $this->object,
113 'email_heading' => $this->get_heading(),
114 'sent_to_admin' => false,
115 'plain_text' => false
116 ) );
117 return ob_get_clean();
118 }
119
120 121 122 123 124 125
126 function get_content_plain() {
127 ob_start();
128 wc_get_template( $this->template_plain, array(
129 'order' => $this->object,
130 'email_heading' => $this->get_heading(),
131 'sent_to_admin' => false,
132 'plain_text' => true
133 ) );
134 return ob_get_clean();
135 }
136
137 138 139 140 141 142
143 function init_form_fields() {
144 $this->form_fields = array(
145 'subject' => array(
146 'title' => __( 'Email subject', 'woocommerce' ),
147 'type' => 'text',
148 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
149 'placeholder' => '',
150 'default' => ''
151 ),
152 'heading' => array(
153 'title' => __( 'Email heading', 'woocommerce' ),
154 'type' => 'text',
155 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
156 'placeholder' => '',
157 'default' => ''
158 ),
159 'subject_paid' => array(
160 'title' => __( 'Email subject (paid)', 'woocommerce' ),
161 'type' => 'text',
162 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_paid ),
163 'placeholder' => '',
164 'default' => ''
165 ),
166 'heading_paid' => array(
167 'title' => __( 'Email heading (paid)', 'woocommerce' ),
168 'type' => 'text',
169 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_paid ),
170 'placeholder' => '',
171 'default' => ''
172 ),
173 'email_type' => array(
174 'title' => __( 'Email type', 'woocommerce' ),
175 'type' => 'select',
176 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
177 'default' => 'html',
178 'class' => 'email_type',
179 'options' => array(
180 'plain' => __( 'Plain text', 'woocommerce' ),
181 'html' => __( 'HTML', 'woocommerce' ),
182 'multipart' => __( 'Multipart', 'woocommerce' ),
183 )
184 )
185 );
186 }
187 }
188
189 endif;
190
191 return new WC_Email_Customer_Invoice();