/** * 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; } }
/** * Returns the instance of the Currency Switcher plugin. * * @return WC_Aelia_CurrencySwitcher */ protected function currency_switcher() { return WC_Aelia_CurrencySwitcher::instance(); }
// Exit if accessed directly // $widget_args is passed when widget is initialised echo get_value('before_widget', $widget_args); // This wrapper is needed for widget JavaScript to work correctly echo '<div class="widget_wc_aelia_currencyswitcher_widget">'; // Title is set in WC_Aelia_CurrencySwitcher_Widget::widget() $currency_switcher_widget_title = get_value('title', $widget_args); if (!empty($currency_switcher_widget_title)) { echo get_value('before_title', $widget_args); echo apply_filters('widget_title', __($currency_switcher_widget_title, $this->text_domain)); echo get_value('after_title', $widget_args); } // If one or more Currencies are misconfigured, inform the Administrators of // such issue if (get_value('misconfigured_currencies', $this, false) === true && current_user_can('manage_options')) { $error_message = WC_Aelia_CurrencySwitcher::instance()->get_error_message(AELIA_CS_ERR_MISCONFIGURED_CURRENCIES); echo '<div class="error">'; echo '<h5 class="title">' . __('Error', $this->text_domain) . '</h5>'; echo $error_message; echo '</div>'; } echo '<!-- Currency Switcher v.' . WC_Aelia_CurrencySwitcher::VERSION . ' - Currency Selector Widget -->'; echo '<form method="post" class="currency_switch_form">'; foreach ($widget_args['currency_options'] as $currency_code => $currency_name) { $button_css_class = 'currency_button ' . $currency_code; if ($currency_code === $widget_args['selected_currency']) { $button_css_class .= ' active'; } echo '<input type="submit" name="aelia_cs_currency" value="' . $currency_code . '" ' . 'class="' . $button_css_class . '" value="' . $currency_name . '" />'; } echo '</form>';
/** * Front-end display of widget. * * @param array $widget_args Widget arguments. * @param array $instance Saved values from database. * @see WP_Widget::widget() */ public function widget($widget_args, $instance = array()) { $this->load_css(); $this->load_js(); if (!is_array($widget_args)) { $widget_args = array(); } $widget_args = array_merge($instance, $widget_args); $widget_type = get_value('widget_type', $widget_args, self::TYPE_DROPDOWN); $widget_template_name = $this->get_widget_template($widget_type); $widget_template_file = WC_Aelia_CurrencySwitcher::instance()->get_template_file($widget_template_name); // Debug //var_dump($widget_template_name, $widget_template_file); if (empty($widget_template_file)) { $this->display_invalid_widget_type_error($widget_type); } else { $widget_args['title'] = apply_filters('wc_aelia_currencyswitcher_widget_title', get_value('title', $widget_args)); $widget_args['currency_options'] = apply_filters('wc_aelia_currencyswitcher_widget_currency_options', $this->get_currency_options()); $selected_currency = get_value('selected_currency', $widget_args); if (empty($selected_currency)) { $widget_args['selected_currency'] = WC_Aelia_CurrencySwitcher::instance()->get_selected_currency(); } // Display the Widget include $widget_template_file; } }
/** * Calculate order totals and taxes in base currency for Orders that have been * generated before version 3.2.10.1402126. This method corrects the calculation * of order totals in base currency, which were incorrectly made taking into * account the exchange markup eventually specified in configuration. * Note: recalculation is made from 2014-01-01 onwards, as exchange rates have * changed significantly in the past months and it's not currently possible * to retrieve them at a specific point in time. * * @return bool */ protected function update_to_3_2_10_1402126() { $base_currency = $this->settings->base_currency(); // Retrieve the exchange rates for the orders whose data already got // partially converted $SQL = "\r\n\t\t\tSELECT\r\n\t\t\t\tposts.ID AS order_id\r\n\t\t\t\t,posts.post_date AS post_date\r\n\t\t\t\t,meta_order.meta_key\r\n\t\t\t\t,meta_order.meta_value\r\n\t\t\t\t-- ,meta_order_base_currency.meta_key AS meta_key_base_currency\r\n\t\t\t\t,meta_order_base_currency.meta_value AS meta_value_base_currency\r\n\t\t\t\t,meta_order_currency.meta_value AS currency\r\n\t\t\tFROM\r\n\t\t\t\t{$this->wpdb->posts} AS posts\r\n\t\t\tJOIN\r\n\t\t\t\t{$this->wpdb->postmeta} AS meta_order ON\r\n\t\t\t\t\t(meta_order.post_id = posts.ID) AND\r\n\t\t\t\t\t(meta_order.meta_key IN ('_order_total', '_order_discount', '_cart_discount', '_order_shipping', '_order_tax', '_order_shipping_tax'))\r\n\t\t\tLEFT JOIN\r\n\t\t\t\t{$this->wpdb->postmeta} AS meta_order_base_currency ON\r\n\t\t\t\t\t(meta_order_base_currency.post_id = posts.ID) AND\r\n\t\t\t\t\t(meta_order_base_currency.meta_key = CONCAT(meta_order.meta_key, '_base_currency')) AND\r\n\t\t\t\t\t(meta_order_base_currency.meta_value > 0)\r\n\t\t\tLEFT JOIN\r\n\t\t\t\t{$this->wpdb->postmeta} AS meta_order_currency ON\r\n\t\t\t\t\t(meta_order_currency.post_id = posts.ID) AND\r\n\t\t\t\t\t(meta_order_currency.meta_key = '_order_currency')\r\n\t\t\tLEFT JOIN\r\n\t\t\t\t{$this->wpdb->term_relationships} AS rel ON\r\n\t\t\t\t\t(rel.object_ID = posts.ID)\r\n\t\t\tLEFT JOIN\r\n\t\t\t\t{$this->wpdb->term_taxonomy} AS taxonomy ON\r\n\t\t\t\t\t(taxonomy.term_taxonomy_id = rel.term_taxonomy_id)\r\n\t\t\tLEFT JOIN\r\n\t\t\t\t{$this->wpdb->terms} AS term ON\r\n\t\t\t\t\t(term.term_id = taxonomy.term_id)\r\n\t\t\tWHERE\r\n\t\t\t\t(posts.post_type = 'shop_order') AND\r\n\t\t\t\t(meta_order.meta_key = '_order_total') AND\r\n\t\t\t\t(meta_order.meta_value IS NOT NULL) AND\r\n\t\t\t\t(meta_order_base_currency.meta_value IS NOT NULL) AND\r\n\t\t\t\t(post_date >= '2014-01-01 00:00:00')\r\n\t\t"; $orders_to_update = $this->select($SQL); // Debug //var_dump($orders_to_update); die(); foreach ($orders_to_update as $order) { // If order currency is empty, for whatever reason, no conversion can be // performed (it's not possible to assume that a specific currency was // used) if (empty($order->currency)) { Logger::log(sprintf(__('Order %s does not have a currency associated, therefore ' . 'it is not possible to determine its value in base currency (%s). ' . 'This may lead to imprecise results in the reports.', AELIA_CS_PLUGIN_TEXTDOMAIN), $order->order_id, $base_currency)); continue; } // Try to retrieve the exchange rate used when the order was placed $value_in_base_currency = $this->convert($order->meta_value, $order->currency, $base_currency, $order); $value_in_base_currency = WC_Aelia_CurrencySwitcher::instance()->float_to_string($value_in_base_currency); try { update_post_meta($order->order_id, $order->meta_key . '_base_currency', $value_in_base_currency); } catch (Exception $e) { $this->add_message(E_USER_ERROR, sprintf(__('Exception occurred updating base currency values for order %s. ' . 'Error: %s.'), $order->order_id, $e->getMessage())); return false; } } return true; }
function bo_get_braintree_merchant_account_id($default_id) { $curr = WC_Aelia_CurrencySwitcher::instance()->get_selected_currency(); switch ($curr) { case 'USD': return BO_BRAINTREE_MERCHANT_ID_USD; case 'EUR': return BO_BRAINTREE_MERCHANT_ID_EUR; default: wp_die('Invalid currency selected in bo_Gateway_Braintree::get_merchant_account_id()'); } }