private function getOrderDetails($orderFields, $oDetails, $pOptions, $currency, $nolabel = false)
 {
     /**********************************
     				exclude some labels in front of output
     			**********************************/
     if (!$nolabel || !is_array($nolabel)) {
         $nolabel['order_date'] = true;
         //i think we should omit label for order date as it's obvious
     }
     /***********************
     				format some variables
     			***********************/
     /**mk timestamp*/
     $oDateTimeStamp = strtotime($orderFields->order_date);
     $uDateTimeStamp = strtotime($orderFields->order_update);
     /***********************
     				format dates
     			***********************/
     $order_date = "" . date_i18n(get_option('date_format'), $oDateTimeStamp) . " " . date_i18n(get_option('time_format'), $oDateTimeStamp) . "";
     //format by set wordpress date/time
     $order_update = "" . date_i18n(get_option('date_format'), $uDateTimeStamp) . " " . date_i18n(get_option('time_format'), $uDateTimeStamp) . "";
     //format by set wordpress date/time
     /***********************
     				add gateway name/label as payment_type to single order vars
     			***********************/
     $gateways = new WPPIZZA_GATEWAYS();
     $gateways->wppizza_instanciate_gateways_frontend();
     $gateways->wppizza_wpml_localization_gateways();
     $gwIni = strtoupper($orderFields->initiator);
     /*payment method*/
     $gw_payment_method = 'CC';
     /*ini as cc payment*/
     if ($gwIni == 'COD') {
         /*COD is always cash*/
         $gw_payment_method = 'CASH';
     }
     /**ini just using the simple initiator value*/
     $payment_type = $orderFields->initiator;
     /**use full label if exists*/
     if (isset($gateways->pluginGateways[$gwIni])) {
         $payment_type = !empty($gateways->pluginGateways[$gwIni]->gatewayOptions['gateway_label']) ? $gateways->pluginGateways[$gwIni]->gatewayOptions['gateway_label'] : $orderFields->initiator;
         /*in case a customised non CC gateway was added, set back to Cash*/
         if (!empty($gateways->pluginGateways[$gwIni]->gatewayTypeSubmit) && $gateways->pluginGateways[$gwIni]->gatewayTypeSubmit == 'ajax') {
             $gw_payment_method = 'CASH';
         }
     }
     /**get string for paymnt method used*/
     $payment_method = $pOptions['localization']['common_value_order_credit_card']['lbl'];
     if ($gw_payment_method == 'CASH') {
         $payment_method = $pOptions['localization']['common_value_order_cash']['lbl'];
     }
     /***********************
     				payment due (if credit card->0)
     			***********************/
     $payment_due = $currency['left'] . wppizza_output_format_price(0, $pOptions['layout']['hide_decimals']) . $currency['right'];
     if ($gw_payment_method == 'CASH') {
         $payment_due = $currency['left'] . wppizza_output_format_price($oDetails['total'], $pOptions['layout']['hide_decimals']) . $currency['right'];
     }
     /***********************
     				pickup or delivery
     			***********************/
     $pickup_delivery = $pOptions['localization']['common_value_order_delivery']['lbl'];
     if (isset($oDetails['selfPickup']) && $oDetails['selfPickup'] >= 1) {
         $pickup_delivery = $pOptions['localization']['common_value_order_pickup']['lbl'];
     }
     /***********************
     				return array
     			***********************/
     $orderDetails = array();
     /*ini*/
     /*wp user id - currently unused*/
     $orderDetails['wp_user_id'] = array('label' => !empty($nolabel['wp_user_id']) ? '' : $pOptions['localization']['common_label_order_wp_user_id']['lbl'], 'value' => $orderFields->wp_user_id);
     /**order id*/
     $orderDetails['id'] = array('label' => !empty($nolabel['id']) ? '' : $pOptions['localization']['common_label_order_order_id']['lbl'], 'value' => $orderFields->id);
     $orderDetails['order_id'] = array('label' => !empty($nolabel['order_id']) ? '' : $pOptions['localization']['common_label_order_order_id']['lbl'], 'value' => $orderFields->id);
     /**transaction_id*/
     $orderFields->transaction_id = apply_filters('wppizza_filter_order_details_transaction_id', $orderFields->transaction_id, $orderFields->id);
     $orderDetails['transaction_id'] = array('label' => !empty($nolabel['transaction_id']) ? '' : $pOptions['localization']['common_label_order_transaction_id']['lbl'], 'value' => $orderFields->transaction_id);
     /**order_date*/
     $orderDetails['order_date'] = array('label' => !empty($nolabel['order_date']) ? '' : $pOptions['localization']['common_label_order_order_date']['lbl'], 'value' => $order_date);
     /**payment_type*/
     $orderDetails['payment_type'] = array('label' => !empty($nolabel['payment_type']) ? '' : $pOptions['localization']['common_label_order_payment_type']['lbl'], 'value' => $payment_type);
     /**payment_status*/
     $orderDetails['payment_method'] = array('label' => !empty($nolabel['payment_method']) ? '' : $pOptions['localization']['common_label_order_payment_method']['lbl'], 'value' => $payment_method);
     /**payment_due*/
     $orderDetails['payment_due'] = array('label' => !empty($nolabel['payment_due']) ? '' : $pOptions['localization']['common_label_order_payment_outstanding']['lbl'], 'value' => $payment_due);
     /**currency - in use but without label*/
     $orderDetails['currency'] = array('label' => !empty($nolabel['currency']) ? '' : $pOptions['localization']['common_label_order_currency']['lbl'], 'value' => $currency['currency']);
     $orderDetails['currencyiso'] = array('label' => !empty($nolabel['currencyiso']) ? '' : $pOptions['localization']['common_label_order_currency']['lbl'], 'value' => $currency['currencyiso']);
     /**pickup/delivery**/
     $orderDetails['pickup_delivery'] = array('label' => !empty($nolabel['pickup_delivery']) ? '' : $pOptions['localization']['common_label_order_delivery_type']['lbl'], 'value' => $pickup_delivery);
     /*total add here too, might be useful*/
     $orderDetails['total'] = array('label' => !empty($nolabel['total']) ? '' : $pOptions['localization']['order_total']['lbl'], 'value' => $currency['left'] . wppizza_output_format_price($oDetails['total'], $pOptions['layout']['hide_decimals']) . $currency['right']);
     /*
     	currently unused variables without labels defined yet in localization
     	might come in useful somewhere one day
     */
     //notes
     $orderDetails['notes'] = array('label' => '', 'value' => $orderFields->notes);
     //payment_status
     $orderDetails['payment_status'] = array('label' => '', 'value' => $orderFields->payment_status);
     //order_update
     $orderDetails['order_update'] = array('label' => '', 'value' => $order_update);
     //initiator
     $orderDetails['initiator'] = array('label' => '', 'value' => $orderFields->initiator);
     return $orderDetails;
 }
 public function wppizza_include_shortcode_template($type, $atts = null)
 {
     /***************************************
     			[include category loop template]
     		***************************************/
     if ($type == 'category') {
         $options = $this->pluginOptions;
         $querys = array();
         /*********************************************************************
         				[as we have changed in v.2.8.7.4 to have the additives as array
         				so we can custom sort them but dont really want to screw up
         				anyones edited templates, re-map key and name]
         			*******************************************************************/
         $mapAdditives = array();
         if (isset($options['additives']) && is_array($options['additives'])) {
             foreach ($options['additives'] as $o => $a) {
                 if (is_array($a)) {
                     if ($a['sort'] == '') {
                         $a['sort'] = $o;
                     }
                     $mapAdditives[$a['sort']] = $a['name'];
                 } else {
                     /**in case we have not yet re-saved the additives**/
                     $mapAdditives[$o] = $a;
                 }
             }
         }
         //ksort($mapAdditives,SORT_NATURAL);//php 5.4 only
         uksort($mapAdditives, 'strnatcmp');
         $options['additives'] = $mapAdditives;
         /*******re-map additives inside loop too **************************/
         add_filter('wppizza_filter_loop_meta', array($this, 'wppizza_additives_remap'), 10, 1);
         /*******************************************************************
          *
          *	[end of additives re-mapping
          *
          ********************************************************************/
         /**********************************************************************************
          *
          *	[top 10 (or whatever) -> bestsellers ]
          *
          **********************************************************************************/
         if (isset($atts['bestsellers'])) {
             global $wpdb;
             /**wppizza posts to compare against, making sure posts still exists**/
             $wppPostsQuery = "SELECT ID FROM " . $wpdb->prefix . "posts where post_type='wppizza' AND post_status='publish' ";
             $wppPostsRes = $wpdb->get_results($wppPostsQuery, OBJECT_K);
             /**run the query**/
             $bestsellersQuery = "SELECT id,order_ini FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE payment_status='COMPLETED' ";
             $bestsellersRes = $wpdb->get_results($bestsellersQuery);
             $bestsellers = array();
             /**loop through items and get quantities**/
             foreach ($bestsellersRes as $b => $bs) {
                 $thisOrderDetails = maybe_unserialize($bs->order_ini);
                 if (isset($thisOrderDetails['item']) && is_array($thisOrderDetails['item'])) {
                     foreach ($thisOrderDetails['item'] as $item) {
                         /**make sure this post still exists and has been sold more than 0 times**/
                         if (isset($wppPostsRes[$item['postId']]) && $item['quantity'] > 0) {
                             if (!isset($bestsellers[$item['postId']])) {
                                 $bestsellers[$item['postId']] = $item['quantity'];
                             } else {
                                 $bestsellers[$item['postId']] += $item['quantity'];
                             }
                         }
                     }
                 }
             }
             /*sort by quantity*/
             arsort($bestsellers);
             /*chunk to required bits*/
             $chunks = (int) $atts['bestsellers'];
             $bestsellers = array_chunk($bestsellers, $chunks, true);
             if (count($bestsellers) > 0) {
                 /**required bestsellers**/
                 $bestsellersIncl = implode(',', array_keys($bestsellers[0]));
             } else {
                 $bestsellersIncl = '';
             }
             /**get/set  id's **/
             $inclAtts = array();
             if ($bestsellersIncl != '') {
                 $inclAtts[] = $bestsellersIncl;
             }
             /**add distinctly set includes (if any)**/
             if (isset($atts['include'])) {
                 $inclAtts[] = $atts['include'];
             }
             /**finally set the includes id's**/
             $atts['include'] = implode(',', $inclAtts);
             /***add a filter that can be used if required for alternative sorting for example*****/
             $atts['include'] = apply_filters('wppizza_filter_bestsellers_include', $atts['include']);
             //alternatives if empty*/
             if ((!isset($atts['include']) || $atts['include'] == '') && isset($atts['ifempty'])) {
                 $atts['include'] = $atts['ifempty'];
             }
             /*distincly unset any category and header**/
             unset($atts['category']);
             /*unset all categories as query_vars below will hold an array of all the categories**/
             $atts['noheader'] = 1;
             /**omit header**/
             /*get and set all terms in the taxonomy and convert to array of all slugs for tax query */
             $terms = get_terms($this->pluginSlugCategoryTaxonomy);
             $query_var = wp_list_pluck($terms, 'slug');
             /** filter arguments -> sort output according to populariry (i.e how many tims an item has been bought)**/
             add_filter('wppizza_filter_loop', array($this, 'wppizza_filter_shortcode_post_in_args'), 10, 1);
             /**********************************************************
             				as bestsellers are not tied to a particular category
             				set some static variables so we can use it in the
             				loop templates
             			**********************************************************/
             $querys['bestsellers'] = new stdClass();
             $querys['bestsellers']->term_id = array_keys($query_var);
             $querys['bestsellers']->name = 'bestsellers';
             //should be a slug. no spaces etc
             $querys['bestsellers']->slug = $query_var;
             $querys['bestsellers']->category_id = 0;
             //unknown / not applicable
         }
         /**********************************************************************************
          *
          *	[single item]
          *
          **********************************************************************************/
         if (isset($atts['single'])) {
             $atts['include'] = (int) $atts['single'];
             unset($atts['category']);
             /*unset all categories as query_vars below will hold an array of all the categories**/
             $atts['noheader'] = 1;
             /**omit header**/
             /*get and set all terms in the taxonomy and convert to array of all slugs for tax query */
             $termDetails = wp_get_post_terms($atts['include'], WPPIZZA_TAXONOMY);
             if ($termDetails && !is_wp_error($termDetails)) {
                 $query_var = wp_list_pluck($termDetails, 'slug', 'term_id');
             } else {
                 /*cat find any, get all*/
                 $terms = get_terms($this->pluginSlugCategoryTaxonomy);
                 $query_var = wp_list_pluck($terms, 'slug');
             }
             /*indexed array of term to be able to set some sort of category id*/
             $termKeys = array_keys($query_var);
             /** filter arguments -> sort output according to populariry (i.e how many tims an item has been bought)**/
             add_filter('wppizza_filter_loop', array($this, 'wppizza_filter_shortcode_post_in_args'), 10, 1);
             /**********************************************************
             				as single items are not tied to a particular category
             				(they can be in several)
             				set some static variables so we can use it in the
             				loop templates
             			**********************************************************/
             $querys['single'] = new stdClass();
             $querys['single']->term_id = $termKeys;
             $querys['single']->name = 'single';
             //should be a slug. no spaces etc
             $querys['single']->slug = $query_var[$termKeys[0]];
             //get first slug
             $querys['single']->category_id = $termKeys[0];
             //just use the first we have
         }
         /**********************************************************************************
          *
          *	[select first category if none selected->used when using shortcode without category,
          *	unless we are looking for bestsellers]
          *
          **********************************************************************************/
         if (!isset($atts['category']) && !isset($atts['bestsellers']) && !isset($atts['single'])) {
             $termSort = $options['layout']['category_sort'];
             asort($termSort);
             reset($termSort);
             $firstTermId = key($termSort);
             /*get slug and taxonomy from id*/
             $querys[] = get_term_by('id', $firstTermId, $this->pluginSlugCategoryTaxonomy);
         }
         /**********************************************************************************
          *
          *	[category(ies) has/have been selected]
          *
          **********************************************************************************/
         if (isset($atts['category'])) {
             $catSlugsToArray = explode(',', $atts['category']);
             if (in_array('!all', $catSlugsToArray)) {
                 /**check if we are excluding some categories**/
                 $excludeCategory = array();
                 foreach ($catSlugsToArray as $sKey => $slug) {
                     if (substr($slug, 0, 1) == '-') {
                         $thisCategory = get_term_by('slug', $slug, $this->pluginSlugCategoryTaxonomy);
                         $excludeCategory[$thisCategory->term_id] = $thisCategory->term_id;
                     }
                 }
                 /**get all sorted ones*/
                 $termSort = $options['layout']['category_sort'];
                 asort($termSort);
                 foreach ($termSort as $termId => $sorter) {
                     if (!isset($excludeCategory[$termId])) {
                         //exclude if necessary
                         $querys[] = get_term_by('id', $termId, $this->pluginSlugCategoryTaxonomy);
                     }
                 }
                 /*********
                 						filter any empty ones if more cats in $options['layout']['category_sort'] for some reason than actual categories
                 
                 						temp solution for !all shortcode:
                 						in some (as yet unknown) cases/situations the sorted categories variable gets saved
                 						including some old/non existing ones and therefore consists of
                 						more than actually existing ones
                 						this can result in the last category being displayed multiple times when using !all shortcode
                 
                 						so - as to at least for now fix the symptoms - filter empty ones
                 					********/
                 $querys = array_filter($querys);
             } else {
                 foreach ($catSlugsToArray as $sKey => $slug) {
                     if (trim($slug) != '') {
                         //in case of using two commas omitting slug
                         /*get slug and taxonomy from slug*/
                         $querys[] = get_term_by('slug', $slug, $this->pluginSlugCategoryTaxonomy);
                     }
                 }
             }
         }
         /*exclude header*/
         if (isset($atts['noheader']) || $options['layout']['suppress_loop_headers']) {
             $noheader = 1;
         }
         /**if we want to capture the category id a menu item is currently in **/
         /**DEPRECATED ->this is not required anymore, but we'll leave it here in case someone is using an old customised loop template that wants this variable**/
         if ($options['layout']['items_group_sort_print_by_category']) {
             $getSlugDetails = 1;
         }
         /*show.hide additives at bottom of loop*/
         if (isset($atts['showadditives'])) {
             $showadditives = $atts['showadditives'];
         }
         $exclude = array();
         if (isset($atts['exclude'])) {
             $exclXplode = explode(",", $atts['exclude']);
             foreach ($exclXplode as $exclId) {
                 $exclude[$exclId] = $exclId;
             }
         }
         /*include specific items only -> overrides exclude*****/
         $include = array();
         if (isset($atts['include'])) {
             $exclude = array();
             /*empty exclude*/
             $inclXplode = explode(",", $atts['include']);
             foreach ($inclXplode as $inclId) {
                 $include[$inclId] = $inclId;
             }
         }
         /*set template style if !default*/
         $loStyle = '';
         if ($options['layout']['style'] != 'default') {
             $loStyle = '-' . $options['layout']['style'] . '';
         }
         /**check which template to use**/
         /*include template from theme if exists*/
         if ($template_file = locate_template(array($this->pluginLocateDir . 'wppizza-loop' . $loStyle . '.php'))) {
         } else {
             /*if template not in theme, fallback to template in plugin*/
             $template_file = '' . WPPIZZA_PATH . 'templates/wppizza-loop' . $loStyle . '.php';
         }
         /*cat count*/
         $catCount = count($querys);
         static $loopCount = 0;
         //set static in case there's more than one shortcode on page
         foreach ($querys as $query) {
             /**q vars**/
             if (isset($query) && $query) {
                 $query_var = $query->slug;
             }
             /*include the template**/
             include $template_file;
             do_action('wppizza_loop_template_end');
             $loopCount++;
         }
         return;
         //after loop
     }
     /***************************************
     			[include navigation template]
     		***************************************/
     if ($type == 'navigation') {
         extract(shortcode_atts(array('title' => ''), $atts));
         $child_of = 0;
         if (isset($atts['parent'])) {
             $query = get_term_by('slug', $atts['parent'], $this->pluginSlugCategoryTaxonomy);
             if ($query) {
                 $child_of = $query->term_id;
             }
         }
         $excludeIds = '';
         if (isset($atts['exclude'])) {
             $excludeIds = $atts['exclude'];
         }
         $post_type = $this->pluginSlug;
         $args = array('taxonomy' => $this->pluginSlugCategoryTaxonomy, 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'title_li' => $title, 'depth' => 0, 'exclude' => $excludeIds, 'child_of' => $child_of, 'show_option_none' => __('Nothing here'), 'hide_empty' => 1, 'echo' => 0);
         /***add a filter if required*****/
         $args = apply_filters('wppizza_filter_navigation', $args);
         /*check if the file exists in the theme, otherwise serve the file from the plugin directory if possible*/
         if ($template_file = locate_template(array($this->pluginLocateDir . 'wppizza-navigation.php'))) {
             include $template_file;
             return;
         }
         /*check if it exists in plugin directory (it should really BE there), otherwise we will have to serve defaults**/
         if (is_file('' . WPPIZZA_PATH . 'templates/wppizza-navigation.php')) {
             $template_file = '' . WPPIZZA_PATH . 'templates/wppizza-navigation.php';
             include $template_file;
             return;
         }
     }
     /***************************************
     			[include shopping cart template]
     		***************************************/
     if ($type == 'cart') {
         /**if request is ajax , return formatted tems**/
         if (isset($atts['request'])) {
             $request = $atts['request'];
         }
         /**variables to use in template**/
         $options = $this->pluginOptions;
         $cart = wppizza_order_summary($_SESSION[$this->pluginSession], $options, 'cart');
         $cart = apply_filters('wppizza_filter_order_summary', $cart);
         /**txt variables from settings->localization*/
         $txt = $options['localization'];
         /*put all text varibles into something easier to deal with**/
         /*check if we set width,height**/
         $style = array();
         if (isset($atts['width']) && $atts['width'] != '') {
             $style['width'] = 'width:' . esc_html($atts['width']) . '';
         }
         if (isset($atts['height']) && $atts['height'] != '') {
             $style['height'] = 'height:' . (int) $atts['height'] . 'px';
         }
         if (count($style) > 0) {
             $cartStyle['cart'] = ' style="' . implode(";", $style) . '"';
         }
         if (isset($style['width'])) {
             $cartStyle['width'] = ' style="' . $style['width'] . '"';
         }
         /**make cart sticky**/
         $stickycart = '';
         if (isset($atts['stickycart'])) {
             $stickycart = 'wppizza-cart-sticky';
         }
         /**display order info like discounts and delivery costs**/
         if (isset($atts['orderinfo'])) {
             $orderinfo = true;
         }
         /**display openingtimes above - depending on template - cart? **/
         if (isset($atts['openingtimes'])) {
             $openingTimes = wppizza_frontendOpeningTimes($options);
         }
         /*check if the file exists in the theme, otherwise serve the file from the plugin directory if possible*/
         if ($template_file = locate_template(array($this->pluginLocateDir . '' . $this->pluginSlug . '-cart.php'))) {
             include $template_file;
             return $cart;
         }
         /*check if it exists in plugin directory, otherwise we will have to serve defaults**/
         if (is_file('' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-cart.php')) {
             $template_file = '' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-cart.php';
             include $template_file;
             return $cart;
         }
     }
     /***************************************
     			[include order page template]
     		***************************************/
     if ($type == 'orderpage') {
         /*******get the variables***/
         $options = $this->pluginOptions;
         $cart = wppizza_order_summary($_SESSION[$this->pluginSession], $options, 'orderpage');
         $cart = apply_filters('wppizza_filter_order_summary', $cart);
         /**txt variables from settings->localization*/
         $txt = $options['localization'];
         /**formelements from settings->order form*/
         $formelements = $options['order_form'];
         /**allow filtering of order form form elements**/
         $formelements = apply_filters('wppizza_filter_formfields_order', $formelements);
         /**set session user vars as get vars to prefill form fields***/
         if (isset($_SESSION[$this->pluginSessionGlobal]['userdata']) && is_array($_SESSION[$this->pluginSessionGlobal]['userdata'])) {
             foreach ($_SESSION[$this->pluginSessionGlobal]['userdata'] as $k => $v) {
                 $_GET[$k] = $v;
             }
         }
         sort($formelements);
         if ($cart['shopopen']) {
             /**if the user is logged in , pre-enter the info we have (if prefill is selected in wppizza->order form settings. CHANGED IN VERSION 2.6.5.3***/
             if (is_user_logged_in()) {
                 global $current_user;
                 $getUserMeta = get_user_meta($current_user->ID);
                 foreach ($getUserMeta as $k => $v) {
                     /**for legacy reasons, strip wppizza_ from key*/
                     if (substr($k, 0, 8) == 'wppizza_') {
                         $k = substr($k, 8);
                     }
                     $userMeta[$k] = $v[0];
                 }
             }
             /***if we are adding get vars to the url (if a tip has been added for instance the page will be refreshed with vars appended), force prefill to be enabled and set values accordingly. ADDED IN VERSION 2.8.6**/
             /*
             	$_GET will also include session data set in $_SESSION[$this->pluginSessionGlobal]['userdata'] as they will not be appended to the url anymore (it's just ugly).
             	MODIFIED IN VERSION 2.8.8.3, but no changes made to this file
             */
             $isSelfPickup = !empty($_SESSION[$this->pluginSession]['selfPickup']) ? 1 : 0;
             /**check if self pickup has been selected and make fields required as set in order form settings, ADDED in 2.8.9.10*/
             foreach ($formelements as $elmKey => $elm) {
                 if (isset($_GET[$elm['key']])) {
                     $formelements[$elmKey]['prefill'] = 1;
                     $userMeta[$elm['key']] = $_GET[$elm['key']];
                 }
                 /**do NOT set required flag on selected elements on self-pickup. ADDED in 2.8.9.10 **/
                 if ($isSelfPickup == 1 && !$elm['required_on_pickup']) {
                     $formelements[$elmKey]['required'] = false;
                 }
                 /**DO set required flag on selected elements on self-pickup even if main required is false. ADDED in 2.10.2.1 **/
                 if ($isSelfPickup == 1 && $elm['required_on_pickup']) {
                     $formelements[$elmKey]['required'] = true;
                 }
             }
             /**add invisible div to order page be be able to still add things to cart and reload (for upsells etc)**/
             add_action('wppizza_order_form_inside_top', array($this, 'wppizza_invisible_cart'));
             /*check if the file exists in the theme, otherwise serve the file from the plugin directory if possible*/
             if ($template_file = locate_template(array($this->pluginLocateDir . '' . $this->pluginSlug . '-order.php'))) {
                 include $template_file;
                 return;
             }
             /*check if it exists in plugin directory, otherwise we will have to serve defaults**/
             if (is_file('' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-order.php')) {
                 $template_file = '' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-order.php';
                 include $template_file;
                 return;
             }
         } else {
             /**shop closed->to stop still active sessions**/
             print "<div class='wpppizza-order-shopclosed'><p>" . $cart['innercartinfo'] . "</p></div>";
         }
     }
     /***************************************
     			[include orderhistory template]
     		***************************************/
     if ($type == 'orderhistory') {
         /**just show the login form and return if user is not logged in**/
         if (!is_user_logged_in()) {
             $this->wppizza_do_login_form(null, true);
             return;
         } else {
             global $current_user;
             $current_user->ID;
             do_action('wppizza_get_orderhistory', $current_user->ID, $atts);
         }
     }
     /***************************************
     			[include confirmation page template]
     		***************************************/
     if ($type == 'confirmationpage') {
         /*******get the variables***/
         $options = $this->pluginOptions;
         $cart = wppizza_order_summary($_SESSION[$this->pluginSession], $options, $type);
         $cart = apply_filters('wppizza_filter_order_summary', $cart);
         /**check if tax was included in prices**/
         $taxIncluded = !empty($options['order']['item_tax_included']) ? true : false;
         /**txt variables from settings->localization additional vars > localization_confirmation_form*/
         $localize = array_merge($options['localization'], $options['localization_confirmation_form']);
         $txt = array();
         foreach ($localize as $k => $v) {
             $txt[$k] = $v['lbl'];
         }
         /**set session user vars as get vars to prefill form fields***/
         $userdata = array();
         if (isset($_SESSION[$this->pluginSessionGlobal]['userdata']) && is_array($_SESSION[$this->pluginSessionGlobal]['userdata'])) {
             foreach ($_SESSION[$this->pluginSessionGlobal]['userdata'] as $k => $v) {
                 $userdata[$k] = $v;
             }
         }
         /******************************************
         				output button and payment method
         				and associated costs
         			******************************************/
         $gwClass = new WPPIZZA_GATEWAYS();
         $getGateways = $gwClass->wppizza_instanciate_gateways_frontend();
         /**get wpml vars - should be done better one day using action hooks), but for the moment this will have to do**/
         $gwClass->wppizza_wpml_localization_gateways();
         /********************************************************
          *
          *
          *	output variables
          *
          *
          ********************************************************/
         /************************************************
         				link back to order page
         			************************************************/
         $orderpagelink = $cart['orderpagelink'];
         /************************************************
         				link to amend order
         			************************************************/
         $amendorderlink = $cart['amendorderlink'];
         /************************************************
         				order button
         			************************************************/
         $orderbutton = '';
         /**add required fields**/
         $addClass = '';
         /**add class if customised to - for example - use an overlay **/
         if (!empty($atts['hasClassAjax'])) {
             $addClass = 'class="wppizzaGwAjaxSubmit"';
         }
         if (!empty($atts['hasClassCustom'])) {
             $addClass = 'class="wppizzaGwCustom"';
         }
         $orderbutton .= '<input id="wppizza_hash" name="wppizza_hash" type="hidden" value="' . $atts['hash'] . '"/>';
         $orderbutton .= '<input id="wppizza-gateway" name="wppizza-gateway" ' . $addClass . ' type="hidden" value="' . $atts['gateway'] . '"/>';
         $orderbutton .= $gwClass->wppizza_gateway_standard_button($txt['confirm_now_button']);
         /************************************************
         				formelements to confirm
         				from settings->order form
         			************************************************/
         $confirmationelements = array();
         foreach ($options['confirmation_form'] as $elmKey => $elm) {
             if ($elm['enabled']) {
                 $confirmationelements[$elmKey] = $elm;
             }
         }
         sort($confirmationelements);
         /************************************************
         				submitted and filtered formelements
         			************************************************/
         $formelements = $options['order_form'];
         $formelements = apply_filters('wppizza_filter_formfields_confirmation', $formelements);
         sort($formelements);
         foreach ($formelements as $k => $oForm) {
             $key = $oForm['key'];
             if ($oForm['key'] == 'ctips' || !$oForm['enabled']) {
                 /***exclude disabled and tips (as those belong to order details)**/
                 unset($formelements[$k]);
             } else {
                 if ($oForm['type'] != 'select') {
                     $formelements[$k]['userVal'] = !empty($userdata[$key]) ? $userdata[$key] : '';
                 } else {
                     $formelements[$k]['userVal'] = !empty($oForm['value'][$userdata[$key]]) ? $oForm['value'][$userdata[$key]] : '';
                 }
             }
         }
         /************************************************
         				paymentmethod used
         			************************************************/
         $gatewayLabel = strtoupper($atts['gateway']);
         $getwayUsedIdent = $gatewayLabel;
         if (isset($getGateways[$getwayUsedIdent])) {
             $gatewayLabel = !empty($getGateways[$getwayUsedIdent]->gatewayName) ? $getGateways[$getwayUsedIdent]->gatewayName : $atts['gateway'];
             $gatewayLabel = !empty($getGateways[$getwayUsedIdent]->gatewayOptions['gateway_label']) ? $getGateways[$getwayUsedIdent]->gatewayOptions['gateway_label'] : $gatewayLabel;
         }
         /*************allow to add to paymentmethod by filter*****/
         $paymentmethod = array();
         $paymentmethod = apply_filters('wppizza_filter_paymentmethod_confirmation', $paymentmethod);
         sort($paymentmethod);
         foreach ($paymentmethod as $k => $oForm) {
             $key = $oForm['key'];
             if ($oForm['type'] != 'select') {
                 $paymentmethod[$k]['userVal'] = !empty($userdata[$key]) ? $userdata[$key] : '';
             } else {
                 $paymentmethod[$k]['userVal'] = !empty($oForm['value'][$userdata[$key]]) ? $oForm['value'][$userdata[$key]] : '';
             }
         }
         /***********************************************
         				output what needs outputting
         			***********************************************/
         /*check if the file exists in the theme, otherwise serve the file from the plugin directory if possible*/
         if ($template_file = locate_template(array($this->pluginLocateDir . '' . $this->pluginSlug . '-confirmation.php'))) {
             include $template_file;
             return;
         }
         /*check if it exists in plugin directory, otherwise we will have to serve defaults**/
         if (is_file('' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-confirmation.php')) {
             $template_file = '' . WPPIZZA_PATH . 'templates/' . $this->pluginSlug . '-confirmation.php';
             include $template_file;
             return;
         }
     }
     /*********************************************************
     			[include search box (using shortcode/widget)]
     			uses class to filter/add search variables
     		*********************************************************/
     if ($type == 'search') {
         /**only display for logged in users**/
         if (isset($atts['loggedinonly']) && !is_user_logged_in()) {
             return;
         }
         /**use class to filter/add search variables when using**/
         $searchvars = new WPPIZZA_SEARCH_VARS();
         $searchvars->atts = $atts;
         $searchvars->options = $this->pluginOptions;
         add_filter('get_search_form', array($searchvars, 'searchvars'));
         /**add hidden wppizza input elm**/
         get_search_form();
         /*output - now altered - search form**/
         remove_filter('get_search_form', array($searchvars, 'searchvars'));
         //** reset to original or we will always have the post_type appended to the serach form once it has been run**/
         return;
     }
     /*********************************************************
     			[additives]
     		*********************************************************/
     if ($type == 'additives') {
         $options = $this->pluginOptions;
         $additives = $options['additives'];
         if (is_array($additives) && count($additives) > 0) {
             asort($additives);
             $str = "<div class='wppizza_additives'>";
             foreach ($additives as $k => $additive) {
                 $str .= "<span class='wppizza_additive_" . $k . " wppizza_additive'><span class='wppizza_additive_id'>" . $k . "</span><span class='wppizza_additive_name_" . $k . " wppizza_additive_name'>" . $additive['name'] . "</span></span>";
             }
             $str .= "</div>";
             echo $str;
         }
         return;
     }
 }
 function gateway_order_on_thankyou_process($res, $options = false)
 {
     $output = '';
     /**legacy**/
     if (!$options) {
         $options = $this->pluginOptions;
     }
     /**check if we are displaying the order on the thank you page**/
     if ($options['gateways']['gateway_showorder_on_thankyou']) {
         /*if we are only passing the id, try and get the order from the db first**/
         if (!is_object($res) && is_numeric($res)) {
             global $wpdb;
             $res = $wpdb->get_row("SELECT id,transaction_id,order_ini,customer_ini,initiator FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE id='" . $res . "' ");
         }
         /**********************************************************
         				[get relevant vars out of db
         			**********************************************************/
         $thisCustomerDetails = maybe_unserialize($res->customer_ini);
         $thisOrderDetails = maybe_unserialize($res->order_ini);
         $thisOrderDetails = apply_filters('wppizza_filter_order_db_return', $thisOrderDetails);
         /**********************************************************
         				[organize vars to make them easier to use in template]
         			**********************************************************/
         $order['transaction_id'] = $res->transaction_id;
         /**filter as required**/
         $order['transaction_id'] = apply_filters('wppizza_email_filter_transaction_id', $order['transaction_id'], $res->id, 'order on thank you');
         $order['transaction_date_time'] = "" . date_i18n(get_option('date_format'), $thisOrderDetails['time']) . " " . date_i18n(get_option('time_format'), $thisOrderDetails['time']) . "";
         $order['gatewayUsed'] = $res->initiator;
         /**get gateway frontend label instead of just COD or similar**/
         $order['gatewayLabel'] = $res->initiator;
         $wppizzaGateways = new WPPIZZA_GATEWAYS();
         $this->pluginGateways = $wppizzaGateways->wppizza_instanciate_gateways_frontend();
         /**
         					get wpml vars of gatewway (label and info essentially)- should be done better one day using action hooks), but for the moment this will have to do.
         				**/
         $wppizzaGateways->wppizza_wpml_localization_gateways();
         $gwIni = strtoupper($res->initiator);
         if (isset($this->pluginGateways[$gwIni])) {
             $order['gatewayLabel'] = !empty($this->pluginGateways[$gwIni]->gatewayOptions['gateway_label']) ? $this->pluginGateways[$gwIni]->gatewayOptions['gateway_label'] : $order['gatewayLabel'];
         }
         /**********************/
         $order['currency'] = $thisOrderDetails['currency'];
         /****************************************************
         				[set currency positions]
         			****************************************************/
         $order['currency_left'] = $thisOrderDetails['currency'] . ' ';
         $order['currency_right'] = '';
         if ($options['layout']['currency_symbol_position'] == 'right') {
             /*right aligned*/
             $order['currency_left'] = '';
             $order['currency_right'] = ' ' . $thisOrderDetails['currency'];
         }
         $order['currencyiso'] = $thisOrderDetails['currencyiso'];
         /***********************************************
         				[set localization vars]
         			************************************************/
         $orderlbl = array();
         foreach ($options['localization'] as $k => $v) {
             if ($k == 'taxes_included') {
                 $orderlbl[$k] = sprintf('' . $v['lbl'] . '', $options['order']['item_tax']);
             } else {
                 $orderlbl[$k] = $v['lbl'];
             }
         }
         /***********************************************
         				[customer details]
         				[we should make this into a filter at some point
         				in conjuction with wppizza_filter_customer_details_html
         				used above]
         			***********************************************/
         $customer = array();
         $customerlbl = array();
         $protectedKeys = array();
         foreach ($options['order_form'] as $k => $v) {
             $protectedKeys[$v['key']] = $v;
         }
         $protectedKeys = apply_filters('wppizza_filter_order_form_fields', $protectedKeys);
         foreach ($thisCustomerDetails as $k => $v) {
             /*****default input fields of this plugin*****/
             if (isset($protectedKeys[$k])) {
                 $customerlbl[$k] = $protectedKeys[$k]['lbl'];
                 if ($protectedKeys[$k]['type'] != 'textarea') {
                     $customer[$k] = $v;
                 } else {
                     $customer[$k] = '<div class="wppizza-order-textarea">' . nl2br($v) . '</div>';
                 }
             }
             /**********************************************************************************************************
              *
              *
              *	THIS BIT BELOW SHOULD NOW BE REDUNDANT NOW AS WE CAN UST USE THE FILTER ABOVE TO ADD TO THE - SO CALLED - PROTECTED KEYS
              *	let's leave it here for now, but it will probably be removed in future versions, as it has never been documnted publicly anyway
              *	as far as i know......
              *
              **********************************************************************************************************/
             if (!isset($protectedKeys[$k]) && is_array($v) && isset($v['label']) && isset($v['value'])) {
                 $customer['' . $v['label'] . ''] = $v['value'];
                 $customerlbl['' . $v['label'] . ''] = $v['label'];
             }
         }
         /***********************************************
         				[order items]
         			***********************************************/
         $items = $thisOrderDetails['item'];
         /**filter old legacy additional info keys**/
         $items = apply_filters('wppizza_filter_order_additional_info', $items);
         /**filter new/current extend additional info keys**/
         $items = apply_filters('wppizza_filter_order_extend', $items);
         /**can be run by other plugins**/
         /**return items with html additional info**/
         $items = apply_filters('wppizza_filter_order_items_html', $items, 'additionalInfo');
         /***********************************************
         				[order summary
         			***********************************************/
         $summary['total_price_items'] = $thisOrderDetails['total_price_items'];
         $summary['discount'] = $thisOrderDetails['discount'];
         $summary['item_tax'] = $thisOrderDetails['item_tax'];
         $summary['taxes_included'] = $thisOrderDetails['taxes_included'];
         if ($options['order']['delivery_selected'] != 'no_delivery') {
             /*delivery disabled*/
             $summary['delivery_charges'] = $thisOrderDetails['delivery_charges'];
         }
         $summary['total_price_items'] = $thisOrderDetails['total_price_items'];
         $summary['selfPickup'] = $thisOrderDetails['selfPickup'];
         $summary['total'] = $thisOrderDetails['total'];
         $summary['tax_applied'] = 'items_only';
         if ($options['order']['shipping_tax']) {
             $summary['tax_applied'] = 'items_and_shipping';
         }
         if ($options['order']['taxes_included']) {
             $summary['tax_applied'] = 'taxes_included';
         }
         if (isset($thisOrderDetails['handling_charge']) && $thisOrderDetails['handling_charge'] > 0) {
             $summary['handling_charge'] = wppizza_output_format_price($thisOrderDetails['handling_charge'], $options['layout']['hide_decimals']);
         }
         if (isset($thisOrderDetails['tips']) && $thisOrderDetails['tips'] > 0) {
             $summary['tips'] = wppizza_output_format_price($thisOrderDetails['tips'], $options['layout']['hide_decimals']);
         }
         /***allow some filtering of order and summary***/
         $order = apply_filters('wppizza_filter_order_show_order_page', $order, $thisOrderDetails);
         $summary = apply_filters('wppizza_filter_summary_show_order_page', $summary, $thisOrderDetails);
         /***********************************************
         				[if template copied to theme directory use
         				that one otherwise use default]
         			***********************************************/
         ob_start();
         if (file_exists($this->pluginTemplateDir . '/wppizza-show-order.php')) {
             include $this->pluginTemplateDir . '/wppizza-show-order.php';
         } else {
             include WPPIZZA_PATH . 'templates/wppizza-show-order.php';
         }
         $output .= ob_get_clean();
     }
     return $output;
 }