PluginProbe
Order Tracking – WordPress Status Tracking Plugin / 3.2.2
Order Tracking – WordPress Status Tracking Plugin v3.2.2
3.5.4 3.5.3 3.5.2 3.5.1 3.5.0 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.3.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 All 235 releases
order-tracking / views / View.CustomerForm.class.php

View.CustomerForm.class.php in Order Tracking – WordPress Status Tracking Plugin 3.2.2, at views/View.CustomerForm.class.php

358 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class to display the customer form on the front end.
5 *
6 * @since 3.0.0
7 */
8 class ewdotpViewCustomerForm extends ewdotpView {
9
10 // Holds any matching orders based on submitted Customer ID and (optionally) email
11 public $customer_orders = array();
12
13 /**
14 * Render the view and enqueue required stylesheets
15 * @since 3.0.0
16 */
17 public function render() {
18 global $ewd_otp_controller;
19
20 $this->set_customer_orders();
21
22 $this->set_customer_options();
23
24 // Add any dependent stylesheets or javascript
25 $this->enqueue_assets();
26
27 // Add css classes to the slider
28 $this->classes = $this->get_classes();
29
30 ob_start();
31
32 $this->add_custom_styling();
33
34 $template = $this->find_template( 'customer-form' );
35
36 if ( $template ) {
37 include( $template );
38 }
39
40 $output = ob_get_clean();
41
42 return apply_filters( 'ewd_otp_customer_form_output', $output, $this );
43 }
44
45 /**
46 * Print the customer's orders, if any
47 *
48 * @since 3.0.0
49 */
50 public function maybe_print_customer_results() {
51
52 $form_submitted = isset($_POST['ewd_otp_form_type']) && 'customer_form' == $_POST['ewd_otp_form_type'];
53
54 if ( $form_submitted && empty( $this->customer_orders ) ) {
55
56 $this->error_message = __( 'No orders were found associated with the submitted customer number', 'order-tracking' );
57
58 $this->print_error_message();
59
60 return;
61 }
62
63 if( empty( $this->customer_orders ) ) { return; }
64
65 $template = $this->find_template( 'customer-results' );
66
67 if ( $template ) {
68 include( $template );
69 }
70 }
71
72 /**
73 * Print the customer ID input
74 *
75 * @since 3.0.0
76 */
77 public function print_customer_id_input() {
78
79 $template = $this->find_template( 'form-identifier-number' );
80
81 if ( $template ) {
82 include( $template );
83 }
84 }
85
86 /**
87 * Print the customer email input, if enabled
88 *
89 * @since 3.0.0
90 */
91 public function maybe_print_customer_email_input() {
92 global $ewd_otp_controller;
93
94 if ( ! $ewd_otp_controller->settings->get_setting( 'email-verification' ) ) { return; }
95
96 $template = $this->find_template( 'form-email' );
97
98 if ( $template ) {
99 include( $template );
100 }
101 }
102
103 /**
104 * Print the customer's name, if selected
105 *
106 * @since 3.0.0
107 */
108 public function maybe_print_customer_name() {
109 global $ewd_otp_controller;
110
111 if ( ! in_array( 'customer_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
112
113 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->customer ) or empty( $this->customer->name ) ) ) { return; }
114
115 $template = $this->find_template( 'customer-name' );
116
117 if ( $template ) {
118 include( $template );
119 }
120 }
121
122 /**
123 * Print the customer's email, if selected
124 *
125 * @since 3.0.0
126 */
127 public function maybe_print_customer_email() {
128 global $ewd_otp_controller;
129
130 if ( ! in_array( 'customer_email', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
131
132 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->customer ) or empty( $this->customer->email ) ) ) { return; }
133
134 $template = $this->find_template( 'customer-email' );
135
136 if ( $template ) {
137 include( $template );
138 }
139 }
140
141 /**
142 * Print any custom fields that should be displayed
143 *
144 * @since 3.0.0
145 */
146 public function print_customer_custom_fields() {
147 global $ewd_otp_controller;
148
149 $custom_fields = $ewd_otp_controller->settings->get_customer_custom_fields();
150
151 foreach ( $custom_fields as $custom_field ) {
152
153 if ( ! $custom_field->front_end_display ) { continue; }
154
155 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->customer ) or empty( $this->customer->custom_fields[ $custom_field->id ] ) ) ) { continue; }
156
157 $custom_field->value = $this->customer->custom_fields[ $custom_field->id ];
158
159 $this->custom_field = $custom_field;
160
161 $this->print_custom_field();
162 }
163 }
164
165 /**
166 * Print the header for the customer orders table
167 *
168 * @since 3.0.0
169 */
170 public function print_customer_orders_header() {
171
172 $template = $this->find_template( 'matching-order-header' );
173
174 if ( $template ) {
175 include( $template );
176 }
177 }
178
179 /**
180 * Print the orders for the customer orders table
181 *
182 * @since 3.0.0
183 */
184 public function print_customer_orders() {
185
186 $template = $this->find_template( 'matching-order' );
187
188 foreach ( $this->customer_orders as $order ) {
189
190 $this->current_order = $order;
191
192 if ( $template ) {
193 include( $template );
194 }
195 }
196 }
197
198 /**
199 * Print the download button for customer orders, if enabled
200 *
201 * @since 3.0.0
202 */
203 public function maybe_print_customer_download_button() {
204 global $ewd_otp_controller;
205
206 if ( empty( $ewd_otp_controller->settings->get_setting( 'allow-customer-downloads' ) ) ) { return; }
207
208 $template = $this->find_template( 'customer-download-button' );
209
210 if ( $template ) {
211 include( $template );
212 }
213 }
214
215 /**
216 * Print the customer form submit button
217 *
218 * @since 3.0.0
219 */
220 public function print_customer_form_submit() {
221
222 $template = $this->find_template( 'form-submit' );
223
224 if ( $template ) {
225 include( $template );
226 }
227 }
228
229 /**
230 * Returns the placeholder for the customer number field
231 *
232 * @since 3.0.0
233 */
234 public function get_identifier_placeholder_label() {
235
236 return $this->get_label( 'label-customer-form-number-placeholder' );
237 }
238
239 /**
240 * Returns the placeholder for the customer email field
241 *
242 * @since 3.0.0
243 */
244 public function get_email_placeholder_label() {
245
246 return $this->get_label( 'label-customer-form-email-placeholder' );
247 }
248
249 /**
250 * Returns true if a link to order tracking results should be included, false otherwise
251 *
252 * @since 3.0.0
253 */
254 public function include_separate_tracking_link() {
255
256 if ( empty( $this->get_option( 'disable-ajax-loading' ) ) ) { return false; }
257
258 if ( empty( $this->get_option( 'tracking-page-url' ) ) ) { return false; }
259
260 return true;
261 }
262
263 /**
264 * Get the initial customer form css classes
265 * @since 3.0.0
266 */
267 public function get_classes( $classes = array() ) {
268 global $ewd_otp_controller;
269
270 $classes = array_merge(
271 $classes,
272 array(
273 'ewd-otp-customer-form-div',
274 'ewd-otp-form'
275 )
276 );
277
278 if ( ! empty( $ewd_otp_controller->settings->get_setting( 'disable-ajax-loading' ) ) ) {
279
280 $classes[] = 'ewd-otp-disable-ajax';
281 }
282
283 return apply_filters( 'ewd_otp_customer_form_classes', $classes, $this );
284 }
285
286 /**
287 * Allow some parameters to be overwritten with $_REQUEST parameters
288 * @since 3.0.0
289 */
290 public function set_request_parameters() {
291 global $ewd_otp_controller;
292
293 if ( empty( $_POST['ewd_otp_form_type'] ) or $_POST['ewd_otp_form_type'] != 'customer_form' ) { return; }
294
295 if ( empty( $_POST['ewd_otp_identifier_number'] ) ) { return; }
296
297 $customer = new ewdotpCustomer();
298
299 $customer->load_customer_from_number( sanitize_text_field( trim( $_POST['ewd_otp_identifier_number'] ) ) );
300
301 if ( $ewd_otp_controller->settings->get_setting( 'email-verification' ) and ! $customer->verify_customer_email( sanitize_email( $_POST['ewd_otp_form_email'] ) ) ) { return; }
302
303 $this->customer = $customer;
304 }
305
306 /**
307 * If a customer is set, fetch their matching orders
308 * @since 3.0.0
309 */
310 public function set_customer_orders() {
311
312 if ( empty( $this->customer->id ) ) { return; }
313
314 $args = array(
315 'after' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
316 'orders_per_page' => -1
317 );
318
319 $this->customer_orders = $this->customer->get_customer_orders( $args );
320 }
321
322 /**
323 * Add in default options when displaying in the admin appointments area
324 *
325 * @since 3.0.0
326 */
327 public function set_customer_options() {
328 global $ewd_otp_controller;
329
330 $this->nonce = wp_create_nonce( basename( __FILE__ ) );
331 $this->customer_form_title = ! empty( $this->order_form_title ) ? $this->order_form_title : $this->get_label( 'label-customer-form-title' );
332 $this->customer_form_instructions = ! empty( $this->order_instructions ) ? $this->order_instructions : $this->get_label( 'label-customer-form-instructions' );
333 $this->order_field_text = ! empty( $this->order_field_text ) ? $this->order_field_text : $this->get_label( 'label-customer-form-number' );
334 $this->email_field_text = ! empty( $this->email_field_text ) ? $this->email_field_text : $this->get_label( 'label-customer-form-email' );
335 $this->submit_text = ! empty( $this->submit_text ) ? $this->submit_text : $this->get_label( 'label-customer-form-button' );
336 }
337
338 /**
339 * Enqueue the necessary CSS and JS files
340 * @since 3.0.0
341 */
342 public function enqueue_assets() {
343 global $ewd_otp_controller;
344
345 wp_enqueue_style( 'ewd-otp-css' );
346
347 $args = array(
348 'nonce' => wp_create_nonce( 'ewd-otp-js' ),
349 'retrieving_results' => $ewd_otp_controller->settings->get_setting( 'label-retrieving-results' ),
350 'customer_notes_submit' => $this->get_label( 'label-order-add-note-button' )
351 );
352
353 $ewd_otp_controller->add_front_end_php_data( 'ewd-otp-js', 'ewd_otp_php_data', $args );
354
355 wp_enqueue_script( 'ewd-otp-js' );
356 }
357 }
358