sprintf( __( '%s signups in this period', 'woocommerce' ), '' . count( $this->customers ) . '' ), 'color' => $this->chart_colours['signups'], 'highlight_series' => 2, ); return $legend; } /** * Get chart widgets. * * @return array */ public function get_chart_widgets() { $widgets = array(); $widgets[] = array( 'title' => '', 'callback' => array( $this, 'customers_vs_guests' ), ); return $widgets; } /** * Output customers vs guests chart. */ public function customers_vs_guests() { $customer_args = array( 'data' => array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders', ), ), 'filter_range' => true, ); $guest_args = $customer_args; // On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table. if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) { $customer_args['where'] = array( array( 'key' => 'post_author', 'value' => '0', 'operator' => '>', ), ); $guest_args['where'] = array( array( 'key' => 'post_author', 'value' => '0', 'operator' => '=', ), ); } else { $customer_args['where_meta'] = array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '>', ), ); $guest_args['where_meta'] = array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '=', ), ); } $customer_order_totals = $this->get_order_report_data( $customer_args ); $guest_order_totals = $this->get_order_report_data( $guest_args ); ?>
__( '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( wp_unslash( $_GET['range'] ) ) : '7day'; if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ), true ) ) { $current_range = '7day'; } $this->check_current_range_nonce( $current_range ); $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( wp_unslash( $_GET['range'] ) ) : '7day'; ?> array( 'ID' => array( 'type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders', ), 'post_date' => array( 'type' => 'post_data', 'function' => '', 'name' => 'post_date', ), ), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, ); $guest_args = $customer_args; // On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table. if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) { $customer_args['where'] = array( array( 'key' => 'post_author', 'value' => '0', 'operator' => '>', ), ); $guest_args['where'] = array( array( 'key' => 'post_author', 'value' => '0', 'operator' => '=', ), ); } else { $customer_args['where_meta'] = array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '>', ), ); $guest_args['where_meta'] = array( array( 'meta_key' => '_customer_user', 'meta_value' => '0', 'operator' => '=', ), ); } $customer_orders = $this->get_order_report_data( $customer_args ); $guest_orders = $this->get_order_report_data( $guest_args ); $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 ); $chart_data = array( 'signups' => array_values( $signups ), 'customer_orders' => array_values( $customer_orders ), 'guest_orders' => array_values( $guest_orders ), ); ?>