sprintf( __( '%s signups in this period', 'woocommerce' ), '' . sizeof( $this->customers ) . '' ), 'color' => $this->chart_colours['signups'], 'highlight_series' => 2 ); return $legend; } /** * [get_chart_widgets description]. * * @return array */ public function get_chart_widgets() { $widgets = array(); $widgets[] = array( 'title' => '', 'callback' => array( $this, 'customers_vs_guests' ) ); return $widgets; } /** * customers_vs_guests. */ public function customers_vs_guests() { $customer_order_totals = $this->get_order_report_data( array( 'data' => array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders' ) ), 'where_meta' => array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '>' ) ), 'filter_range' => true ) ); $guest_order_totals = $this->get_order_report_data( array( 'data' => array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders' ) ), 'where_meta' => array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '=' ) ), 'filter_range' => true ) ); ?>
__( 'Year', 'woocommerce' ), 'last_month' => __( 'Last Month', 'woocommerce' ), 'month' => __( 'This Month', 'woocommerce' ), '7day' => __( 'Last 7 Days', 'woocommerce' ) ); $this->chart_colours = array( 'signups' => '#3498db', 'customers' => '#1abc9c', 'guests' => '#8fdece' ); $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { $current_range = '7day'; } $this->calculate_current_range( $current_range ); $admin_users = new WP_User_Query( array( 'role' => 'administrator', 'fields' => 'ID' ) ); $manager_users = new WP_User_Query( array( 'role' => 'shop_manager', 'fields' => 'ID' ) ); $users_query = new WP_User_Query( array( 'fields' => array( 'user_registered' ), 'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ) ) ); $this->customers = $users_query->get_results(); foreach ( $this->customers as $key => $customer ) { if ( strtotime( $customer->user_registered ) < $this->start_date || strtotime( $customer->user_registered ) > $this->end_date ) { unset( $this->customers[ $key ] ); } } include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' ); } /** * Output an export link. */ public function get_export_button() { $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; ?> get_order_report_data( array( 'data' => array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders' ), 'post_date' => array( 'type' => 'post_data', 'function' => '', 'name' => 'post_date' ), ), 'where_meta' => array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '>' ) ), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true ) ); $guest_orders = $this->get_order_report_data( array( 'data' => array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders' ), 'post_date' => array( 'type' => 'post_data', 'function' => '', 'name' => 'post_date' ), ), 'where_meta' => array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '=' ) ), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true ) ); $signups = $this->prepare_chart_data( $this->customers, 'user_registered', '', $this->chart_interval, $this->start_date, $this->chart_groupby ); $customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby ); $guest_orders = $this->prepare_chart_data( $guest_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby ); // Encode in json format $chart_data = json_encode( array( 'signups' => array_values( $signups ), 'customer_orders' => array_values( $customer_orders ), 'guest_orders' => array_values( $guest_orders ) ) ); ?>