/** * Indicates if debug mode is active. * * @return bool */ protected static function debug_mode() { if (self::$_debug_mode === null) { self::$_debug_mode = \WC_Aelia_CurrencySwitcher::settings()->debug_mode(); } return self::$_debug_mode; }
/** * Returns the Currency used in the Country to which a specific IP Address * belongs. * * @param string host A host name or IP Address. * @param string default_currency The Currency to use as a default in case the * Country currency could not be detected. * @return string|bool A currency code, or False if an error occurred. */ public function get_currency_by_host($host, $default_currency) { $ip2location = WC_Aelia_IP2Location::factory(); $country_code = $ip2location->get_country_code($host); if ($country_code === false) { Logger::log(sprintf(__('Could not retrieve Country Code for host "%s". Using ' . 'default currency: %s. Error messages (JSON): %s.', AELIA_CS_PLUGIN_TEXTDOMAIN), $host, $default_currency, json_encode($ip2location->get_errors()))); return $default_currency; } $country_currency = $this->get_country_currency($country_code); if (WC_Aelia_CurrencySwitcher::settings()->is_currency_enabled($country_currency)) { return $country_currency; } else { return $default_currency; } }
/** * 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; } }
/** * Class constructor. * * @param array An array of Settings that can be used to override the ones * currently saved in the configuration. * @return WC_Aelia_OpenExchangeRatesModel. */ public function __construct($settings = null) { parent::__construct($settings); // API Key is necessary for the Model to work correctly $this->_api_key = get_value(WC_Aelia_CurrencySwitcher_Settings::FIELD_OPENEXCHANGE_API_KEY, $settings, WC_Aelia_CurrencySwitcher::settings()->current_settings(WC_Aelia_CurrencySwitcher_Settings::FIELD_OPENEXCHANGE_API_KEY)); if (empty($this->_api_key)) { throw new Exception(__('Open Exchange API Key has not been entered. Service cannot be used ' . 'without such key. See http://openexchangerates.org/ for more details.', AELIA_CS_PLUGIN_TEXTDOMAIN)); } }
* variation. In such case, we load it ourselves. */ if (!function_exists('woocommerce_wp_text_input')) { global $woocommerce; if (version_compare($woocommerce->version, '2.1', '<')) { require_once $woocommerce->plugin_path . '/admin/post-types/writepanels/writepanels-init.php'; } } echo '<tr>'; echo '<td colspan="2">'; // This view is designed to be loaded by an instance of // WC_Aelia_CurrencyPrices_Manager. Such instance is what "$this" and "self" // refer to. $currencyprices_manager = $this; $enabled_currencies = $currencyprices_manager->enabled_currencies(); $base_currency = WC_Aelia_CurrencySwitcher::settings()->base_currency(); $post_id = $currencyprices_manager->current_post->ID; $loop = $currencyprices_manager->loop_idx; echo '<div id="wc_aelia_cs_product_prices" class="clearfix hide_if_variable-subscription">'; // Display header of currency pricing section include 'product_currencyprices_header.php'; echo '<div id="regular_prices">'; $product_regular_prices = $currencyprices_manager->get_variation_regular_prices($post_id); // Outputs the Product Variation prices in the different Currencies foreach ($enabled_currencies as $currency) { if ($currency == $base_currency) { continue; } woocommerce_wp_text_input(array('id' => WC_Aelia_CurrencyPrices_Manager::FIELD_VARIABLE_REGULAR_CURRENCY_PRICES . "[{$loop}][{$currency}]", 'class' => 'wc_input_price short', 'label' => __('Regular Price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol($currency) . ')', 'type' => 'number', 'value' => get_value($currency, $product_regular_prices, null), 'placeholder' => __('Auto', AELIA_CS_PLUGIN_TEXTDOMAIN), 'custom_attributes' => array('step' => 'any', 'min' => '0'))); } echo '</div>';
/** * Checks that plugin requirements are satisfied. * * @return bool */ public static function check_requirements() { self::$requirements_errors = array(); if (PHP_VERSION < '5.3') { self::$requirements_errors[] = __('Plugin requires PHP 5.3 or greater. Please upgrade PHP to version 5.3 ' . 'or higher, or ask your hosting provider to do so. Of course, please make sure ' . 'that you make a backup of your site(s) before proceeding. The upgrade to PHP ' . '5.3 is fairly safe, but it is always better to keep backups before performing ' . 'any important operation.', AELIA_CS_PLUGIN_TEXTDOMAIN); } // Check that all required extensions are loaded $required_extensions = array('curl'); $extension_errors = self::check_required_extensions($required_extensions); self::$requirements_errors = array_merge(self::$requirements_errors, $extension_errors); return empty(self::$requirements_errors); }
/** * Returns the instance of the settings controller loaded by the plugin. * * @return WC_Aelia_CurrencySwitcher_Settings */ protected function settings_controller() { return WC_Aelia_CurrencySwitcher::settings(); }
// 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>';
/** * Convenience method. Returns an array of the Enabled Currencies. * * @return array */ protected function enabled_currencies() { return WC_Aelia_CurrencySwitcher::settings()->get_enabled_currencies(); }
/** * Returns an array of Currency => Currency Name pairs. * * @return array An array of Currency => Currency Name pairs. */ protected function get_currency_options() { $result = array(); $settings_controller = WC_Aelia_CurrencySwitcher::settings(); $enabled_currencies = $settings_controller->get_enabled_currencies(); $exchange_rates = $settings_controller->get_exchange_rates(); $woocommerce_currencies = get_woocommerce_currencies(); foreach ($enabled_currencies as $currency) { // Display only Currencies supported by WooCommerce if (($currency_name = get_value($currency, $woocommerce_currencies, false)) != false) { // Display only currencies with a valid Exchange Rate if (get_value($currency, $exchange_rates, 0) > 0) { $result[$currency] = $currency_name; } else { $this->misconfigured_currencies = true; } } } return $result; }
/** * Calculate order items totals and taxes in base currency for all orders. * This method adds the line totals in base currency for all the order items * created before Currency Switcher 3.2.11.140227 was installed. * * @return bool */ protected function update_to_3_3_7_140611() { $price_decimals = WC_Aelia_CurrencySwitcher::settings()->price_decimals($this->settings->base_currency()); // Retrieve the order items for which the values in base currencies will be // added/updated $SQL = $this->wpdb->prepare("\r\n\t\t\tINSERT INTO {$this->wpdb->prefix}woocommerce_order_itemmeta (\r\n\t\t\t\torder_item_id\r\n\t\t\t\t,meta_key\r\n\t\t\t\t,meta_value\r\n\t\t\t)\r\n\t\t\tSELECT\r\n\t\t\t\tLINE_ITEMS_DATA.order_item_id\r\n\t\t\t\t,LINE_ITEMS_DATA.order_item_meta_key_base_currency\r\n\t\t\t\t,LINE_ITEMS_DATA.meta_value_base_currency\r\n\t\t\tFROM (\r\n\t\t\t\t-- Fetch all line items for whom the totals in base currency have not been saved yet\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tposts.ID AS order_id\r\n\t\t\t\t\t,meta_order_base_currency.meta_value / meta_order.meta_value as exchange_rate\r\n\t\t\t\t\t,WCOI.order_item_id\r\n\t\t\t\t\t,WCOI.order_item_type\r\n\t\t\t\t\t,WCOIM.meta_key\r\n\t\t\t\t\t,WCOIM.meta_value\r\n\t\t\t\t\t,CONCAT(WCOIM.meta_key, '_base_currency') AS order_item_meta_key_base_currency\r\n\t\t\t\t\t,ROUND(WCOIM.meta_value * (meta_order_base_currency.meta_value / meta_order.meta_value), %d) AS meta_value_base_currency\r\n\t\t\t\tFROM\r\n\t\t\t\t\t{$this->wpdb->posts} AS posts\r\n\t\t\t\tJOIN\r\n\t\t\t\t\t{$this->wpdb->postmeta} AS meta_order ON\r\n\t\t\t\t\t\t(meta_order.post_id = posts.ID) AND\r\n\t\t\t\t\t\t(meta_order.meta_key IN ('_order_total'))\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->postmeta} AS meta_order_base_currency ON\r\n\t\t\t\t\t\t(meta_order_base_currency.post_id = posts.ID) AND\r\n\t\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\t(meta_order_base_currency.meta_value > 0)\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->postmeta} AS meta_order_currency ON\r\n\t\t\t\t\t\t(meta_order_currency.post_id = posts.ID) AND\r\n\t\t\t\t\t\t(meta_order_currency.meta_key = '_order_currency')\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->term_relationships} AS rel ON\r\n\t\t\t\t\t\t(rel.object_ID = posts.ID)\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->term_taxonomy} AS taxonomy ON\r\n\t\t\t\t\t\t(taxonomy.term_taxonomy_id = rel.term_taxonomy_id)\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->terms} AS term ON\r\n\t\t\t\t\t\t(term.term_id = taxonomy.term_id)\r\n\t\t\t\t-- Order items\r\n\t\t\t\tJOIN\r\n\t\t\t\t\t{$this->wpdb->prefix}woocommerce_order_items WCOI ON\r\n\t\t\t\t\t\t(WCOI.order_id = posts.ID)\r\n\t\t\t\tJOIN\r\n\t\t\t\t\t{$this->wpdb->prefix}woocommerce_order_itemmeta WCOIM ON\r\n\t\t\t\t\t\t(WCOIM.order_item_id = WCOI.order_item_id) AND\r\n\t\t\t\t\t\t(WCOIM.meta_key IN ('_line_subtotal',\r\n\t\t\t\t\t\t\t\t\t\t\t'_line_subtotal_tax',\r\n\t\t\t\t\t\t\t\t\t\t\t'_line_tax',\r\n\t\t\t\t\t\t\t\t\t\t\t'_line_total',\r\n\t\t\t\t\t\t\t\t\t\t\t'tax_amount',\r\n\t\t\t\t\t\t\t\t\t\t\t'shipping_tax_amount'))\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t{$this->wpdb->prefix}woocommerce_order_itemmeta WCOIM_TOUPDATE ON\r\n\t\t\t\t\t\t(WCOIM_TOUPDATE.order_item_id = WCOIM.order_item_id) AND\r\n\t\t\t\t\t\t(WCOIM_TOUPDATE.meta_key = CONCAT(WCOIM.meta_key, '_base_currency'))\r\n\t\t\t\tWHERE\r\n\t\t\t\t\t(WCOIM_TOUPDATE.meta_value IS NULL) AND\r\n\t\t\t\t\t(posts.post_type = 'shop_order') AND\r\n\t\t\t\t\t(meta_order.meta_key = '_order_total') AND\r\n\t\t\t\t\t(meta_order.meta_value IS NOT NULL) AND\r\n\t\t\t\t\t(meta_order_base_currency.meta_value IS NOT NULL)\r\n\t\t\t) AS LINE_ITEMS_DATA;\r\n\t\t", $price_decimals); //var_dump($SQL);die(); $this->add_message(E_USER_NOTICE, __('Recalculating line totals in base currency...')); $rows_affected = $this->exec($SQL); // Debug //var_dump($order_items_to_update);die(); if ($rows_affected === false) { $this->add_message(E_USER_ERROR, __('Failed. Please check PHP error log for error messages ' . 'related to the operation.')); return false; } else { $this->add_message(E_USER_NOTICE, sprintf(__('Done. %s rows affected.'), $rows_affected)); } 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()'); } }