/** * Intercepts the data about to be passed to KISSMetrics, replacing the order * totals with their counterpart in base currency. * * @param array kissmetrics_properties The data to be passed to KISSMetrics. * @return array */ public function wc_kissmetrics_completed_purchase_properties($kissmetrics_properties) { $order_id = get_value('order_id', $kissmetrics_properties); if (!empty($order_id)) { $order = new Aelia_Order($order_id); $kissmetrics_properties['order_total'] = $order->get_total_in_base_currency(); $kissmetrics_properties['shipping_total'] = $order->get_shipping_in_base_currency(); } return $kissmetrics_properties; }
/** * Displays additional data in the "orders list" page. * * @param string column The column being displayed. */ public function manage_shop_order_posts_custom_column($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = new Aelia_Order($post->ID); } switch ($column) { case 'order_total': case 'total_cost': $base_currency = WC_Aelia_CurrencySwitcher::settings()->base_currency(); /* If order is not in base currency, display order total in base currency * before the one in order currency. It's not possible to display it after, * because WooCommerce core simply outputs the information and it's not * possible to modify it. */ if ($the_order->get_order_currency() != $base_currency) { $order_total_base_currency = WC_Aelia_CurrencySwitcher::instance()->format_price($the_order->get_total_in_base_currency(), $base_currency); echo '<div class="order_total_base_currency" title="' . __('Order total in base currency (estimated)', AELIA_CS_PLUGIN_TEXTDOMAIN) . '">'; echo '(' . esc_html(strip_tags($order_total_base_currency)) . ')'; echo '</div>'; } break; } }
/** * Filters Post metadata being retrieved before it's returned to caller. * * @param mixed metadata The original metadata. * @param int object_id The post ID. * @param meta_key The metadata to be retrieved. * @return mixed The metadata value. */ public function get_post_metadata($metadata, $object_id, $meta_key) { if (version_compare($this->wc()->version, '2.1', '>=')) { return $metadata; } // WooCommerce 2.0.x only // This method is only called during generation of "Sales overview" report // page. Order totals in base currency should be used for reporting. // NOTE: this method of returning the order totals in base currency is a hack, // but there is no other way to do it, because the "Sales overview" reports // don't call a hook that allows to alter the values, or the fields retrieved, // but they just call get_post_meta() for every order. // See file woocommerce-admin-reports.php, method woocommerce_sales_overview(), // line ~472. if ($meta_key == '_order_total') { $meta_cache = update_meta_cache('post', array($object_id)); $obj_cache = $meta_cache[$object_id]; $order = new Aelia_Order($object_id); return $order->get_total_in_base_currency(); } return $metadata; }