2019-04-11 18:31:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Analytics.
|
|
|
|
* NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-admin.
|
|
|
|
*
|
|
|
|
* @package Woocommerce Admin
|
|
|
|
*/
|
|
|
|
|
2019-08-01 18:17:08 +00:00
|
|
|
namespace Automattic\WooCommerce\Admin\Features;
|
|
|
|
|
2019-04-11 18:31:31 +00:00
|
|
|
/**
|
|
|
|
* Contains backend logic for the Analytics feature.
|
|
|
|
*/
|
2019-08-12 18:50:22 +00:00
|
|
|
class Analytics {
|
2019-04-11 18:31:31 +00:00
|
|
|
/**
|
|
|
|
* Class instance.
|
|
|
|
*
|
2019-08-12 21:52:09 +00:00
|
|
|
* @var Analytics instance
|
2019-04-11 18:31:31 +00:00
|
|
|
*/
|
|
|
|
protected static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get class instance.
|
|
|
|
*/
|
|
|
|
public static function get_instance() {
|
|
|
|
if ( ! self::$instance ) {
|
|
|
|
self::$instance = new self();
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook into WooCommerce.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
add_filter( 'woocommerce_component_settings_preload_endpoints', array( $this, 'add_preload_endpoints' ) );
|
|
|
|
add_filter( 'wc_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
|
|
|
|
add_action( 'admin_menu', array( $this, 'register_pages' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preload data from the countries endpoint.
|
|
|
|
*
|
|
|
|
* @param array $endpoints Array of preloaded endpoints.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function add_preload_endpoints( $endpoints ) {
|
2019-11-12 18:15:55 +00:00
|
|
|
$endpoints['countries'] = '/wc-analytics/data/countries';
|
2019-04-11 18:31:31 +00:00
|
|
|
return $endpoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds fields so that we can store user preferences for the columns to display on a report.
|
|
|
|
*
|
|
|
|
* @param array $user_data_fields User data fields.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function add_user_data_fields( $user_data_fields ) {
|
|
|
|
return array_merge(
|
|
|
|
$user_data_fields,
|
|
|
|
array(
|
|
|
|
'categories_report_columns',
|
|
|
|
'coupons_report_columns',
|
|
|
|
'customers_report_columns',
|
|
|
|
'orders_report_columns',
|
|
|
|
'products_report_columns',
|
|
|
|
'revenue_report_columns',
|
|
|
|
'taxes_report_columns',
|
|
|
|
'variations_report_columns',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers report pages.
|
|
|
|
*/
|
|
|
|
public function register_pages() {
|
2019-04-17 02:31:55 +00:00
|
|
|
$report_pages = array(
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics',
|
|
|
|
'title' => __( 'Analytics', 'woocommerce-admin' ),
|
|
|
|
'path' => '/analytics/revenue',
|
|
|
|
'icon' => 'dashicons-chart-bar',
|
|
|
|
'position' => 56, // After WooCommerce & Product menu items.
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'woocommerce-analytics-revenue',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Revenue', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/revenue',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-orders',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Orders', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/orders',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-products',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Products', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/products',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-categories',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Categories', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/categories',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-coupons',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Coupons', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/coupons',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-taxes',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Taxes', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/taxes',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-downloads',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Downloads', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/downloads',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
|
|
|
'yes' === get_option( 'woocommerce_manage_stock' ) ? array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-stock',
|
2019-04-17 02:31:55 +00:00
|
|
|
'title' => __( 'Stock', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-17 02:31:55 +00:00
|
|
|
'path' => '/analytics/stock',
|
|
|
|
) : null,
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-customers',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Customers', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/customers',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
array(
|
2019-05-07 18:43:18 +00:00
|
|
|
'id' => 'woocommerce-analytics-settings',
|
2019-04-11 18:31:31 +00:00
|
|
|
'title' => __( 'Settings', 'woocommerce-admin' ),
|
2019-05-07 18:43:18 +00:00
|
|
|
'parent' => 'woocommerce-analytics',
|
2019-04-11 18:31:31 +00:00
|
|
|
'path' => '/analytics/settings',
|
2019-04-17 02:31:55 +00:00
|
|
|
),
|
2019-04-11 18:31:31 +00:00
|
|
|
);
|
2019-04-17 02:31:55 +00:00
|
|
|
|
2019-12-05 23:06:11 +00:00
|
|
|
$report_pages = apply_filters( 'woocommerce_analytics_report_menu_items', $report_pages );
|
2019-04-17 02:31:55 +00:00
|
|
|
|
|
|
|
foreach ( $report_pages as $report_page ) {
|
|
|
|
if ( ! is_null( $report_page ) ) {
|
|
|
|
wc_admin_register_page( $report_page );
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 18:31:31 +00:00
|
|
|
}
|
|
|
|
}
|