1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 if ( ! class_exists( 'WC_Email_Customer_Completed_Order' ) ) :
6
7 8 9 10 11 12 13 14 15 16 17
18 class WC_Email_Customer_Completed_Order extends WC_Email {
19
20 21 22
23 function __construct() {
24
25 $this->id = 'customer_completed_order';
26 $this->title = __( 'Completed order', 'woocommerce' );
27 $this->description = __( 'Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.', 'woocommerce' );
28
29 $this->heading = __( 'Your order is complete', 'woocommerce' );
30 $this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
31
32 $this->template_html = 'emails/customer-completed-order.php';
33 $this->template_plain = 'emails/plain/customer-completed-order.php';
34
35
36 add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) );
37
38
39 $this->heading_downloadable = $this->get_option( 'heading_downloadable', __( 'Your order is complete - download your files', 'woocommerce' ) );
40 $this->subject_downloadable = $this->get_option( 'subject_downloadable', __( 'Your {site_title} order from {order_date} is complete - download your files', 'woocommerce' ) );
41
42
43 parent::__construct();
44 }
45
46 47 48 49 50 51
52 function trigger( $order_id ) {
53
54 if ( $order_id ) {
55 $this->object = new WC_Order( $order_id );
56 $this->recipient = $this->object->billing_email;
57
58 $this->find[] = '{order_date}';
59 $this->replace[] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
60
61 $this->find[] = '{order_number}';
62 $this->replace[] = $this->object->get_order_number();
63 }
64
65 if ( ! $this->is_enabled() || ! $this->get_recipient() )
66 return;
67
68 $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
69 }
70
71 72 73 74 75 76
77 function get_subject() {
78 if ( ! empty( $this->object ) && $this->object->has_downloadable_item() )
79 return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject_downloadable ), $this->object );
80 else
81 return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject ), $this->object );
82 }
83
84 85 86 87 88 89
90 function get_heading() {
91 if ( ! empty( $this->object ) && $this->object->has_downloadable_item() )
92 return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading_downloadable ), $this->object );
93 else
94 return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading ), $this->object );
95 }
96
97 98 99 100 101 102
103 function get_content_html() {
104 ob_start();
105 wc_get_template( $this->template_html, array(
106 'order' => $this->object,
107 'email_heading' => $this->get_heading(),
108 'sent_to_admin' => false,
109 'plain_text' => false
110 ) );
111 return ob_get_clean();
112 }
113
114 115 116 117 118 119
120 function get_content_plain() {
121 ob_start();
122 wc_get_template( $this->template_plain, array(
123 'order' => $this->object,
124 'email_heading' => $this->get_heading(),
125 'sent_to_admin' => false,
126 'plain_text' => true
127 ) );
128 return ob_get_clean();
129 }
130
131 132 133 134 135 136
137 function init_form_fields() {
138 $this->form_fields = array(
139 'enabled' => array(
140 'title' => __( 'Enable/Disable', 'woocommerce' ),
141 'type' => 'checkbox',
142 'label' => __( 'Enable this email notification', 'woocommerce' ),
143 'default' => 'yes'
144 ),
145 'subject' => array(
146 'title' => __( '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_downloadable' => array(
160 'title' => __( 'Subject (downloadable)', 'woocommerce' ),
161 'type' => 'text',
162 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_downloadable ),
163 'placeholder' => '',
164 'default' => ''
165 ),
166 'heading_downloadable' => array(
167 'title' => __( 'Email Heading (downloadable)', 'woocommerce' ),
168 'type' => 'text',
169 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_downloadable ),
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_Completed_Order();