/** * Check, if debug logging is enabled * * @since 1.0 * @return bool */ public static function is_debug_enabled() { if (null === self::$is_debug_enabled) { $condition = true; self::$is_debug_enabled = $condition; } return self::$is_debug_enabled; }
/** * Save the Targets settings */ public function save() { try { $this->verify_request(WooCommerce_Grow_Helpers::get_field('_wpnonce', $_REQUEST), 'woocommerce-grow-targets'); $is_calculate_growth = null !== WooCommerce_Grow_Helpers::get_field('calculate_growth', $_POST) ? true : false; // Calculate and Growth settings if ($is_calculate_growth) { $initial_revenue_number = WooCommerce_Grow_Helpers::get_field('initial_revenue_number', $_POST); $initial_orders_number = WooCommerce_Grow_Helpers::get_field('initial_orders_number', $_POST); $initial_sessions_number = WooCommerce_Grow_Helpers::get_field('initial_sessions_number', $_POST); $initial_cr_number = WooCommerce_Grow_Helpers::get_field('initial_cr_number', $_POST); $initial_aov_number = WooCommerce_Grow_Helpers::get_field('initial_aov_number', $_POST); // Call to GA to get sessions for the last month $ga = WooCommerce_Grow_Google_Analytics::get_instance(); $month = date('m', strtotime('first day of previous month')); $year = date('Y'); list($start_date, $end_date) = WooCommerce_Grow_Helpers::get_first_and_last_of_the_month($month, $year); $initial_sessions = $ga->get_sessions_for_month($month, $year); $filters = array('date_min' => $start_date, 'date_max' => $end_date); $reports = WooCommerce_Grow_Helpers::setup_wc_reports($filters); $initial_revenue = WooCommerce_Grow_Helpers::get_wc_total_sales($reports); $initial_orders = WooCommerce_Grow_Helpers::get_wc_total_orders($reports); WooCommerce_Grow_Helpers::add_debug_log('Revenue: ' . $initial_revenue); WooCommerce_Grow_Helpers::add_debug_log('Orders: ' . $initial_orders); $initial_cr = WooCommerce_Grow_Helpers::calculate_cr($initial_orders, $initial_sessions); $initial_aov = WooCommerce_Grow_Helpers::calculate_aov($initial_revenue, $initial_orders); $growth_rate = WooCommerce_Grow_Helpers::get_field('growth_rate', $_POST); // Save the initial options WooCommerce_Grow_Helpers::update_option('initial_revenue_number', $initial_revenue); WooCommerce_Grow_Helpers::update_option('initial_orders_number', $initial_orders); WooCommerce_Grow_Helpers::update_option('initial_sessions_number', $initial_sessions); WooCommerce_Grow_Helpers::update_option('initial_cr_number', $initial_cr); WooCommerce_Grow_Helpers::update_option('initial_aov_number', $initial_aov); WooCommerce_Grow_Helpers::update_option('growth_rate', $growth_rate); $months = WooCommerce_Grow_Helpers::get_twelve_months_ahead(); foreach ($months as $month) { $target_sessions = WooCommerce_Grow_Helpers::calculate_growth($initial_sessions, $growth_rate); $target_cr = WooCommerce_Grow_Helpers::calculate_growth($initial_cr, $growth_rate); $target_aov = WooCommerce_Grow_Helpers::calculate_growth($initial_aov, $growth_rate); $targets['sessions_percentage'][$month['year']][$month['month']] = ceil($target_sessions); $targets['cr_percentage'][$month['year']][$month['month']] = $target_cr; $targets['aov_percentage'][$month['year']][$month['month']] = $target_aov; $targets['revenue_percentage'][$month['year']][$month['month']] = wc_format_decimal($target_sessions * $target_cr * $target_aov, 2); $targets['orders_percentage'][$month['year']][$month['month']] = ceil($target_sessions * $target_cr); } WooCommerce_Grow_Helpers::update_option('monthly_targets', $targets); } } catch (Exception $e) { WC_Admin_Settings::add_error($e->getMessage()); } }
<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
/** * Returns the profile ID from the set Google UID * * TODO: move the use of this method to the UID setting. So we can have the setting value in an easy to get the Profile ID format * TODO: Preferred format: UID:ProfileID * * @since 1.0 * @return array * @throws Exception */ function get_single_ga_profile() { $webproperty_id = get_option('woocommerce_woocommerce_grow_settings'); $ga_uid = $webproperty_id['ga_api_uid']; if (empty($ga_uid)) { // TODO: TEST throw new Exception(sprintf(__('The Google Account User ID is not set. Please visit %ssettings page%s to set the Google UID.', 'woocommerce-grow'), '<a href="' . WooCommerce_Grow_Helpers::get_plugin_settings_page() . '" target="_blank">', '</a>')); } list($pre, $account_id, $post) = explode('-', $ga_uid); try { $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id, $ga_uid); } catch (Exception $e) { throw new Exception(sprintf(__('Analytics API error occurred. Error Code: %s. Error Message: %s ', 'woocommerce-grow'), $e->getCode(), $e->getMessage())); } $profile_id = $profiles->items[0]->id; // If the profile is empty or it does not match the UID we chose to use. if (empty($profile_id) || $ga_uid != $profiles->items[0]->webPropertyId) { throw new Exception(sprintf(__('There is no Google Profile ID found from your Google UID. Please visit %ssettings page%s to set the Google UID.', 'woocommerce-grow'), '<a href="' . WooCommerce_Grow_Helpers::get_plugin_settings_page() . '" target="_blank">', '</a>')); } return $profile_id; }