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; }
function wppizza_get_orderhistory($userid, $atts) { global $wpdb; /*******get the variables***/ $options = $this->pluginOptions; /**initialize some defaults**/ $orders = array(); $ordersPerPage = 10; /*set attribute max per page**/ if (isset($atts['maxpp']) && (int) $atts['maxpp'] > 0) { $ordersPerPage = (int) $atts['maxpp']; } $ordersPerPage = apply_filters('wppizza_history_ordersperpage_filter', $ordersPerPage); if (!isset($_GET['pg']) || (int) $_GET['pg'] < 1) { $limitOffset = 0; } else { $limitOffset = (int) ($_GET['pg'] - 1) * $ordersPerPage; } /**multisite get all orders from all sites*/ $ordersMultisite = false; if (is_multisite() && isset($atts['multisite'])) { /*set flag*/ $ordersMultisite = true; $historyRes = array(); $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A); if ($blogs) { foreach ($blogs as $blog) { $blogid = $blog['blog_id']; $details = get_blog_details($blogid); switch_to_blog($blogid); $multiQuery = "SELECT order_date, id,transaction_id,order_status,order_ini,customer_ini,initiator FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE payment_status IN ('COD','COMPLETED') "; /*allow another where condition**/ $multiQuery = apply_filters('wppizza_history_query_where_filter', $multiQuery); /**limit to user**/ $multiQuery .= "AND wp_user_id=" . $userid . " "; /**sort**/ $multiQuery .= "ORDER BY order_date DESC "; /**get the results and add to array**/ $multiQueryRes = $wpdb->get_results($multiQuery); foreach ($multiQueryRes as $qRes) { $orderBlogId = $qRes->id . '_' . $blogid; //concat order id and blog id to make sure we have a unique id $historyRes[$orderBlogId] = $qRes; $historyRes[$orderBlogId]->blogid = $blogid; $historyRes[$orderBlogId]->blogname = $details->blogname; } /**we also need the blog options**/ $blogoptions[$blogid] = get_option(WPPIZZA_SLUG); /*restore current*/ restore_current_blog(); } } /*get count**/ $historyCount = count($historyRes); /*sort by date in reverse**/ arsort($historyRes); /**slice to get max per page on page**/ $historyRes = array_slice($historyRes, $limitOffset, $ordersPerPage); } /****************************** not using multisite ******************************/ if (!$ordersMultisite) { /**run the query**/ $historyQuery = "SELECT id,transaction_id,order_status,order_ini,customer_ini,initiator FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE payment_status IN ('COD','COMPLETED') "; /*allow another where condition**/ $historyQuery = apply_filters('wppizza_history_query_where_filter', $historyQuery); /**limit to user**/ $historyQuery .= "AND wp_user_id=" . $userid . " "; /**sort**/ $historyQuery .= "ORDER BY order_date DESC "; /**limit**/ $historyQuery .= "limit " . $limitOffset . "," . $ordersPerPage . ""; $historyRes = $wpdb->get_results($historyQuery); /*get count**/ $historyCount = "SELECT count(*) as count FROM " . $wpdb->prefix . $this->pluginOrderTable . " WHERE payment_status IN ('COD','COMPLETED') AND wp_user_id=" . $userid . " "; $historyCount = $wpdb->get_results($historyCount); $historyCount = $historyCount[0]->count; } if (count($historyRes > 0)) { /*********************************************** [set some global localization vars] ************************************************/ $orderlbl = array(); foreach ($this->pluginOptions['localization'] as $k => $v) { if ($k == 'taxes_included') { $orderlbl[$k] = sprintf('' . $v['lbl'] . '', $this->pluginOptions['order']['item_tax']); } else { $orderlbl[$k] = $v['lbl']; } } $output = ''; foreach ($historyRes as $k => $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); if (isset($thisOrderDetails['total'])) { /*just to be sure*/ /***initialize array of this order**/ $orders[$res->id] = array(); /**multisite , get option of appropriate site otherwise use options of this site**/ if (isset($res->blogid) && isset($atts['sitetitle']) && isset($blogoptions[$res->blogid])) { $options = $blogoptions[$res->blogid]; $blogid = $res->blogid; } else { $options = $this->pluginOptions; $blogid = false; } /********************************************************** [organize vars to make them easier to use in template] **********************************************************/ $order['transaction_id'] = $res->transaction_id; $order['order_status'] = $res->order_status; /**filter as required**/ $order['transaction_id'] = apply_filters('wppizza_filter_transaction_id', $order['transaction_id'], $res->id); $order['transaction_date_time'] = "" . date_i18n(get_option('date_format'), $thisOrderDetails['time']) . " " . date_i18n(get_option('time_format'), $thisOrderDetails['time']) . ""; /*useful in multisite perhaps to identify which site the order was made on**/ $order['site_title'] = ''; if (isset($res->blogname) && isset($atts['sitetitle'])) { $order['site_title'] = ' <span class="wppizza-history-sitetitle wppizza-history-site-' . $res->blogid . '">' . $res->blogname . '</span>'; } $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(); $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']; /***allow some filtering of order and summary***/ $order = apply_filters('wppizza_filter_order_history', $order, $thisOrderDetails); /*********************************************** [order items] ***********************************************/ $items = $thisOrderDetails['item']; /**filter old legacy additional info keys**/ $items = apply_filters('wppizza_filter_orderhistory_additional_info', $items); /**filter new/current extend additional info keys**/ $items = apply_filters('wppizza_filter_order_extend', $items); /**return items with html additional info**/ $items = apply_filters('wppizza_filter_orderhistory_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'] = $thisOrderDetails['handling_charge']; } if (isset($thisOrderDetails['tips']) && $thisOrderDetails['tips'] > 0) { $summary['tips'] = $thisOrderDetails['tips']; } $orders[$res->id]['order'] = $order; $orders[$res->id]['items'] = $items; $orders[$res->id]['summary'] = $summary; $orders[$res->id]['options'] = $options; $orders[$res->id]['blogid'] = $blogid; /***allow some filtering of order and summary***/ $summary = apply_filters('wppizza_filter_summary_history', $summary, $thisOrderDetails); } } } $ordersOnPage = count($orders); $numberOfOrders = $historyCount; /*********************************************** [if template copied to theme directory use that one otherwise use default] ***********************************************/ ob_start(); if (file_exists($this->pluginTemplateDir . '/wppizza-orderhistory.php')) { include $this->pluginTemplateDir . '/wppizza-orderhistory.php'; } else { include WPPIZZA_PATH . 'templates/wppizza-orderhistory.php'; } $output .= ob_get_clean(); print "" . $output; }
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; }