/** * 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; }
/** * Filters the available payment gateways based on the selected currency. * * @param array available_gateways A list of the available gateways to filter. * @return array */ public function woocommerce_available_payment_gateways($available_gateways) { global $wp; $payment_currency = null; // If customer is paying for an existing order, take its currency $order_id = $this->user_is_paying_existing_order(); if (is_numeric($order_id)) { // Debug //var_dump("PAYING ORDER " . $order_id); $order = new Aelia_Order($order_id); $payment_currency = $order->get_order_currency(); } // If payment currency is empty, then customer is paying for a new order. In // such case, take the active currency if (empty($payment_currency)) { $payment_currency = $this->get_selected_currency(); } // Debug //var_dump($payment_currency); $currency_gateways = self::settings()->currency_payment_gateways($payment_currency); // If no payment gateway has been enabled for a currency, it most probably // means that the Currency Switcher has not been configured properly. In such // case, return all payment gateways originally passed by WooCommerce, to // allow the Customer to complete the order. if (empty($currency_gateways)) { return $available_gateways; } //var_dump($currency_gateways, $available_gateways); foreach ($available_gateways as $gateway_id => $gateway) { if (!in_array($gateway_id, $currency_gateways)) { unset($available_gateways[$gateway_id]); } } return $available_gateways; }
/** * Overrides the currency symbol displayed by WooCommerce, depending on the * Admin page being rendered. * * @param string currency_symbol The currency symbol currently used. * @param string currency The currency. * @return string */ public function woocommerce_currency_symbol($currency_symbol, $currency) { if (is_admin() && !defined('DOING_AJAX') && function_exists('get_current_screen')) { $screen = get_current_screen(); // WooCommerce 2.1 // When viewing an Order, override the currency symbol and force it to the // one of the currency in which the order was placed if ($screen->base == 'post') { global $post; static $overriding_currency_symbol = false; // If we are already overriding the symbol, just return it. This will prevent // infinite loops if ($overriding_currency_symbol) { return $currency_symbol; } if (get_value('post_type', $post) == 'shop_order') { $overriding_currency_symbol = true; $order = new Aelia_Order($post->ID); $currency_symbol = get_woocommerce_currency_symbol($order->get_order_currency()); $overriding_currency_symbol = false; } } } return $currency_symbol; }
/** * Google Analytics eCommerce tracking. This method replicates the logic of * WC_Google_Analytics::ecommerce_tracking_code(), with the addition of tracking * order currency as well. * * @param mixed $order_id * @see WC_Google_Analytics::ecommerce_tracking_code() */ public function ecommerce_tracking_code($order_id) { global $woocommerce; $tracking_id = $this->ga_id; if (!$tracking_id) { return; } if ($this->ga_ecommerce_tracking_enabled == "no" || current_user_can('manage_options') || get_post_meta($order_id, '_ga_tracked', true) == 1) { return; } // Doing eCommerce tracking so unhook standard tracking from the footer remove_action('wp_footer', array($this, 'google_tracking_code')); // Get the order and output tracking code. Use Aelia_Order class, which allows // to retrieve the order currency $order = new Aelia_Order($order_id); $loggedin = is_user_logged_in() ? 'yes' : 'no'; if (is_user_logged_in()) { $user_id = get_current_user_id(); $current_user = get_user_by('id', $user_id); $username = $current_user->user_login; } else { $user_id = ''; $username = __('Guest', 'woocommerce'); } if (!empty($this->ga_set_domain_name)) { $set_domain_name = "['_setDomainName', '" . esc_js($this->ga_set_domain_name) . "'],"; } else { $set_domain_name = ''; } $code = "\r\n\t\t\tvar _gaq = _gaq || [];\r\n\r\n\t\t\t_gaq.push(\r\n\t\t\t\t['_setAccount', '" . esc_js($tracking_id) . "'], " . $set_domain_name . "\r\n\t\t\t\t['_setCustomVar', 1, 'logged-in', '" . esc_js($loggedin) . "', 1],\r\n\t\t\t\t['_trackPageview']\r\n\t\t\t);\r\n\r\n\t\t\t_gaq.push(['_addTrans',\r\n\t\t\t\t'" . esc_js($order->get_order_number()) . "', // order ID - required\r\n\t\t\t\t'" . esc_js(get_bloginfo('name')) . "', // affiliation or store name\r\n\t\t\t\t'" . esc_js($order->get_total()) . "', // total - required\r\n\t\t\t\t'" . esc_js($order->get_total_tax()) . "', // tax\r\n\t\t\t\t'" . esc_js($order->get_shipping()) . "', // shipping\r\n\t\t\t\t'" . esc_js($order->billing_city) . "', // city\r\n\t\t\t\t'" . esc_js($order->billing_state) . "', // state or province\r\n\t\t\t\t'" . esc_js($order->billing_country) . "' // country\r\n\t\t\t]);\r\n\t\t"; // Order items if ($order->get_items()) { foreach ($order->get_items() as $item) { $_product = $order->get_product_from_item($item); $code .= "_gaq.push(['_addItem',"; $code .= "'" . esc_js($order->get_order_number()) . "',"; $code .= "'" . esc_js($_product->get_sku() ? __('SKU:', 'woocommerce') . ' ' . $_product->get_sku() : $_product->id) . "',"; $code .= "'" . esc_js($item['name']) . "',"; if (isset($_product->variation_data)) { $code .= "'" . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . "',"; } else { $out = array(); $categories = get_the_terms($_product->id, 'product_cat'); if ($categories) { foreach ($categories as $category) { $out[] = $category->name; } } $code .= "'" . esc_js(join("/", $out)) . "',"; } $code .= "'" . esc_js($order->get_item_total($item, true, true)) . "',"; $code .= "'" . esc_js($item['qty']) . "'"; $code .= "]);"; } } // Track order currency $order_currency = $order->get_order_currency(); $code .= "\r\n\t\t\t_gaq.push(['_set', 'currencyCode', '" . esc_js($order_currency) . "']);\r\n\t\t"; $code .= "\r\n\t\t\t_gaq.push(['_trackTrans']); // submits transaction to the Analytics servers\r\n\r\n\t\t\t(function() {\r\n\t\t\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r\n\t\t\t\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r\n\t\t\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r\n\t\t\t})();\r\n\t\t"; echo '<script type="text/javascript">' . $code . '</script>'; update_post_meta($order_id, '_ga_tracked', 1); }