<div class="wc-grow-cards-wrapper"> <?php // TODO: Add months to plugin activation hook $months = ''; //get_option( WooCommerce_Grow::PREFIX . 'target_months', '' ); if ('' == $months) { $months = WooCommerce_Grow_Helpers::get_twelve_months_ahead(); // update_option( WooCommerce_Grow::PREFIX . 'target_months', $months ); } $monthly_targets = WooCommerce_Grow_Helpers::get_option('monthly_targets', array()); $growth_rate = WooCommerce_Grow_Helpers::get_option('growth_rate'); $initial_revenue = WooCommerce_Grow_Helpers::get_option('initial_revenue_number'); $initial_orders = WooCommerce_Grow_Helpers::get_option('initial_orders_number'); $initial_sessions = WooCommerce_Grow_Helpers::get_option('initial_sessions_number'); $initial_cr = WooCommerce_Grow_Helpers::get_option('initial_cr_number'); $initial_aov = WooCommerce_Grow_Helpers::get_option('initial_aov_number'); $currency_symbol = get_woocommerce_currency_symbol(); foreach ($months as $target_month) { $month = $target_month['month']; $year = $target_month['year']; $month_in_text = date('F', strtotime($year . '-' . $month)); $revenue_percentage = isset($monthly_targets['revenue_percentage'][$year][$month]) ? $monthly_targets['revenue_percentage'][$year][$month] : 'N/A'; $orders_percentage = isset($monthly_targets['orders_percentage'][$year][$month]) ? $monthly_targets['orders_percentage'][$year][$month] : 'N/A'; $sessions_percentage = isset($monthly_targets['sessions_percentage'][$year][$month]) ? $monthly_targets['sessions_percentage'][$year][$month] : 'N/A'; $cr_percentage = isset($monthly_targets['cr_percentage'][$year][$month]) ? $monthly_targets['cr_percentage'][$year][$month] : 'N/A'; $aov_percentage = isset($monthly_targets['aov_percentage'][$year][$month]) ? $monthly_targets['aov_percentage'][$year][$month] : 'N/A'; ?> <div class="wc-grow-month-card"> <div class="wc-grow-panel wc-grow-month-card-panel-top wc-grow-background-color-blue"> <div class="wc-grow-float-right"> <span class="wc-grow-month-name"><?php
/** * Check, if the analytics account is authenticated and has an access token. * Authenticate it, if it is not. * * TODO: have the access token in a transient and check if the token expired before continuing * * @return bool */ function is_app_authenticated() { $access_token = WooCommerce_Grow_Helpers::get_option('access_token'); // We have an access token already if (!empty($access_token)) { try { $this->client->setAccessToken($access_token); } catch (Exception $e) { echo sprintf(__('Error: Unable to set Google Analytics access token. Error Code: %s. Error Message: %s ', 'woocommerce-grow'), $e->getCode(), $e->getMessage()); return false; } } else { $settings = get_option('woocommerce_woocommerce_grow_settings', array()); $auth_code = WooCommerce_Grow_Helpers::get_field('authorization_token', $settings); if (empty($auth_code)) { // TODO: needs behavior return false; } try { // The authenticate method gets an access token, sets the access token // and returns the access token all at once. $access_token = $this->client->authenticate($auth_code); $this->client->setAccessToken($access_token); WooCommerce_Grow_Helpers::update_option('access_token', $access_token); } catch (Exception $e) { echo sprintf(__('Google Analytics was unable to authenticate you. Please refresh and try again. If the problem persists, please obtain a new authorizations token. Error Code: %s. Error Message: %s ', 'woocommerce-grow'), $e->getCode(), $e->getMessage()); return false; } } return true; }