PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / markup / pages.php

pages.php in WPPizza – A Restaurant Plugin 3.20, at classes/markup/pages.php

2,369 lines 79.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MARKUP_PAGES Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPizza Pages Markup
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14 /* ================================================================================================================================= *
15 *
16 *
17 *
18 * CLASS - WPPIZZA_MARKUP_PAGES
19 *
20 *
21 *
22 * ================================================================================================================================= */
23
24 class WPPIZZA_MARKUP_PAGES{
25
26 /* should be defined for php 8.2+ */
27 public $thankyoupage_title;
28 public $thankyoupage_results_formatted;
29
30
31 /******************************************************************************
32 *
33 *
34 * [construct]
35 *
36 *
37 *******************************************************************************/
38 function __construct() {
39
40 /* get title and order details on thank you page */
41 add_action('wp', array($this, 'thankyou_order_info'));
42
43 /** add some localized js variables (validation rules)*/
44 add_filter('wppizza_filter_js_localize',array($this, 'localize_js_orderpage_validation_rules'));
45
46 /** thank you page, replace title/content , but keep title in navigation menu intact/as_is **/
47 add_filter('the_title', array($this, 'thankyoupage_title'), 10, 2);//set title
48 add_filter('pre_wp_nav_menu', array($this, 'remove_filter_thankyoupage_title'), 10, 2 );//don't change title in nav menu
49 add_filter('wp_nav_menu_items', array($this, 'reapply_filter_thankyoupage_title'), 10, 2 );// re-apply title filter after nav menu
50
51 }
52
53 /******************************************************************************
54 *
55 *
56 * [methods]
57 *
58 *
59 *******************************************************************************/
60 /***************************************
61 [get order details once to display right title and info
62 on thank you page (instead of running the query 2x) ]
63 ***************************************/
64 function thankyou_order_info($param, $type = 'thankyoupage'){
65 global $post, $wppizza_options;
66
67
68 /*
69 get relevant title and content on thank you page
70 */
71 if(is_object($post) && $wppizza_options['order_settings']['orderpage'] == $post->ID && ( isset($_GET[WPPIZZA_TRANSACTION_GET_PREFIX]) || isset($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]) ) ){
72
73 /*
74 get order from transaction hash
75 */
76 if(isset($_GET[WPPIZZA_TRANSACTION_GET_PREFIX])){
77
78 /****************************************
79 set the transaction order query args
80 ****************************************/
81 $args = array(
82 'query' => array(
83 'hash' => wppizza_sanitize_hash($_GET[WPPIZZA_TRANSACTION_GET_PREFIX]) ,
84 'payment_status' => array('COMPLETED', 'QUOTE', 'FAILED', 'INPROGRESS', 'AUTHORIZED', 'CAPTURED', 'CANCELLED', 'UNCONFIRMED', 'CONFIRMED', 'REJECTED', 'REFUNDED', 'PAYMENT_PENDING' ),
85 ),
86 );
87
88 }
89
90 /*
91 get order from cancel prefix hash
92 */
93 if(isset($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX])){
94 /****************************************
95 set the cancel order query args
96 ****************************************/
97 $args = array(
98 'query' => array(
99 'hash' => wppizza_sanitize_hash($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]) ,
100 'payment_status' => array('COMPLETED', 'FAILED', 'INPROGRESS', 'AUTHORIZED', 'CAPTURED', 'CANCELLED', 'UNCONFIRMED'),
101 ),
102 );
103
104 }
105
106 /*
107 add formatting arguments, run query and restun results
108 */
109 if(isset($_GET[WPPIZZA_TRANSACTION_GET_PREFIX]) || isset($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]) ){
110
111 /*
112 adding class idents, distinct secion and adding all blog options
113 */
114 $args['format'] = array(
115 'blog_options' => array('blog_options'),// add some additional - perhaps useful - info to pass on to gateways
116 'sections' => true,//leave order sections in its distinct [section] array to use in templates generation
117 );
118
119 /*************************************************
120 run query, and get results
121 even single order results are always arrays
122 so simply use reset here
123 *************************************************/
124 $results_formatted = WPPIZZA() -> db -> get_orders($args, $type);
125 $results_formatted = reset($results_formatted['orders']);
126 }
127
128
129 /*
130 cast payment status to uppercase for legacy reasons
131 as it will also be passed on to
132 $this -> thankyoupage_results_formatted
133 */
134 if(!empty($results_formatted)){
135
136 $results_formatted['sections']['ordervars']['payment_status']['value'] = strtoupper($results_formatted['sections']['ordervars']['payment_status']['value']);
137 $payment_status = strtoupper($results_formatted['sections']['ordervars']['payment_status']['value']);
138
139 /********************
140 add action hook that can be used
141 to - for example - alter localizations
142 only run whene there are actually results
143 ********************/
144 do_action('wppizza_thankyou_order_info', $payment_status, $results_formatted);
145 }
146
147
148 /********************
149 get/set page title
150 ********************/
151
152 /* generic | unknown | failed */
153 $this -> thankyoupage_title = $wppizza_options['localization']['generic_error_label'];
154
155
156 /* cancelled */
157 if((!empty($payment_status) && $payment_status == 'CANCELLED') || isset($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]) ){
158 $this -> thankyoupage_title = $wppizza_options['localization']['order_cancelled'];
159 }
160
161 /* payment pending */
162 if(!empty($payment_status) && $payment_status == 'PAYMENT_PENDING'){
163 $this -> thankyoupage_title = $wppizza_options['localization']['order_payment_pending'];
164 }
165
166 /* in progress/captured - empty title as it's already displayed in the body*/
167 if(!empty($payment_status) && in_array( $payment_status, array('INPROGRESS', 'CAPTURED') )){
168 $this -> thankyoupage_title = '&nbsp;';
169 }
170
171 /* unconfirmed */
172 if(!empty($payment_status) && $payment_status == 'UNCONFIRMED'){
173 $this -> thankyoupage_title = $wppizza_options['localization']['order_unconfirmed'];
174 }
175
176 /* confirmed, not yet executed */
177 if(!empty($payment_status) && $payment_status == 'CONFIRMED'){
178 $this -> thankyoupage_title = apply_filters('wppizza_filter_page_confirmed_title', '' , $results_formatted);
179 }
180
181 /* rejected */
182 if(!empty($payment_status) && $payment_status == 'REJECTED'){
183 $this -> thankyoupage_title = apply_filters('wppizza_filter_page_rejected_title', '' , $results_formatted);
184 }
185
186 /* completed or quote */
187 if(!empty($payment_status) && in_array( $payment_status, array('COMPLETED', 'QUOTE') )){
188 $this -> thankyoupage_title = $wppizza_options['localization']['thank_you'];
189 }
190
191 /* refunded */
192 if(!empty($payment_status) && $payment_status == 'REFUNDED'){
193 $this -> thankyoupage_title = apply_filters('wppizza_filter_page_refunded_title', '' , $results_formatted);
194 }
195
196 /* specifically set to error */
197 if(isset($_GET['e'])){
198 $this -> thankyoupage_title = $wppizza_options['localization']['generic_error_label'];
199 }
200
201 /********************
202 get/set order results formatted
203 ********************/
204 $this -> thankyoupage_results_formatted = !empty($results_formatted) ? $results_formatted : false;
205 }
206
207
208 return;
209 }
210
211 /***************************************
212 [change title in thank you page after order]
213 ***************************************/
214 function thankyoupage_title($title, $post_id = null) {
215 global $wppizza_options;
216 $orderpage_id = $wppizza_options['order_settings']['orderpage'];
217
218 if($orderpage_id == $post_id && is_page( $post_id ) && !empty($this -> thankyoupage_title)){
219 $title = $this -> thankyoupage_title;
220 }
221
222 return $title;
223 }
224 /***************************************
225 [do NOT change title in navigation menu]
226 ***************************************/
227 function remove_filter_thankyoupage_title( $nav_menu, $args ) {
228 // we are working with menu, so remove the title filter
229 remove_filter( 'the_title', array($this, 'thankyoupage_title'), 10, 2 );
230 return $nav_menu;
231 }
232 /***************************************
233 [RE-apply filter for page title on page ]
234 ***************************************/
235 function reapply_filter_thankyoupage_title( $items, $args ) {
236 // we are done working with menu, so add the title filter back
237 add_filter( 'the_title', array($this, 'thankyoupage_title'), 10, 2 );
238 return $items;
239 }
240
241 /***************************************
242 [add some localized js variables for validations]
243 orderpage only
244 ***************************************/
245 function localize_js_orderpage_validation_rules($localize){
246 /* bail if not orderpage and no orderpage widget*/
247 if(!wppizza_is_orderpage() && !wppizza_has_orderpage_widget()){
248 return $localize;
249 }
250
251 global $wppizza_options;
252
253 /*****************************
254 validation rules, as set in formfields
255 *****************************/
256 $validate_rules = array();
257 /** forced to orderpage (because it is parameter) */
258 foreach(WPPIZZA()->helpers->enabled_formfields(false, true, false) as $key=>$value){
259 $rules = $value['validation'];
260 foreach($rules as $rule_key => $rule_value)
261 if($rule_key != 'default'){
262 $validate_rules[$key][$rule_key] = $rule_value;
263 }
264 }
265 /*
266 add to localized script
267 */
268 $localize['validate']['rules'] = $validate_rules;
269
270 /*****************************
271 validation error messages
272 *****************************/
273 $validate_error['email'] = $wppizza_options['localization']['required_field_email'];
274 $validate_error['required'] = $wppizza_options['localization']['required_field'];
275 $validate_error['decimal'] = $wppizza_options['localization']['required_field_decimal'];
276 /* decode any entities */
277 foreach($validate_error as $jsmKey => $jsMessage){
278 $validate_error[$jsmKey] = wppizza_decode_entities($jsMessage);
279 }
280
281 /*
282 add to localized script
283 */
284 $localize['validate']['error'] = $validate_error;
285
286 return $localize;
287 }
288 /***************************************
289 [apply attributes]
290 ***************************************/
291 function markup($type, $atts = null, $is_admin = false){
292 global $wppizza_options, $post;
293
294 /*
295 since 3.19.2:
296 instead of altering 'the_content' which may cauase issue if other plugins or the theme itself filters it
297 we are simply changing the type attribute now
298 */
299 if (is_object($post) && $wppizza_options['order_settings']['orderpage'] == $post->ID && is_page( $post->ID )) {
300 //thank you
301 if(isset($_GET[WPPIZZA_TRANSACTION_GET_PREFIX])){
302 $type = 'thankyoupage';
303 }
304 //cancel
305 if(isset($_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX])){
306 $type = 'ordercancelled';
307 }
308 }
309
310
311 /* merge localization */
312 $txt = $wppizza_options['confirmation_form']['localization'] + $wppizza_options['localization'];
313
314 /* get session user data */
315 $user_session = WPPIZZA()->session->get_userdata();
316
317 /**get markup**/
318 if($type == 'orderpage'){
319 $markup = self::order_page($type, $atts, $txt, $user_session);
320 }
321
322 /**get markup**/
323 if($type == 'confirmationpage'){
324 $markup = self::confirmation_page($type, $atts, $txt, $user_session);
325 }
326
327 /**get markup**/
328 if($type == 'thankyoupage'){
329 $markup = self::thankyou_page($type, $atts, $txt, $user_session);
330 }
331
332 /**get markup**/
333 if($type == 'ordercancelled'){
334 $markup = self::cancelled_page($type, $atts, $txt, $user_session);
335 }
336
337 /**get markup (users order history)**/
338 if($type == 'orderhistory'){
339 $markup = self::orderhistory_page($type, $atts, $txt, $user_session);
340 }
341
342 /**get markup (admin, full order history)**/
343 if($type == 'admin_orderhistory' && $is_admin === true){
344 $markup = self::admin_orderhistory_page($type, $atts, $txt, $user_session);
345 }
346
347 /**get markup (admin_dashboard_widget)**/
348 if($type == 'admin_dashboard_widget' && $is_admin === true){
349 $markup = self::admin_dashboard_widget_page($type, $atts, $txt, $user_session);
350 }
351
352 return $markup;
353 }
354
355 /***************************************
356
357 [orderpage]
358
359 ***************************************/
360 function order_page($type, $atts , $txt, $user_session){
361 global $wppizza_options;
362
363 /****************************************
364 set the order query args
365 get order details form session hash and get formatted output
366 ****************************************/
367 $args = array(
368 'query' => array(
369 'hash' => (!empty($user_session['wppizza_hash']) ? $user_session['wppizza_hash']: '' ) ,
370 'payment_status' => array('INITIALIZED'),
371 ),
372 'format' => array(
373 'blog_options' => array('checkout_parameters', 'blog_options'),// add some additional info
374 'sections' => true,
375 ),
376 );
377 /*************************************************
378 run query, and get results
379 even single order results are always arrays
380 so simply use reset here
381 *************************************************/
382 $order_results = WPPIZZA() -> db -> get_orders($args, $type);
383 $order_results = reset($order_results['orders']);
384
385 /*************************************************
386 filter text depending on order results if needed
387 *************************************************/
388 $txt = apply_filters('wppizza_filter_orderpage_localization', $txt, $order_results, $type);
389
390 /*************************************************
391 cart will be empty if
392 - going directly to orderpage without ever having been to the site at all
393 - going to orderpage without ever having put anything into the cart
394
395 in both cases, there will not be any db entries added to keep the db entries
396 to a minimum
397 **************************************************/
398 $cart_empty = empty($order_results['sections']['order']) ? true : false ;
399
400 /*************************************************
401 show formfields from session as customer_ini
402 might not have been set yet and avoid php notices
403 if nothing was added to cart/db yet
404 *************************************************/
405 $order_formatted = (!$cart_empty) ? $order_results['sections'] : array();/* for consistency with carts etc */
406 $order_formatted['checkout_parameters'] = (!empty($order_results['checkout_parameters'])) ? $order_results['checkout_parameters']: array();
407
408
409 /*************************************************
410 set checkout parameters
411 *************************************************/
412 $shop_open = wppizza_is_shop_open();
413 $can_checkout = !empty($order_formatted['checkout_parameters']['can_checkout']) ? true : false;
414 $nocart = !empty($atts['nocart']) ? true : false;
415
416
417 /*
418 ids'|classes
419 */
420 $id = ''.WPPIZZA_PREFIX.'-order-wrap-'.$type.'';
421 $formid = ''.WPPIZZA_PREFIX.'-send-order';
422 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
423 if(!empty($order_formatted['checkout_parameters']['is_pickup'])){
424 $class .= ' '.WPPIZZA_PREFIX.'-order-ispickup';
425 }
426
427
428 $class_shop_closed = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-shop-closed';
429 $class_cart_empty = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-cart-empty';
430
431 $class_txt_shop_closed = ''.WPPIZZA_PREFIX.'-closed';
432
433 $order_fieldset_id = ''.WPPIZZA_PREFIX.'-order-details';
434 $order_fieldset_class = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-order-details';
435
436 $personal_fieldset_id = ''.WPPIZZA_PREFIX.'-personal-details';
437 $personal_fieldset_class = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-personal-details';
438
439 $payment_methods_fieldset_id = ''.WPPIZZA_PREFIX.'-payment-methods';
440 $payment_methods_fieldset_class = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-payment-methods';
441
442
443 /**************************************
444 login form - will never get here if no items in cart anyway
445 **************************************/
446 $login_form = WPPIZZA()->user->login_form();// uses markup/global/login.php
447
448 /**************************************
449 order
450 **************************************/
451 if(!$nocart && !$cart_empty){/* if cart not disabled by 'nocart=1|true' in shortcode/widget AND there are actually items in cart*/
452 /*
453 itemised items table
454 */
455 $order_details_itemised = WPPIZZA() -> markup_maincart -> itemised_markup($order_formatted, $type);
456
457 /*
458 subtotals/summary table
459 */
460 $order_details_summary = WPPIZZA() -> markup_maincart -> summary_markup($order_formatted, $type);
461 /*
462 pickup / delivery note
463 */
464 $order_details_pickup_note = self::pickup_note_markup($order_formatted, $type);
465 /*
466 pickup checkbox/toggle
467 */
468 $order_details_pickup_choices = WPPIZZA() -> markup_pickup_choice -> attributes($atts, $type);
469 }else{
470 /** avoid php notices **/
471 $order_details_itemised = '';
472 $order_details_summary = '';
473 $order_details_pickup_note = '';
474 $order_details_pickup_choices = '';
475
476 }
477 /*************************************
478 personal_details
479 *************************************/
480 /*
481 user input fields - unless cart is empty anyway
482 */
483 $personal_details = (!$cart_empty) ? WPPIZZA()->user->formfields_inputs($order_formatted['customer'], $order_formatted, $type) : false;
484
485 /*
486 user update info - within fieldset. might be an empty string if certain conditions are not met
487 */
488 $user_profile = (!$cart_empty) ? WPPIZZA()->user->profile_options() : false;
489
490
491 /**************************************
492 gateways buttons
493 **************************************/
494 $payment_methods ='';
495 if($can_checkout){/* will also have checked if there are any gateways enabled */
496 $payment_methods = WPPIZZA()->gateways->markup();
497 }
498
499
500 /**************************************
501 inline payment details - confirmation page not enabled
502 **************************************/
503 $payment_details = '';
504 if($can_checkout){/* will also have checked if there are any gateways enabled */
505 $payment_details = self::payment_details_markup($type, $order_formatted);
506 }
507
508
509 /**************************************
510 submit button provided one can actually checkout
511 **************************************/
512 $submit_error_div = '';//a generic - but empty - error div right before the submit button one can write any errors to if needed
513 $submit_button = '';//button or image
514 $submit_nonce = '';//nonce
515
516 if($can_checkout){
517 $button_class = array();
518 $button_class[] = 'submit';
519 $button_class[] = !empty($wppizza_options['confirmation_form']['confirmation_form_enabled']) ? ''.WPPIZZA_PREFIX.'-confirm-order' : ''.WPPIZZA_PREFIX.'-ordernow';/** are we using a confirmation form too ?**/
520 $button_class = implode(' ', $button_class);
521
522
523 /*
524 a generic - but empty - error div right before the submit button one can write any errors to if needed
525 @since v3.7 -update v3.12.14
526 */
527 $submit_error_div = '<div role="alert" id="'.WPPIZZA_PREFIX.'-submit-error" class="'.WPPIZZA_PREFIX.'-validation-error"></div>';
528
529
530 /**
531 use image instead of button
532 **/
533 $submit_image = apply_filters('wppizza_filter_submit_as_image', '');
534 if(!empty($submit_image)){
535 $submit_button .='<div id="'.WPPIZZA_PREFIX.'-ordernow" class="'. $button_class .' '.WPPIZZA_PREFIX.'-ordernow-img" title="'.$txt['send_order'].'" >';
536 $submit_button .='<input type="image" src="'.$submit_image.'" border="0" alt="'.$txt['send_order'].'" />';
537 $submit_button .='</div>';
538 }else{
539 $submit_button .='<input id="'.WPPIZZA_PREFIX.'-ordernow" class="'. $button_class .'" type="submit" style="display:block" value="'.$txt['send_order'].'" />';
540 }
541
542 /* add nonce */
543 $submit_nonce = ''.wp_nonce_field( '' . WPPIZZA_PREFIX . '_nonce_checkout','' . WPPIZZA_PREFIX . '_nonce_checkout',true,false).'';
544
545
546
547 /* add cache buster input - in conjunction with js force reloading order page when backpaging after cod order */
548 // removed as of 3.11.1 as we are actually using "window.performance.navigation.type" etc in js to achieve this
549 //$submit_button .='<input id="'.WPPIZZA_PREFIX.'_no_cache" type="hidden" name="'.WPPIZZA_PREFIX.'_no_cache" value="'.time().'" />';
550 }
551
552 /**
553 no checkout applies if min order not reached OR no gateway enabled.
554 only if min order applues will a note be displayed though
555 if there's no gateway enabled, then nothing will show
556 **/
557 /*
558 minimum order required text
559 */
560 $minimum_order = (!$cart_empty) ? WPPIZZA() -> markup_maincart -> minimum_order($order_formatted, $type) : false;
561
562
563 /*************************************
564
565 markup
566
567 *************************************/
568 /*
569 ini array
570 */
571 $markup = array();
572
573 /*
574 get markup
575 */
576 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.order.php')){
577 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.order.php');
578 }else{
579 require(WPPIZZA_PATH.'templates/markup/pages/page.order.php');
580 }
581
582
583 /*
584 Big Red Note if email sending is disabled
585 right after opening div
586 */
587 if(!empty($wppizza_options['tools']['disable_emails'])){
588 $markup['div_'] .= '<h3 style="color:red; text-align:center">'.wppizza_textdomain_dev('Note: Email sending has currently been disabled by the administrator.', 'wppizza-dev').'</h3>';
589 }
590
591 /*
592 Another Big Red Note if shop is forcefully opened
593 for a certain user id or ip address
594 right after opening div
595 */
596 if(!empty($wppizza_options['tools']['always_open_for_user']) && !empty(get_current_user_id()) ){
597 /* explode comma separated str to array */
598 $always_open_for_user = explode(',', $wppizza_options['tools']['always_open_for_user']);
599 if( in_array(get_current_user_id(), $always_open_for_user) || in_array($_SERVER['REMOTE_ADDR'], $always_open_for_user)){
600 $markup['div_'] .= '<h3 style="color:red; text-align:center">'.wppizza_textdomain_dev('Note: Shop is set to be always open for your UserID / IP-Address.', 'wppizza-dev').'</h3>';
601 }
602 }
603
604
605 /*
606 only displayed if shop is closed
607 and pickup choices were force-enabled with 'wppizza_filter_force_pickup_toggle_display' filter
608 and toggle is enabled on order page
609 make sure to wrap in form or the toggle does nothing
610 */
611 $force_pickup_toggle = apply_filters('wppizza_filter_force_pickup_toggle_display', false);
612 if(!$shop_open && !empty($force_pickup_toggle)){
613 /*
614 form start
615 */
616 $markup['form_'] = '<form id="' . $formid . '" method="post" accept-charset="' . WPPIZZA_CHARSET .'">';
617 $markup['order_details_pickup_choices'] = $order_details_pickup_choices ; /*uses: markup/global/pickup_choice.php */
618 $markup['_form'] = '</form>';
619 }
620
621 /*
622 apply filter if required and implode for output
623 3rd parameter indicates if we are using confirmation form
624 */
625 $markup = apply_filters('wppizza_filter_pages_order_markup', $markup, $order_formatted, $type, $wppizza_options['confirmation_form']['confirmation_form_enabled'] );
626
627 /*
628 if cart disabled by 'nocart=1|true' shortcode , remove fieldset
629 */
630 if($nocart){
631 unset($markup['order_details_']);
632 unset($markup['order_details_legend']);
633 unset($markup['order_details_itemised']);
634 unset($markup['order_details_summary']);
635 unset($markup['order_details_pickup_note']);
636 unset($markup['order_details_pickup_choices']);
637 unset($markup['_order_details']);
638 }
639
640 /*
641 add values for js wppizzaCartJson to the page
642 */
643 $jsoncart = WPPIZZA() -> markup_maincart -> get_cart_json($order_formatted, $type);
644 $markup['div_'] = $markup['div_'] . $jsoncart;
645
646 /*
647 implode the markup to string for output
648 */
649 $markup = implode('', $markup);
650
651 return $markup;
652
653 }
654
655 /***************************************
656
657 [confirmation page]
658
659 ***************************************/
660 function confirmation_page($type, $atts = null, $txt = array() , $user_session = array()){
661
662 /****************************************
663 set the order query args
664 get order details from db
665 ****************************************/
666 $args = array(
667 'query' => array(
668 'hash' => $user_session['wppizza_hash'] ,
669 'payment_status' => array('INITIALIZED'),
670 ),
671 'format' => array(
672 'blog_options' => array('confirmation', 'checkout_parameters', 'blog_options'),// add some additional info
673 'sections' => true,
674 ),
675 );
676 /*************************************************
677 run query, and get results
678 even single order results are always arrays
679 so simply use reset here
680 *************************************************/
681 $order_results = WPPIZZA() -> db -> get_orders($args, $type);
682 $order_results = reset($order_results['orders']);
683
684 /*************************************************
685 filter text depending on order results if needed
686 *************************************************/
687 $txt = apply_filters('wppizza_filter_orderpage_localization', $txt, $order_results, $type);
688
689
690 $order_formatted = $order_results['sections'];/* for consistency with carts etc */
691 $order_formatted['confirmation'] = $order_results['confirmation'];
692 $order_formatted['checkout_parameters'] = (!empty($order_results['checkout_parameters'])) ? $order_results['checkout_parameters']: array();
693
694 /**get links to order/amend pages*/
695 $href_orderpage = wppizza_page_links('orderpage');
696 $href_amendorder = wppizza_page_links('amendorderlink');
697 /** do we have any confirmation inputs ?*/
698 $has_inputs = !empty($order_formatted['confirmation']) ? true : false;
699
700
701 /*
702 ids'|classes
703 */
704 $id = ''.WPPIZZA_PREFIX.'-order-wrap-'.$type.'';
705 $class = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-wrap-'.$type.'';
706 if(!empty($order_formatted['ordervars']['pickup_delivery']['value']) && $order_formatted['ordervars']['pickup_delivery']['value'] == 'Y'){
707 $class .= ' '.WPPIZZA_PREFIX.'-order-ispickup';
708 }
709
710
711 $id_form = ''.WPPIZZA_PREFIX.'-send-order';
712 $class_form = ''.WPPIZZA_PREFIX.'-order-confirmed';
713
714 $class_legal = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-legal';
715 $class_personal_details = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-personal-details';
716 $class_payment_method = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-payment-method';
717
718 $id_order_details = ''.WPPIZZA_PREFIX.'-order-details-'.$type.'';
719 $class_order_details = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-order-details';
720
721 $id_subtotals_after = ''.WPPIZZA_PREFIX.'-'.$type.'-subtotals-after';
722
723
724
725
726
727 /***********************
728
729 [markup parameters]
730
731 ************************/
732
733 /*
734 confirmation form input fields
735 */
736 if($has_inputs){
737 $confirm_inputs = WPPIZZA()->user->formfields_inputs($order_formatted['confirmation'], $order_formatted, $type);
738 }
739 /*
740 personal_details
741 */
742 $personal_details= WPPIZZA()->user->formfields_values($order_formatted['customer'], 'confirmationpage');
743
744 /*
745 payment-method
746 */
747 $payment_method = WPPIZZA()->gateways->markup(true);
748
749 /*
750 order-details
751 */
752 /* pickup / delivery note */
753 $order_details_pickup_note = self::pickup_note_markup($order_formatted, $type);
754
755 /* order_itemised */
756 $order_details_itemised = WPPIZZA()->markup_maincart->itemised_markup($order_formatted, $type); /* cart_itemised */
757
758 /* order_summary */
759 $order_details_summary = WPPIZZA()->markup_maincart->summary_markup($order_formatted, $type); /* summary */
760
761
762 /*
763 inline payment details - confirmation page not enabled
764 */
765
766 $payment_details = self::payment_details_markup($type, $order_formatted);
767
768 /*
769 a generic - but empty - error div right before the submit button one can write any errors to if needed
770 @since v3.7 -update v3.12.14
771 */
772 $submit_error_div = '<div role="alert" id="'.WPPIZZA_PREFIX.'-submit-error" class="'.WPPIZZA_PREFIX.'-validation-error"></div>';
773
774 /*
775 submit_button
776 */
777 $submit_button ='<input id="'.WPPIZZA_PREFIX.'-ordernow" class="submit '.WPPIZZA_PREFIX.'-ordernow" type="submit" style="display:block" value="'.$txt['confirm_now_button'].'" />';
778
779 /*
780 add nonce
781 */
782 $submit_nonce = ''.wp_nonce_field( '' . WPPIZZA_PREFIX . '_nonce_checkout','' . WPPIZZA_PREFIX . '_nonce_checkout',true,false).'';
783 /* set flag that this is the confirmation page to not override session vars from main order page. simply added to nonce variable here */
784 $submit_nonce .='<input type="hidden" name="'.WPPIZZA_PREFIX.'_'.$type.'" value="1" />';
785
786 /*************************************
787
788 markup
789
790 *************************************/
791 /*
792 ini array
793 */
794 $markup = array();
795 /*
796 get markup
797 */
798 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.confirm-order.php')){
799 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.confirm-order.php');
800 }else{
801 require(WPPIZZA_PATH.'templates/markup/pages/page.confirm-order.php');
802 }
803 /*
804 apply filter if required and implode for output
805 3rd parameter (using confirmation form) is - obviously - true or we would never be here
806 */
807 $markup = apply_filters('wppizza_filter_pages_confirmorder_markup', $markup, $order_formatted, $type, true);
808
809 /*
810 add values for js wppizzaCartJson to the page
811 */
812 $markup['jsoncart'] = WPPIZZA() -> markup_maincart -> get_cart_json($order_formatted, $type);
813
814
815 /*
816 implode the markup to string for output
817 */
818 $markup = implode('', $markup);
819
820
821 return $markup;
822
823
824
825 }
826 /***************************************
827
828 [thank you page]
829
830 ***************************************/
831 function thankyou_page($type, $atts = null, $txt = array(), $user_session = array()){
832 global $wppizza_options, $blog_id ;
833 /*
834 also search failed and any progress statusses here to display errors or "waiting page" if necessary
835 furthermore, do not restrict to user id / 0 / session either. we will display those specifically
836 */
837 $show_results = false;
838 $is_order = false;
839 $is_completed = false;
840 $is_inprogress = false;
841 $is_payment_pending = false;
842 $is_unconfirmed = false;
843 $is_confirmed = false;
844 $is_cancelled = false;
845 $is_rejected = false;
846 $is_quote = false;
847 $is_refunded = false;
848 $order_page_link = '';
849
850
851 if(!empty($this -> thankyoupage_results_formatted)){
852
853 $order_results = $this -> thankyoupage_results_formatted;
854
855 $order_formatted = $order_results['sections'];/* for consistency with carts etc */
856
857 /** check if this order actually completed and not failed */
858 $is_completed = ($order_formatted['ordervars']['payment_status']['value'] == 'COMPLETED') ? true : false ;
859
860 /** in progress statusses, will make page reload a few times**/
861 $is_inprogress = (in_array($order_formatted['ordervars']['payment_status']['value'],array('INPROGRESS', 'AUTHORIZED', 'CAPTURED'))) ? true : false ;
862
863 /** payment_pending */
864 $is_payment_pending = ($order_formatted['ordervars']['payment_status']['value'] == 'PAYMENT_PENDING') ? true : false ;
865
866 /** unconfirmed status**/
867 $is_unconfirmed = (in_array($order_formatted['ordervars']['payment_status']['value'],array('UNCONFIRMED'))) ? true : false ;
868
869 /** confirmed status**/
870 $is_confirmed = (in_array($order_formatted['ordervars']['payment_status']['value'],array('CONFIRMED'))) ? true : false ;
871
872 /** rejected status**/
873 $is_rejected = (in_array($order_formatted['ordervars']['payment_status']['value'],array('REJECTED'))) ? true : false ;
874
875 /** refunded status**/
876 $is_refunded = (in_array($order_formatted['ordervars']['payment_status']['value'],array('REFUNDED'))) ? true : false ;
877
878 /** check if it was cancelled **/
879 $is_cancelled = (in_array($order_formatted['ordervars']['payment_status']['value'],array('CANCELLED'))) ? true : false ;
880
881 /** check if it was a quote **/
882 $is_quote = (in_array($order_formatted['ordervars']['payment_status']['value'],array('QUOTE'))) ? true : false ;
883
884 /** if failed order, return false **/
885 $is_order = ($is_completed || $is_quote) ? true : false ;
886
887 /**********************************************************
888 showing whole order , not just thank you if, enabled
889 with ['order_settings']['gateway_showorder_on_thankyou']
890 **********************************************************/
891 $show_results = apply_filters('wppizza_filter_showorder_on_thankyou', $show_results , $order_results);
892
893 /** if failed order or generally set to not show results on thank you page, return false **/
894 $show_results = (($is_completed || $is_quote) && $show_results) ? true : false ;
895
896 /**
897 if logged in and wp_user_id does not match or
898 not logged and sessionid does not match, do not show full results
899 **/
900 if(is_user_logged_in() && $order_formatted['ordervars']['wp_user_id']['value'] != get_current_user_id()){
901 $show_results = false;
902 }
903 if(!is_user_logged_in() && $order_formatted['ordervars']['session_id']['value'] != session_id()){
904 $show_results = false;
905 }
906
907
908 /** if failed order, get errors **/
909 $errors = ($is_completed || $is_quote || $is_inprogress) ? '' : $order_formatted['ordervars']['display_errors']['value_formatted'];
910
911 /*
912 ids'|classes
913 */
914 $id = ''.WPPIZZA_PREFIX.'-order-'.$type.'-'.$order_formatted['site']['blog_id']['value_formatted'].'-'.$order_formatted['ordervars']['order_id']['value_formatted'].'';
915
916 $class = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-wrap-'.$type.'';
917 /* add pickup class - if is pickup */
918 if(!empty($order_formatted['ordervars']['pickup_delivery']['value']) && $order_formatted['ordervars']['pickup_delivery']['value'] == 'Y'){
919 $class .= ' '.WPPIZZA_PREFIX.'-order-ispickup';
920 }
921 /* add quote class if required */
922 if($is_quote){
923 $class .= ' '.WPPIZZA_PREFIX.'-order-quote';
924 }
925
926
927 $class_transaction_details = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-transaction-details';
928 $class_personal_details = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-personal-details';
929 $class_order_details = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-order-details';
930
931 }else{
932 /*
933 in case there was an error or order does not exist
934 */
935 $id = ''.WPPIZZA_PREFIX.'-order-'.$type.'-error';
936 $class = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-wrap-'.$type.'-error';
937 $order_results = false;
938 $show_results = false;
939 $order_formatted = array();/* as there's no order just return an empty array */
940 $errors = '';/* no errors known as db returned no results */
941 }
942
943 /*************************************************
944 filter text depending on order results if needed
945 *************************************************/
946 $txt = apply_filters('wppizza_thankyoupage_localization', $txt, $order_results, $type);
947
948 /*
949 general error ids'|classes| links
950 */
951 $id_errors = ''.WPPIZZA_PREFIX.'-order-errors';
952 $class_errors = ''.WPPIZZA_PREFIX.'-order-error';
953 $id_noorder = ''.WPPIZZA_PREFIX.'-noorder-'.$type.'';
954 $class_noorder = ''.WPPIZZA_PREFIX.'-noorder';
955
956 /*
957 general processing ids'|classes| links
958 */
959 $id_processing = ''.WPPIZZA_PREFIX.'-order-processing';
960 $class_processing = ''.WPPIZZA_PREFIX.'-order-processing';
961 $id_wait = ''.WPPIZZA_PREFIX.'-processing-'.$type.'';
962 $class_wait = ''.WPPIZZA_PREFIX.'-processing';
963 $class_order_id = ''.WPPIZZA_PREFIX.'-order-processing-id';
964
965
966 /*
967 general payment_pending ids'|classes| links
968 */
969 $id_payment_pending_info = ''.WPPIZZA_PREFIX.'-payment_pending-'.$type.'';
970 $class_payment_pending_info = ''.WPPIZZA_PREFIX.'-payment_pending';
971
972
973 /*
974 general unconfirmed ids'|classes| links
975 */
976 $id_unconfirmed = ''.WPPIZZA_PREFIX.'-order-unconfirmed';
977 $class_unconfirmed = ''.WPPIZZA_PREFIX.'-order-unconfirmed';
978
979 /*
980 general confirmed ids'|classes| links
981 */
982 $id_confirmed = ''.WPPIZZA_PREFIX.'-order-confirmed';
983 $class_confirmed = ''.WPPIZZA_PREFIX.'-order-confirmed';
984
985 /*
986 general rejected ids'|classes| links
987 */
988 $id_rejected = ''.WPPIZZA_PREFIX.'-order-rejected';
989 $class_rejected = ''.WPPIZZA_PREFIX.'-order-rejected';
990
991 /*
992 general refunded ids'|classes| links
993 */
994 $id_refunded = ''.WPPIZZA_PREFIX.'-order-refunded';
995 $class_refunded = ''.WPPIZZA_PREFIX.'-order-refunded';
996
997
998 if(!$is_completed && !$is_quote && !$is_inprogress && !$is_payment_pending && !$is_cancelled && !$is_unconfirmed && !$is_confirmed && !$is_rejected && !$is_refunded){
999
1000 /**
1001 if
1002 - there's only the one '10003' "email to shop failed" error
1003 - the order was NOT a COD type order (i.e money was already paid )
1004 we'll display a "contact us" message as the shop whas not received an email in will perhaps know nothing about it
1005
1006 in all other cases (for now), display the standard try again link
1007 **/
1008 $is_10003_error = false;
1009 if(
1010 !empty($order_formatted['ordervars']['display_errors']['value']) &&
1011 is_array($order_formatted['ordervars']['display_errors']['value']) &&
1012 count($order_formatted['ordervars']['display_errors']['value']) == 1 &&
1013 $order_formatted['ordervars']['display_errors']['value'][0]['error_id'] == 10003 &&
1014 $order_formatted['ordervars']['payment_method']['value'] == 'prepaid'
1015 ){
1016 $is_10003_error = true;
1017 }
1018
1019 /*
1020 show link or contact us
1021 */
1022 if(!$is_10003_error){
1023 $order_page_link = wppizza_page_links();
1024 $order_page_link = '<div class="'.WPPIZZA_PREFIX.'-try-again"><a href="'.$order_page_link['orderpage'].'">'.$txt['failed_payment_try_again_link'].'</a></div>';
1025 }else{
1026 // replace order_page_link with "contact us" text (as payment will not actually have failed, only the shop will not have received the order as the shop email has issues)
1027 $txt['thank_you_error'] = $txt['thank_you_error_contact_us'];
1028 }
1029 }
1030
1031
1032 /***********************************************************
1033 empty cart session when order completed or in progress of completion
1034 ***********************************************************/
1035 if( $is_completed || $is_quote || $is_inprogress || $is_payment_pending || $is_unconfirmed || $is_confirmed || $is_rejected || $is_refunded){
1036 if(!WPPIZZA_DEV_DISABLE_CLEAR_CART){
1037 WPPIZZA()->session->empty_cart(true);
1038 }
1039 }
1040
1041 /**********************************************************
1042 showing whole order , not just thank you
1043 **********************************************************/
1044 if($show_results){
1045 /**************************************
1046 general transaction details
1047 **************************************/
1048 $transaction_details = self::order_transaction_details($order_formatted['ordervars'], $type);// uses markup/order/transaction_details.php
1049 /* pickup / delivery note */
1050 $order_details_pickup_note = self::pickup_note_markup($order_formatted, $type);//uses markup/global/pages.pickup_note.php
1051 /*************************************
1052 personal_details
1053 *************************************/
1054 $personal_details = WPPIZZA()->user->formfields_values($order_formatted['customer'], 'thankyoupage');//uses markup/global/formfields.values.php
1055 /************************************
1056 order-details : itemised, summary
1057 ************************************/
1058 /* order_itemised */
1059 $order_details_itemised = WPPIZZA()->markup_maincart->itemised_markup($order_formatted, $type); /* cart_itemised - uses markup/order/itemised.php */
1060 /* order_summary */
1061 $order_details_summary = WPPIZZA()->markup_maincart->summary_markup($order_formatted, $type); /* summary - uses markup/order/summary.php */
1062 }
1063
1064 /*************************************
1065
1066 cancelled payment
1067
1068 *************************************/
1069 if($is_cancelled){
1070
1071 /** in case there was an error or order does not exist **/
1072 $id = ''.WPPIZZA_PREFIX.'-order-cancelled';
1073 $class = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-wrap-cancelled';
1074
1075 /*
1076 [cancelled text]
1077 */
1078 $cancel_text = $txt['order_cancelled_p'];
1079 /*
1080 create return to shop link
1081 */
1082 $return_link = '<div class="'.WPPIZZA_PREFIX.'-back-to-shop"><a href="'.site_url().'">'.$txt['label_return_to_shop'].'</a></div>';
1083
1084 /*
1085 cancelled via ipn
1086 */
1087 $cancel_type = 'ipn';
1088
1089 /*
1090 ini array
1091 */
1092 $markup = array();
1093 /*
1094 get markup
1095 */
1096 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.cancelled.php')){
1097 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.cancelled.php');
1098 }else{
1099 require(WPPIZZA_PATH.'templates/markup/pages/page.cancelled.php');
1100 }
1101
1102 /*
1103 apply filter if required and implode for output
1104 */
1105 $markup = apply_filters('wppizza_filter_pages_cancelled_markup', $markup, $order_formatted, $cancel_type);
1106 $markup = implode('', $markup);
1107
1108
1109
1110
1111 return $markup;
1112 }
1113
1114 /*************************************
1115
1116 processing payment / INPROGRESS
1117
1118 *************************************/
1119 if($is_inprogress){
1120
1121 /** in case there was an error or order does not exist **/
1122 $id = ''.WPPIZZA_PREFIX.'-order-wrap-processing';
1123 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1124
1125 /*
1126 ini array
1127 */
1128 $markup = array();
1129 /*
1130 get markup
1131 */
1132 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.processing.php')){
1133 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.processing.php');
1134 }else{
1135 require(WPPIZZA_PATH.'templates/markup/pages/page.processing.php');
1136 }
1137 /** order info */
1138 $markup['order_info_']='<div class="'.$class_order_id.'">';
1139 $markup['order_info_date']='['.$order_formatted['ordervars']['order_date']['value_formatted'].']';
1140 $markup['order_info_id']='<br />'.$order_formatted['ordervars']['payment_gateway']['value_formatted'].' - ID:'.$order_formatted['ordervars']['order_id']['value_formatted'].'';
1141 $markup['order_info_txid']='<br />TXID: '.$order_formatted['ordervars']['transaction_id']['value_formatted'].'';
1142 $markup['order_info_status']=' - '.$order_formatted['ordervars']['payment_status']['value_formatted'].'';
1143 $markup['_order_info']='</div>';
1144 /** add processing js */
1145 $markup['refresh_page']='<script>setInterval(function(){console.log("awaiting payment processing...");window.location.reload(true); return;},3000);</script>';
1146
1147 /*
1148 apply filter if required and implode for output
1149 */
1150 $markup = apply_filters('wppizza_filter_pages_processing_markup', $markup, $order_formatted);
1151 $markup = implode('', $markup);
1152
1153
1154
1155
1156 return $markup;
1157 }
1158
1159 /*************************************
1160
1161 payment pending ....
1162
1163 *************************************/
1164 if($is_payment_pending){
1165 /** in case there was an error or order does not exist **/
1166 $id = ''.WPPIZZA_PREFIX.'-order-wrap-payment-pending';
1167 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1168
1169 /* add link back to order page including hash */
1170 $order_check_link = wppizza_orderpage_url(array(WPPIZZA_TRANSACTION_GET_PREFIX=>$order_formatted['ordervars']['hash']['value']));
1171 $txt['payment_pending_info'] = sprintf($txt['order_payment_pending_p'], $order_check_link, $order_check_link);// add it 2x in case someone wants to use it 2x
1172
1173 /*
1174 ini array
1175 */
1176 $markup = array();
1177
1178 /*
1179 get markup
1180 */
1181 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.payment-pending.php')){
1182 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.payment-pending.php');
1183 }else{
1184 require(WPPIZZA_PATH.'templates/markup/pages/page.payment-pending.php');
1185 }
1186
1187 /** add 15 seconds refresh js anyway, even though payments could take hours or even days to arrive for thos status....*/
1188 $markup['refresh_page']='<script>setInterval(function(){window.location = "'.$order_check_link.'";return;},15000);</script>';
1189
1190 /*
1191 apply filter if required and implode for output
1192 */
1193 $markup = apply_filters('wppizza_filter_payment_pending_markup', $markup, $order_formatted);
1194 $markup = implode('', $markup);
1195
1196
1197 return $markup;
1198
1199 }
1200 /*************************************
1201
1202 waiting for confirmation / UNCONFIRMED
1203
1204 *************************************/
1205 if($is_unconfirmed){
1206
1207 /** in case there was an error or order does not exist **/
1208 $id = ''.WPPIZZA_PREFIX.'-order-wrap-unconfirmed';
1209 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1210
1211 /*
1212 ini array
1213 */
1214 $markup = array();
1215 /*
1216 get markup
1217 */
1218 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.unconfirmed.php')){
1219 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.unconfirmed.php');
1220 }else{
1221 require(WPPIZZA_PATH.'templates/markup/pages/page.unconfirmed.php');
1222 }
1223 // /** order info */
1224 // $markup['order_info_']='<div class="'.$class_order_id.'">';
1225 // $markup['order_info_date']='['.$order_formatted['ordervars']['order_date']['value_formatted'].']';
1226 // $markup['order_info_id']='<br />'.$order_formatted['ordervars']['payment_gateway']['value_formatted'].' - ID:'.$order_formatted['ordervars']['order_id']['value_formatted'].'';
1227 // $markup['order_info_txid']='<br />TXID: '.$order_formatted['ordervars']['transaction_id']['value_formatted'].'';
1228 // $markup['order_info_status']=' - '.$order_formatted['ordervars']['payment_status']['value_formatted'].'';
1229 // $markup['_order_info']='</div>';
1230 // /** add processing js */
1231 // $markup['refresh_page']='<script>setInterval(function(){window.location.reload(true);},5000);</script>';
1232
1233 /*
1234 apply filter if required and implode for output
1235 */
1236 $markup = apply_filters('wppizza_filter_pages_unconfirmed_markup', $markup, $order_formatted);
1237 $markup = implode('', $markup);
1238
1239
1240 return $markup;
1241 }
1242
1243 /*************************************
1244
1245 order confirmed by user, waiting for confirmation (execution) by shop
1246
1247 *************************************/
1248 if($is_confirmed){
1249
1250 /** in case there was an error or order does not exist **/
1251 $id = ''.WPPIZZA_PREFIX.'-order-wrap-confirmed';
1252 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1253
1254 /** empty by default plugins should use the filter to write to this as to what will happen next */
1255 $empty_string = '';
1256 $txt['order_confirmed_info'] = apply_filters('wppizza_filter_page_confirmed_info', $empty_string , $order_formatted);
1257
1258 /*
1259 ini array
1260 */
1261 $markup = array();
1262
1263
1264 /*
1265 get markup
1266 */
1267 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.confirmed.php')){
1268 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.confirmed.php');
1269 }else{
1270 require(WPPIZZA_PATH.'templates/markup/pages/page.confirmed.php');
1271 }
1272
1273 /*
1274 apply filter if required and implode for output
1275 */
1276 $markup = apply_filters('wppizza_filter_pages_confirmed_markup', $markup, $order_formatted);
1277 $markup = implode('', $markup);
1278
1279
1280 return $markup;
1281 }
1282
1283 /*************************************
1284
1285 rejected
1286
1287 *************************************/
1288 if($is_rejected){
1289
1290 /** in case there was an error or order does not exist **/
1291 $id = ''.WPPIZZA_PREFIX.'-order-wrap-rejected';
1292 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1293
1294 /** empty by default - plugins should use the filter to write rejection reason to this */
1295 $empty_string = '';
1296 $txt['order_rejected_info'] = apply_filters('wppizza_filter_page_rejected_info', $empty_string , $order_formatted);
1297
1298 /*
1299 ini array
1300 */
1301 $markup = array();
1302 /*
1303 get markup
1304 */
1305 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.rejected.php')){
1306 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.rejected.php');
1307 }else{
1308 require(WPPIZZA_PATH.'templates/markup/pages/page.rejected.php');
1309 }
1310 /*
1311 apply filter if required and implode for output
1312 */
1313 $markup = apply_filters('wppizza_filter_pages_rejected_markup', $markup, $order_formatted);
1314 $markup = implode('', $markup);
1315
1316
1317 return $markup;
1318
1319 }
1320
1321 /*************************************
1322
1323 refunded
1324
1325 *************************************/
1326 if($is_refunded){
1327
1328 /** in case there was an error or order does not exist **/
1329 $id = ''.WPPIZZA_PREFIX.'-order-wrap-refunded';
1330 $class = ''.WPPIZZA_PREFIX.'-order-wrap';
1331
1332 /** empty by default - plugins should use the filter to write refunded reason to this */
1333 $empty_string = '';
1334 $txt['order_refunded_info'] = apply_filters('wppizza_filter_page_refunded_info', $empty_string , $order_formatted);
1335
1336 /*
1337 ini array
1338 */
1339 $markup = array();
1340 /*
1341 get markup
1342 */
1343 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.refunded.php')){
1344 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.refunded.php');
1345 }else{
1346 require(WPPIZZA_PATH.'templates/markup/pages/page.refunded.php');
1347 }
1348 /*
1349 apply filter if required and implode for output
1350 */
1351 $markup = apply_filters('wppizza_filter_pages_refunded_markup', $markup, $order_formatted);
1352 $markup = implode('', $markup);
1353
1354
1355 return $markup;
1356
1357 }
1358
1359 /*************************************
1360
1361 markup thank you / failed / unknown
1362
1363 *************************************/
1364 /*
1365 ini array
1366 */
1367 $markup = array();
1368 /*
1369 get markup
1370 */
1371 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.thankyou.php')){
1372 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.thankyou.php');
1373 }else{
1374 require(WPPIZZA_PATH.'templates/markup/pages/page.thankyou.php');
1375 }
1376 /*
1377 apply filter if required and implode for output
1378 */
1379 $markup = apply_filters('wppizza_filter_pages_thankyou_markup', $markup, $order_formatted);
1380 $markup = implode('', $markup);
1381
1382
1383 return $markup;
1384 }
1385 /***************************************
1386
1387 [order cancelled page]
1388
1389 ***************************************/
1390 function cancelled_page($type, $atts = null, $txt = array(), $user_session = array()){
1391
1392 /***************************************************************
1393 update db/order to CANCELLED by _GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]
1394 ****************************************************************/
1395 /*
1396 set db to cancel by hash. will silently not do anything and return false
1397 if hash does not match anything , $_GET will automatically be sanitized
1398 */
1399 $order_cancel = WPPIZZA()->db->cancel_order(false, false, $_GET[WPPIZZA_TRANSACTION_CANCEL_PREFIX]);
1400
1401
1402 /***************************************************************
1403 end db cancellation
1404 ****************************************************************/
1405
1406 /** in case there was an error or order does not exist **/
1407 $id = ''.WPPIZZA_PREFIX.'-order-cancelled';
1408 $class = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-wrap-cancelled';
1409
1410 /***************************************************************
1411 if that order does not exist, show error
1412 ****************************************************************/
1413 if($order_cancel){
1414 $cancel_text = $txt['order_cancelled_p'];
1415 }else{
1416 $cancel_text = $txt['order_not_found'];
1417 }
1418 /*
1419 create return to shop link
1420 */
1421 $return_link = '<div class="'.WPPIZZA_PREFIX.'-back-to-shop"><a href="'.site_url().'">'.$txt['label_return_to_shop'].'</a></div>';
1422
1423 /*
1424 for consistency use user_session as $order_formatted
1425 */
1426 $order_formatted = $user_session;
1427
1428 /*
1429 cancelled via direct link from gateway
1430 */
1431 $cancel_type = 'link';
1432 /*************************************
1433
1434 markup
1435
1436 *************************************/
1437
1438 /*
1439 ini array
1440 */
1441 $markup = array();
1442 /*
1443 get markup
1444 */
1445 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.cancelled.php')){
1446 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.cancelled.php');
1447 }else{
1448 require(WPPIZZA_PATH.'templates/markup/pages/page.cancelled.php');
1449 }
1450 /*
1451 apply filter if required and implode for output
1452 */
1453 $markup = apply_filters('wppizza_filter_pages_cancelled_markup', $markup, $order_formatted, $cancel_type);
1454 $markup = implode('', $markup);
1455
1456 return $markup;
1457 }
1458 /***************************************
1459
1460 [USERS order history page]
1461
1462 ***************************************/
1463 function orderhistory_page($type, $atts = null, $txt = array(), $user_session = array()){
1464
1465 /*
1466 ids'|classes
1467 */
1468 $id = ''.WPPIZZA_PREFIX.'-orders-wrap-'.$type.'';/* wrapper id */
1469 $class = ''.WPPIZZA_PREFIX.'-orders-wrap '.WPPIZZA_PREFIX.'-order-wrap-'.$type.'';/* wrapper class */
1470
1471 $id_noorders = ''.WPPIZZA_PREFIX.'-noorders-'.$type.'';
1472 $class_noorders = ''.WPPIZZA_PREFIX.'-noorders';
1473
1474 /*
1475 login form
1476 - only shown if not logged in and registration is enabled in the first place
1477 show registration disabled here if that is the case and user (typically admin) is not logged in
1478 */
1479 $login_form = WPPIZZA()->user->login_form(true);// uses markup/global/login.php
1480
1481
1482 /*
1483 we are not logged in
1484 */
1485 if(!is_user_logged_in()){
1486 $no_orders = false ;
1487 $is_logged_in = false ;
1488 $user_id = 0 ;
1489 $purchase_history = array();
1490 $pagination = '';
1491 $txt['history_no_previous_orders'] = '' ;/* just to make sure if someone takes the if($no_orders) out of the template */
1492 }
1493 /*
1494 we are logged in
1495 */
1496 if(is_user_logged_in()){
1497 $is_logged_in = true ;
1498 $user_id = get_current_user_id() ;
1499
1500 /*
1501 query args
1502 get (only) completed orders for this user
1503 */
1504 $args = array(
1505 'query'=>array(
1506 'wp_user_id' => $user_id ,
1507 'payment_status' => 'COMPLETED',
1508 'blogs' => (!empty($atts['multisite']) ? true : false ),//force multisite if set by atts
1509 ),
1510 'pagination' =>array(
1511 'paged' => (isset($_GET['pg']) ? (int)$_GET['pg'] : 0) ,
1512 'limit' => (( !empty($atts['maxpp']) && (int)$atts['maxpp']>0) ? (int)$atts['maxpp'] : 10 ) ,
1513 ),
1514 'format' => array(
1515 'blog_options' => true,
1516 ),
1517 );
1518 $orders_completed = WPPIZZA()->db->get_orders($args, $type);
1519
1520 /*
1521 no orders
1522 */
1523 if(empty($orders_completed['total_number_of_orders'])){
1524
1525 $no_orders = true;
1526 $purchase_history = array();
1527 $pagination = '';
1528
1529 }else{
1530
1531 /*
1532 classes, loop and pagination
1533 */
1534
1535 $no_orders = false;
1536 $purchase_history = array();
1537 $pagination = self::orderhistory_pagination($orders_completed['total_number_of_orders'], $args['pagination']['limit'], 2, true);
1538
1539 /* set classes */
1540 $class_order = ''.WPPIZZA_PREFIX.'-order-wrap '.WPPIZZA_PREFIX.'-order-'.$type.'';
1541 $class_fieldset = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-transaction-details-'.$type.'';
1542 $class_legend_span = ''.WPPIZZA_PREFIX.'-dashicon '.WPPIZZA_PREFIX.'-toggle-order-transaction-details dashicons dashicons-plus';
1543 $class_order_details = ''.WPPIZZA_PREFIX.'-order-details';
1544 $class_transaction_details = ''.WPPIZZA_PREFIX.'-transaction-details';
1545
1546 /* loop through orders */
1547 foreach($orders_completed['orders'] as $uoKey => $order_formatted){
1548
1549 /* set id */
1550 $purchase_history[$uoKey] = array();
1551
1552 $purchase_history[$uoKey]['id'] = ''.WPPIZZA_PREFIX.'-order-'.$type.'-'.$uoKey.'';
1553
1554 /* might come in useful in filters */
1555 $purchase_history[$uoKey]['blog_id'] = $order_formatted['site']['blog_id']['value_formatted'];
1556 $purchase_history[$uoKey]['order_id'] = $order_formatted['ordervars']['order_id']['value_formatted'];
1557 /* itemised */
1558 $purchase_history[$uoKey]['order_itemised'] = WPPIZZA()->markup_maincart->itemised_markup($order_formatted, $type);
1559 /* order_summary */
1560 $purchase_history[$uoKey]['order_summary'] = WPPIZZA()->markup_maincart->summary_markup($order_formatted, $type);
1561 /* transaction details */
1562 $purchase_history[$uoKey]['transaction_details'] = self::order_transaction_details($order_formatted['ordervars'], $type);
1563
1564 }
1565 }
1566 }
1567
1568 /*************************************
1569
1570 markup
1571
1572 *************************************/
1573 /*
1574 ini markup array
1575 */
1576 $markup = array();
1577
1578 /*
1579 get markup
1580 */
1581 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.purchase-history.php')){
1582 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.purchase-history.php');
1583 }else{
1584 require(WPPIZZA_PATH.'templates/markup/pages/page.purchase-history.php');
1585 }
1586 /*
1587 apply filter if required and implode for output
1588 */
1589 $markup = apply_filters('wppizza_filter_pages_purchasehistory_markup', $markup, $purchase_history, $user_id);
1590 $markup = implode('', $markup);
1591
1592
1593 return $markup;
1594 }
1595
1596 /***************************************
1597 #
1598 # [ADMIN admin_dashboard_widget_page, can be added somewhere by shortcode]
1599 # IT'S THE USERS RESPONSIBILITY TO SECURE THE PAGE IF ATT SET TO UNPROTECTED
1600 #
1601 # @since 3.8
1602 # @param string
1603 # @param array
1604 # @param array
1605 # @param array
1606 #
1607 # @return string
1608 ***************************************/
1609 function admin_dashboard_widget_page($type, $atts = null, $txt = array(), $user_session = array()){
1610 global $wppizza_options, $current_user;
1611
1612 /*
1613 ini markup
1614 */
1615 $markup = '';
1616
1617
1618 /************************
1619 #
1620 # attributes
1621 #
1622 ************************/
1623 /*
1624 if distinctly set, we can bypass wordpress login requirements
1625 which makes it the responsibility of the user to protect this page
1626 */
1627 $protected = empty($atts['unprotected']) ? true : false;
1628
1629 /*******************
1630 we are not logged in yet
1631 display login form (provided we are not bypassing protection altogether via attribute)
1632 *******************/
1633 if(!empty($protected) && !is_user_logged_in()){
1634
1635 /*
1636 filter to simplify form , omitting toggles, forgot password etc etc
1637 */
1638 add_filter('wppizza_filter_login_widget_markup', array($this, 'admin_orderhistory_login_markup'));
1639 /*
1640 login form markup
1641 */
1642 $markup = WPPIZZA() -> user -> login_form(false, true, true);// uses markup/global/login.php
1643
1644 /* set flag to disallow access to orders */
1645 $access_denied = true;
1646 }
1647
1648 /*******************
1649 we are logged in
1650 with protection enabled (default)
1651 but do not have the required capabilities
1652 *******************/
1653 if (!empty($protected) && is_user_logged_in() && empty($current_user->allcaps['wppizza_cap_orderhistory'])){
1654 $markup = __('Sorry, you are not allowed to access this page.', 'default' );
1655
1656 /* set flag to disallow access to orders */
1657 $access_denied = true;
1658 }
1659 /***************************************************
1660 we are logged in
1661 or bypassing protection altogether
1662
1663 => get widget
1664
1665 ***************************************************/
1666 if( ($protected === false || is_user_logged_in()) && empty($access_denied)){
1667
1668 /*************************************
1669
1670 markup
1671
1672 *************************************/
1673 /*
1674 ini markup array
1675 */
1676 $widget_markup = WPPIZZA() -> admin_dashboard_widgets -> wppizza_do_dashboard_widget_sales(true);
1677 /*
1678 wrap in same div ids as admin
1679 */
1680 $markup = '<div id="'.WPPIZZA_PREFIX.'_dashboard_widget" class="postbox"><div class="inside">'.$widget_markup.'</div></div>';
1681
1682
1683 /* enqueue dashicons */
1684 wp_enqueue_style( 'dashicons' );
1685
1686
1687 /* enqueue global admin scripts to make reload work */
1688 wp_register_script( WPPIZZA_SLUG.'-global', WPPIZZA_URL.'js/scripts.admin.global.js' , array('jquery'), WPPIZZA_VERSION, true);
1689 wp_enqueue_script( WPPIZZA_SLUG.'-global');
1690
1691 }
1692
1693
1694 return $markup;
1695 }
1696
1697 /***************************************
1698 #
1699 # [ADMIN order history page, can be added somewhere by shortcode]
1700 # IT'S THE USERS RESPONSIBILITY TO SECURE THE PAGE IF ATT SET TO UNPROTECTED
1701 #
1702 # @since 3.5
1703 # @param string
1704 # @param array
1705 # @param array
1706 # @param array
1707 #
1708 # @return string
1709 ***************************************/
1710 function admin_orderhistory_page($type, $atts = null, $txt = array(), $user_session = array()){
1711 global $wppizza_options, $current_user;
1712 static $shortcode_id = 0; $shortcode_id++;
1713 $get_blog_id = get_current_blog_id();
1714
1715 $constant = 'admin-orders';
1716
1717
1718 /************************
1719 #
1720 # attributes
1721 #
1722 ************************/
1723 /*
1724 if distinctly set, we can bypass wordpress login requirements
1725 which makes it the responsibility of the user to protect this page
1726 */
1727 $protected = empty($atts['unprotected']) ? true : false;
1728
1729 /*
1730 passing on post_id to pagination
1731 in/for ajax calls
1732 */
1733 $set_post_id = empty($atts['post_id']) ? false : (int)$atts['post_id'];
1734
1735 /*
1736 keys that make up the name
1737 */
1738 $name_keys = !empty($atts['name']) ? array_filter(explode(',',str_replace(' ','', $atts['name']))) : array('cname');
1739
1740 /*
1741 keys that make up the address
1742 */
1743 $address_keys = !empty($atts['address']) ? array_filter(explode(',',str_replace(' ','', $atts['address']))) : array('caddress');
1744
1745 /*
1746 omit pagination
1747 */
1748 $show_pagination = !empty($atts['no_pagination']) ? false : true;
1749
1750 /*
1751 print_view
1752 */
1753 $print_view = !empty($atts['print_view']) ? true : false;
1754
1755 /*
1756 order_delete
1757 */
1758 $delete_order = !empty($atts['delete_order']) && current_user_can('wppizza_cap_delete_order') ? true : false;
1759
1760 /************************
1761 #
1762 # set audio attributes if notifications
1763 # are enabled for order history
1764 #
1765 ************************/
1766 if(!empty($wppizza_options['settings']['new_orders_notify']) && !empty($wppizza_options['settings']['new_orders_audio_file']) && isset($wppizza_options['settings']['new_orders_notify_pages']['orderhistory']) ){
1767 $atts['audio_notify'] = $wppizza_options['settings']['new_orders_audio_file'];
1768 }
1769
1770 /************************
1771 #
1772 # ids'|classes
1773 #
1774 ************************/
1775
1776 /* no order id/classes */
1777 $id_noorders = ''.WPPIZZA_PREFIX.'-'.$constant.'-noorders-'.$shortcode_id.'';
1778 $class_noorders = ''.WPPIZZA_PREFIX.'-'.$constant.'-noorders';
1779
1780 /* order table thead/tfoot classes */
1781 $class_table = ''.WPPIZZA_PREFIX.'-'.$constant.'-table';
1782
1783 /* order table thead/tfoot classes */
1784 $class_th_dates = ''.WPPIZZA_PREFIX.'-th-dates';
1785 $class_th_customer = ''.WPPIZZA_PREFIX.'-th-customer';
1786 $class_th_order = ''.WPPIZZA_PREFIX.'-th-order';
1787 $class_th_status_type = ''.WPPIZZA_PREFIX.'-th-status-type';
1788 $class_th_actions = ''.WPPIZZA_PREFIX.'-th-actions';
1789
1790 /* order classes */
1791 $class_dates = ''.WPPIZZA_PREFIX.'-dates';
1792 $class_customer = ''.WPPIZZA_PREFIX.'-customer';
1793 $class_order = ''.WPPIZZA_PREFIX.'-order';
1794 $class_status_type = ''.WPPIZZA_PREFIX.'-status-type';
1795 $class_actions = ''.WPPIZZA_PREFIX.'-actions';
1796
1797
1798 /************************
1799 #
1800 # ini strings/parameters
1801 #
1802 ************************/
1803 $login_form = '';
1804 $pagination = '';
1805 $no_orders = '';
1806 $has_orders = false;
1807 $order_history = array();
1808
1809 /*******************
1810 we are not logged in yet
1811 display login form (provided we are not bypassing protection altogether via attribute)
1812 *******************/
1813 if(!empty($protected) && !is_user_logged_in()){
1814
1815 /*
1816 filter to simplify form , omitting toggles, forgot password etc etc
1817 */
1818 add_filter('wppizza_filter_login_widget_markup', array($this, 'admin_orderhistory_login_markup'));
1819 /*
1820 login form markup
1821 */
1822 $login_form = WPPIZZA() -> user -> login_form(false, true, true);// uses markup/global/login.php
1823
1824 /* set flag to disallow access to orders */
1825 $access_denied = true;
1826 }
1827
1828
1829 /*******************
1830 we are logged in
1831 with protection enabled (default)
1832 but do not have the required capabilities
1833 *******************/
1834 if (!empty($protected) && is_user_logged_in() && empty($current_user->allcaps['wppizza_cap_orderhistory'])){
1835 $login_form = __('Sorry, you are not allowed to access this page.', 'default' );
1836
1837 /* set flag to disallow access to orders */
1838 $access_denied = true;
1839 }
1840
1841 /***************************************************
1842 we are logged in
1843 or bypassing protection altogether
1844
1845 => get orders
1846
1847 ***************************************************/
1848 if( ($protected === false || is_user_logged_in()) && empty($access_denied)){
1849
1850 /*
1851 query args
1852 get completed orders only for all users
1853 omitting failed, cancelled etc
1854 */
1855 $args = array(
1856 'query'=>array(
1857 'payment_status' => 'COMPLETED',
1858 ),
1859 'pagination' =>array(
1860 'paged' => (isset($_GET['pg']) ? (int)$_GET['pg'] : 0) ,
1861 'limit' => (( !empty($atts['maxpp']) && (int)$atts['maxpp']>0) ? (int)$atts['maxpp'] : $wppizza_options['settings']['admin_order_history_max_results'] ) ,
1862 ),
1863 'format' => true,
1864 );
1865 $orders_completed = WPPIZZA()->db->get_orders($args, $type);
1866
1867 /*
1868 do we have any orders ?
1869 */
1870 $has_orders = empty($orders_completed['total_number_of_orders']) ? false : true;
1871
1872
1873 /*
1874 no orders
1875 */
1876 if(empty($has_orders)){
1877
1878 $no_orders = '<p id="' . $id_noorders . '" class="' . $class_noorders . '">'. __('no orders found','wppizza-admin') .'</p>';
1879
1880 }
1881
1882 if(!empty($has_orders)){
1883 /*
1884 got orders
1885 */
1886
1887 /*
1888 get pagination if not hidden by attribute
1889 */
1890 if($show_pagination){
1891 $pagination = self::orderhistory_pagination($orders_completed['total_number_of_orders'], $args['pagination']['limit'], 2, false, $set_post_id);
1892 }
1893
1894
1895 /***************************
1896 loop through orders
1897 ***************************/
1898
1899 foreach($orders_completed['orders'] as $uoKey => $order_formatted){
1900
1901 /***
1902 # multisite info blog name if parent and enabled
1903 # (added before total)
1904 ***/
1905 $blog_name = '';//.print_r($order_formatted, true);
1906 if(is_multisite() && !empty($order_formatted['site']['site_name']['value_formatted']) && $get_blog_id == 1 && !empty($wppizza_options['settings']['wp_multisite_order_history_all_sites'])){
1907 $blog_name= "<div class='".WPPIZZA_PREFIX."-blogname'>".$order_formatted['site']['site_name']['value_formatted']."</div> ";
1908 }
1909
1910
1911 /***
1912 # dates
1913 ***/
1914 $order_date = ($order_formatted['ordervars']['order_date']['value'] != '0000-00-00 00:00:00' ) ? date('d M, H:i' ,strtotime($order_formatted['ordervars']['order_date']['value'])) : '&nbsp;' ;
1915 $order_date = '<div class="'.WPPIZZA_PREFIX.'-'.$order_formatted['ordervars']['order_date']['class_ident'].'">'.$order_date.'</div>';
1916 $order_update = ($order_formatted['ordervars']['order_update']['value'] != '0000-00-00 00:00:00' ) ? date('d M, H:i' ,strtotime($order_formatted['ordervars']['order_update']['value'])) : '&nbsp;' ;
1917 $order_update = '<div class="'.WPPIZZA_PREFIX.'-'.$order_formatted['ordervars']['order_update']['class_ident'].'">'.$order_update.'</div>';
1918
1919 /***
1920 # name
1921 ***/
1922 $name = array();
1923 foreach($name_keys as $nkey){
1924 if(!empty($order_formatted['customer'][$nkey]['value'])){
1925 $name[] = '<span class="'.$nkey.'">'.$order_formatted['customer'][$nkey]['value'].'</span>';
1926 }
1927 }
1928 $name = !empty($name) ? '<div class="'.WPPIZZA_PREFIX.'-customer-name">'.implode(' ',$name).'</div>' : '';
1929
1930 /***
1931 # address
1932 ***/
1933 $address = array();
1934 $address_raw = array();
1935
1936 foreach($address_keys as $akey){
1937 if(!empty($order_formatted['customer'][$akey]['value'])){
1938 $address[] = '<span class="'.$akey.'">'.implode(', ',explode(PHP_EOL, $order_formatted['customer'][$akey]['value'])).'</span>';
1939 $address_raw[] = ''.implode(', ',explode(PHP_EOL, $order_formatted['customer'][$akey]['value'])).'';
1940 }
1941 }
1942 $address = !empty($address) ? implode(', ',$address) : '';
1943 $address_raw = !empty($address_raw) ? implode(', ',$address_raw) : '';
1944 $address_encode = urlencode(esc_html(wppizza_decode_entities($address_raw)));
1945 $address_search_url = apply_filters('wppizza_filter_admin_orderhistory_addresssearch_url', 'https://www.google.com/maps/search/'.$address_encode.'', $address_encode );
1946
1947
1948 $address = !empty($address) ? '<div class="'.WPPIZZA_PREFIX.'-customer-address"><a href="'.$address_search_url.'" target="_blank">'.$address.'</a></div>' : '';
1949
1950
1951 /***
1952 # total, payment
1953 ***/
1954 $total = '<div class="'.WPPIZZA_PREFIX.'-total"><span>'.$order_formatted['ordervars']['total']['value_formatted'].'</span></div>' ;
1955 $payment_type = '<div class="'.WPPIZZA_PREFIX.'-payment-type">'.$order_formatted['ordervars']['payment_type']['value_formatted'].'</div>' ;
1956
1957 /***
1958 # status, type
1959 ***/
1960 $excluded_status = apply_filters('wppizza_filter_pages_admin_orderhistory_status', array('REFUNDED', 'REJECTED', 'OTHER'));
1961 $order_status = WPPIZZA() -> admin_helper -> orderhistory_order_status_select($type, 'compact', $uoKey, $order_formatted['ordervars']['order_status']['value'], $excluded_status);
1962 $order_status = '<div class="'.WPPIZZA_PREFIX.'-order-status">'.$order_status.'</div>';
1963 //type
1964 $order_type ='<div class="'.WPPIZZA_PREFIX.'-order-type">'.$order_formatted['ordervars']['order_type']['value_formatted'].'</div>';
1965
1966 /***
1967 # order view (print)
1968 ***/
1969 $print_class = empty($print_view) ? 'view' : 'print'; //determines if js launches print screen or just view order
1970 $order_view ='<span id="'.WPPIZZA_PREFIX.'-order-print-'.$uoKey.'" class="'.WPPIZZA_PREFIX.'-order-'.$print_class.' '.WPPIZZA_PREFIX.'-dashicon dashicons dashicons-media-document" title="'.__('view / print order', 'wppizza-admin').'"></span>';
1971
1972 /***
1973 # order delete (if attribute set)
1974 ***/
1975 /* Translators: 1: WPPizza Order ID to be deleted */
1976 $order_delete = empty($delete_order) ? '' : '<span id="'.WPPIZZA_PREFIX.'-order-delete-'.$uoKey.'" class="'.WPPIZZA_PREFIX.'-order-delete '.WPPIZZA_PREFIX.'-dashicon dashicons dashicons-trash" title="'.sprintf(__('delete order #%s', 'wppizza-admin'), $order_formatted['ordervars']['order_id']['value']).'"></span>';
1977
1978 /*************************************************
1979 *
1980 * set columns to use in template
1981 *
1982 *************************************************/
1983 $order_history[$uoKey] = array();
1984
1985 $order_history[$uoKey]['uoKey'] = ''.WPPIZZA_PREFIX.'-order-'.$uoKey.'';
1986
1987 $order_history[$uoKey]['class'] = ''.WPPIZZA_PREFIX.'-status-'.$order_formatted['ordervars']['order_status']['value'].'';
1988
1989 $order_history[$uoKey]['blog_name'] = ''.$blog_name.'';
1990
1991 $order_history[$uoKey]['order_date'] = ''.$order_date.'';
1992
1993 $order_history[$uoKey]['order_update'] = ''.$order_update.'';
1994
1995 $order_history[$uoKey]['name'] = ''.$name.'';
1996
1997 $order_history[$uoKey]['address'] = ''.$address.'';
1998
1999 $order_history[$uoKey]['total'] = ''.$total.'';
2000
2001 $order_history[$uoKey]['payment_type'] = ''.$payment_type.'';
2002
2003 $order_history[$uoKey]['order_status'] = ''.$order_status.'';
2004
2005 $order_history[$uoKey]['order_type'] = ''.$order_type.'';
2006
2007 $order_history[$uoKey]['order_view'] = ''.$order_view.'';
2008
2009 $order_history[$uoKey]['order_delete'] = ''.$order_delete.'';
2010
2011 $order_history[$uoKey]['order_formatted'] = $order_formatted;
2012
2013 }
2014
2015 }
2016
2017 /*
2018 if we are showing orders, we need to also pass the shortcode attributes to the js when polling
2019 */
2020 $shortcode_attributes = "<input type='hidden' class='".WPPIZZA_PREFIX."-".$constant."-attributes' value='".esc_html(json_encode($atts))."' />";
2021 }
2022
2023 /*************************************
2024
2025 markup
2026
2027 *************************************/
2028 /*
2029 ini markup array
2030 */
2031 $markup = array();
2032
2033 /*
2034 get markup
2035 */
2036 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/pages/page.admin-order-history.php')){
2037 require(WPPIZZA_TEMPLATE_DIR.'/markup/pages/page.admin-order-history.php');
2038 }else{
2039 require(WPPIZZA_PATH.'templates/markup/pages/page.admin-order-history.php');
2040 }
2041 /*
2042 apply filter if required and implode for output
2043 */
2044 $markup = apply_filters('wppizza_filter_pages_shortcode_orderhistory_markup', $markup, $has_orders, $order_history);
2045 //alwasy add nonce
2046 $markup['_ajax_nonce'] = wp_nonce_field( '' . WPPIZZA_PREFIX . '_ajax_nonce','' . WPPIZZA_PREFIX . '_ajax_nonce', true, false);
2047
2048 $markup = implode('', $markup);
2049 /*
2050 add attributes if logged in or not protected in the first place
2051 */
2052 $markup .= !empty($shortcode_attributes) ? $shortcode_attributes : '' ;
2053
2054 /*
2055 add a non-removable wrapper to ajax into so to speak on load
2056 and include relevant js
2057 */
2058 if(!defined('DOING_AJAX') || !DOING_AJAX){
2059 /*
2060 current_post_id passed on to ajax request (must be last part of element id) to create the right pagination links to this page
2061 skip surrounding div to disable polling if we need to be logged in first
2062 */
2063 $current_post_id = get_the_ID();
2064 $markup = empty($access_denied) ? '<div id="'.WPPIZZA_PREFIX.'-'.$constant.'-'.$shortcode_id.'-'.$current_post_id.'" class="'.WPPIZZA_PREFIX.'-'.$constant.'">'.$markup.'</div>' : $markup ;
2065 /*
2066 enqueue js to poll orders, change status, view/print order etc etc
2067 */
2068 $js_filename='scripts.orderhistory.min.js';
2069 $js_enqueue_ident=''.WPPIZZA_SLUG.'-orderhistory';
2070 wp_register_script($js_enqueue_ident, WPPIZZA_URL.'js/'.$js_filename , array('jquery'), WPPIZZA_VERSION, true);
2071 wp_enqueue_script($js_enqueue_ident);
2072
2073 }
2074
2075
2076 return $markup;
2077 }
2078
2079
2080 /******************************************************************************************************************************
2081 #
2082 #
2083 #
2084 # [helpers]
2085 #
2086 #
2087 #
2088 ******************************************************************************************************************************/
2089 function orderhistory_pagination($no_of_orders, $maxpp, $ellipsis = false, $pagination_info = true, $post_id = false){
2090 global $wppizza_options;
2091
2092 /* skip if fewer orders than maxpp */
2093 if($no_of_orders<=$maxpp){
2094 $markup = '';
2095 return $markup ;
2096 }
2097
2098 $total_pages=ceil($no_of_orders/$maxpp);
2099 $currentPageLink = empty($post_id) ? get_permalink() : get_permalink($post_id);//allow ajax calls for example to pass on page links
2100 $current_page = !isset($_GET['pg']) || empty((int)$_GET['pg']) ? 1 : (int)$_GET['pg'];
2101 $current_orders_from = ($current_page==1) ? $current_page : ( ($current_page==$total_pages) ? (($current_page-1)*$maxpp+1) : (($current_page-1)*$maxpp+1) );
2102 $current_orders_to = ($current_page==1) ? $maxpp : ( ($current_page==$total_pages) ? $no_of_orders : ($current_page*$maxpp) );
2103
2104
2105 $markup = array();
2106
2107 $markup['div_'] = '<div class="'.WPPIZZA_PREFIX.'-history-pagination">';
2108 /*
2109 previous link
2110 */
2111 if($current_page>1){
2112 $link= esc_url_raw(add_query_arg(array('pg' => ($current_page-1)), $currentPageLink ));
2113 $markup['previous'] = '<a href="'.$link.'" class="'.WPPIZZA_PREFIX.'-history-pagination-previous">'.__('&laquo; Previous Page', 'default' ).'</a>';
2114 }else{
2115 $markup['previous_disabled'] = '<a class="'.WPPIZZA_PREFIX.'-history-pagination-previous '.WPPIZZA_PREFIX.'-history-pagination-disabled" disabled="disabled">'.__('&laquo; Previous Page', 'default' ).'</a>';
2116 }
2117
2118 /*
2119 page links - limited
2120 */
2121 if((int)$ellipsis > 0 ){
2122 for($i=1;$i<=$total_pages;$i++){
2123
2124 /* links/buttons */
2125 if($i <= $ellipsis || $i > $total_pages - $ellipsis || $i==$current_page || ($i>=($current_page-$ellipsis) && $i < $current_page) || ($i<=($current_page+$ellipsis) && $i > $current_page) ){
2126
2127 if($current_page==$i){
2128 $markup[$i]= '<a href="javascript:void(0)" class="'.WPPIZZA_PREFIX.'-history-pagination-selected">'.$i.'</a>';
2129 }else{
2130 $link= esc_url_raw(add_query_arg(array('pg' => $i), $currentPageLink ));
2131 $markup[$i]= '<a href="'.$link.'" class="'.WPPIZZA_PREFIX.'-history-pagination-count">'.$i.'</a>';
2132 }
2133
2134 }else{
2135 /* dots */
2136 if($i == ($ellipsis+1) || $i == ($total_pages - $ellipsis - 1) ){
2137 $markup[$i]= '...';
2138 }
2139
2140 }
2141 }
2142 }
2143
2144
2145 /*
2146 page links - unlimited
2147 */
2148 if(empty($ellipsis)){
2149 for($i=1;$i<=$total_pages;$i++){
2150 if($current_page==$i){
2151 $markup[$i]= '<a href="javascript:void(0)" class="'.WPPIZZA_PREFIX.'-history-pagination-selected">'.$i.'</a>';
2152 }else{
2153 $link= esc_url_raw(add_query_arg(array('pg' => $i), $currentPageLink ));
2154 $markup[$i]= '<a href="'.$link.'" class="'.WPPIZZA_PREFIX.'-history-pagination-count">'.$i.'</a>';
2155 }
2156 }
2157 }
2158
2159 /*
2160 next link
2161 */
2162 if($current_page<$total_pages){
2163 $link= esc_url_raw(add_query_arg(array('pg' => ($current_page+1)), $currentPageLink ));
2164 $markup['next']= '<a href="'.$link.'" class="'.WPPIZZA_PREFIX.'-history-pagination-next">'.__('Next Page &raquo;', 'default' ).'</a>';
2165 }else{
2166 $markup['next_disabled']= '<a class="'.WPPIZZA_PREFIX.'-history-pagination-next '.WPPIZZA_PREFIX.'-history-pagination-disabled" disabled="disabled">'.__('Next Page &raquo;', 'default' ).'</a>';
2167 }
2168
2169 /*
2170 pagination info (no of orders on page) if more than one page
2171 */
2172 if($total_pages>1 && !empty($pagination_info)){
2173 $markup['info_'] = '<p class="'.WPPIZZA_PREFIX.'-history-pagination-info">';
2174 $markup['info'] = sprintf($wppizza_options['localization']['pagination_info'],$current_orders_from, $current_orders_to, $no_of_orders);// $on_page . ' / ' . $no_of_orders;
2175 $markup['_info'] = '</p>';
2176 }
2177
2178
2179 $markup['_div'] = '</div>';
2180
2181
2182
2183 /*
2184 apply filter if required and implode for output
2185 */
2186 $markup = apply_filters('wppizza_filter_pagination_purchasehistory_markup', $markup);
2187 $markup = implode('', $markup);
2188
2189 return $markup;
2190 }
2191
2192
2193 /*************************************
2194
2195 global_details. order date, order id, transation id etc etc
2196
2197 *************************************/
2198 function order_transaction_details($order, $type){
2199
2200 /*
2201 get selected (filterable) parameters
2202 available keys:
2203 [wp_user_id] [order_update] [order_delivered] [notes] [payment_gateway] [payment_status] [user_data]
2204 [ip_address] [order_date] [order_id] [payment_due] [pickup_delivery] [payment_type] [payment_method]
2205 [transaction_id] [total]
2206 */
2207 $tx_details_keys = array('order_date','payment_type','transaction_id','order_delivered');
2208 $tx_details_keys = array_combine($tx_details_keys, $tx_details_keys);//combine key/vals
2209 $tx_details_keys = apply_filters('wppizza_filter_transaction_details', $tx_details_keys, $type, $order);
2210
2211 /*
2212 omitting empty ones (like order_update) that do not exist yet
2213 restricted to set keys
2214 */
2215 $transaction_details = array();
2216 foreach($order as $key=>$parameter){
2217 if(!empty($parameter['value_formatted']) && in_array($key, $tx_details_keys) ){
2218 $transaction_details[$key] = array();
2219 $transaction_details[$key]['class'] = ''.WPPIZZA_PREFIX.'-'.$parameter['class_ident'].'';
2220 $transaction_details[$key]['label'] = '<label>'.$parameter['label'].'</label>';
2221 $transaction_details[$key]['value'] = '<span>'.$parameter['value_formatted'].'</span>';
2222 }
2223 }
2224
2225 /*************************************
2226
2227 markup
2228
2229 *************************************/
2230 /*
2231 ini array
2232 */
2233 $markup = array();
2234 /*
2235 get markup
2236 */
2237 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/order/transaction_details.php')){
2238 require(WPPIZZA_TEMPLATE_DIR.'/markup/order/transaction_details.php');
2239 }else{
2240 require(WPPIZZA_PATH.'templates/markup/order/transaction_details.php');
2241 }
2242
2243 /*
2244 apply filter if required (return $markup array will be imploded for output)
2245 */
2246 $markup = apply_filters('wppizza_filter_order_transactiondetails_markup', $markup, $transaction_details, $type);
2247
2248 $markup = implode('', $markup);
2249
2250 return $markup;
2251 }
2252
2253 /*************************************
2254
2255 pickup_note
2256
2257 *************************************/
2258 function pickup_note_markup($order_formatted, $type){
2259 $vals = $order_formatted['ordervars']['pickup_delivery'];
2260
2261 /* nothing set */
2262 if(empty($vals['value_formatted'])){return '';}
2263
2264 $class = ''.WPPIZZA_PREFIX.'-'.$vals['class_ident'].'';
2265 $pickup_delivery_message = $vals['value_formatted'];
2266
2267 /*************************************
2268
2269 markup
2270
2271 *************************************/
2272 /*
2273 ini array
2274 */
2275 $markup = array();
2276 /*
2277 get markup
2278 */
2279 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/global/pages.pickup_note.php')){
2280 require(WPPIZZA_TEMPLATE_DIR.'/markup/global/pages.pickup_note.php');
2281 }else{
2282 require(WPPIZZA_PATH.'templates/markup/global/pages.pickup_note.php');
2283 }
2284 /*
2285 apply filter if required and implode for output
2286 */
2287 $markup = apply_filters('wppizza_filter_pages_pickup_note_markup', $markup);
2288 $markup = implode('', $markup);
2289
2290
2291 return $markup;
2292 }
2293
2294 /*************************************
2295
2296 inline payment details markup
2297 if wppizza_gateways_inline_elements_{gateway ident} filter was added
2298 by a gateways
2299 @param str
2300 @retun str
2301 @since 3.6.1
2302 *************************************/
2303 function payment_details_markup($type = 'confirmationpage', $order_formatted = array()){
2304
2305 $selected_gateway_ident = strtolower( wppizza_selected_gateway() );
2306
2307 $markup = '';
2308
2309 if(has_filter('wppizza_gateways_inline_elements_'.$selected_gateway_ident)){
2310 /*
2311 order page or confirmation page conditionals
2312 */
2313 global $wppizza_options;
2314 if( ( $type == 'orderpage' && empty($wppizza_options['confirmation_form']['confirmation_form_enabled'])) || $type == 'confirmationpage' ){
2315
2316 $payment_details_fieldset_id = ''.WPPIZZA_PREFIX.'-payment-details';
2317 $payment_details_fieldset_class = ''.WPPIZZA_PREFIX.'-fieldset '.WPPIZZA_PREFIX.'-payment-details';
2318 $payment_details_ssl_lock = is_ssl() ? '<span class="'.WPPIZZA_PREFIX.'-dashicon dashicons dashicons-lock"></span>' : '' ;
2319 $payment_details = implode('', apply_filters('wppizza_gateways_inline_elements_'.$selected_gateway_ident, array(), $order_formatted, $selected_gateway_ident ));
2320
2321
2322 /*
2323 ini array
2324 */
2325 $markup = array();
2326
2327 /*
2328 get markup
2329 */
2330 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/order/payment_details.php')){
2331 require(WPPIZZA_TEMPLATE_DIR.'/markup/order/payment_details.php');
2332 }else{
2333 require(WPPIZZA_PATH.'templates/markup/order/payment_details.php');
2334 }
2335
2336 /*
2337 apply filter if required and implode for output
2338 */
2339 $markup = apply_filters('wppizza_filter_order_payment_details_markup', $markup, $selected_gateway_ident, $order_formatted );
2340 $markup = implode('', $markup);
2341
2342 }
2343 }
2344
2345 return $markup;
2346 }
2347
2348
2349
2350
2351 /*************************************
2352
2353 user login filter, removing
2354 various elements of the login screen
2355 if we are displaying admin order history
2356 by shortcode somewhere
2357 *************************************/
2358 function admin_orderhistory_login_markup($markup){
2359 /*
2360 only return basic login markup
2361 without the fancy stuff
2362 */
2363 $base_login = array();
2364 $base_login['login'] = $markup['login'];
2365
2366 return $base_login;
2367 }
2368 }
2369 ?>