register_network_order_widget(); } } /** * Register the network order dashboard widget. */ public function register_network_order_widget() { wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce Network Orders', 'woocommerce' ), array( $this, 'network_orders' ) ); } /** * Get top seller from DB. * * @return object */ private function get_top_seller() { global $wpdb; $query = array(); $query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id FROM {$wpdb->posts} as posts"; $query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id "; $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id "; $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id "; $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) "; $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) "; $query['where'] .= "AND order_item_meta.meta_key = '_qty' "; $query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' "; $query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' "; $query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' "; $query['groupby'] = 'GROUP BY product_id'; $query['orderby'] = 'ORDER BY qty DESC'; $query['limits'] = 'LIMIT 1'; return $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } /** * Get sales report data. * * @return object */ private function get_sales_report_data() { include_once dirname( __FILE__ ) . '/reports/class-wc-report-sales-by-date.php'; $sales_by_date = new WC_Report_Sales_By_Date(); $sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) ); $sales_by_date->end_date = strtotime( date( 'Y-m-d', current_time( 'timestamp' ) ) ); $sales_by_date->chart_groupby = 'day'; $sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)'; return $sales_by_date->get_report_data(); } /** * Show status widget. */ public function status_widget() { include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php'; $reports = new WC_Admin_Report(); echo ''; } /** * Show order data is status widget. */ private function status_widget_order_rows() { if ( ! current_user_can( 'edit_shop_orders' ) ) { return; } $on_hold_count = 0; $processing_count = 0; foreach ( wc_get_order_types( 'order-count' ) as $type ) { $counts = (array) wp_count_posts( $type ); $on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0; $processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0; } ?>
  • %s order awaiting processing', '%s orders awaiting processing', $processing_count, 'woocommerce' ), $processing_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
  • %s order on-hold', '%s orders on-hold', $on_hold_count, 'woocommerce' ), $on_hold_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
  • get_var( $wpdb->prepare( "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} AS lookup INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID WHERE stock_quantity <= %d AND stock_quantity > %d AND posts.post_status = 'publish'", $stock, $nostock ) ); } set_transient( $transient_name, (int) $lowinstock_count, DAY_IN_SECONDS * 30 ); } $transient_name = 'wc_outofstock_count'; $outofstock_count = get_transient( $transient_name ); if ( false === $outofstock_count ) { /** * Status widget out of stock count pre query. * * @since 4.3.0 * @param null|string $outofstock_count Out of stock count, by default null. * @param int $nostock No stock amount */ $outofstock_count = apply_filters( 'woocommerce_status_widget_out_of_stock_count_pre_query', null, $nostock ); if ( is_null( $outofstock_count ) ) { $outofstock_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} AS lookup INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID WHERE stock_quantity <= %d AND posts.post_status = 'publish'", $nostock ) ); } set_transient( $transient_name, (int) $outofstock_count, DAY_IN_SECONDS * 30 ); } ?>
  • %s product low in stock', '%s products low in stock', $lowinstock_count, 'woocommerce' ), $lowinstock_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
  • %s product out of stock', '%s products out of stock', $outofstock_count, 'woocommerce' ), $outofstock_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
  • comments} comments LEFT JOIN {$wpdb->posts} posts ON (comments.comment_post_ID = posts.ID) WHERE comments.comment_approved = '1' AND comments.comment_type = 'review' AND posts.post_password = '' AND posts.post_type = 'product' AND comments.comment_parent = 0 ORDER BY comments.comment_date_gmt DESC LIMIT 5" ); $comments = $wpdb->get_results( "SELECT posts.ID, posts.post_title, comments.comment_author, comments.comment_ID, comments.comment_content {$query_from};" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared ); if ( $comments ) { echo ''; } else { echo '

    ' . esc_html__( 'There are no product reviews yet.', 'woocommerce' ) . '

    '; } } /** * Network orders widget. */ public function network_orders() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION ); wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true ); $user = wp_get_current_user(); $blogs = get_blogs_of_user( $user->ID ); $blog_ids = wp_list_pluck( $blogs, 'userblog_id' ); wp_localize_script( 'wc-network-orders', 'woocommerce_network_orders', array( 'nonce' => wp_create_nonce( 'wp_rest' ), 'sites' => array_values( $blog_ids ), 'order_endpoint' => get_rest_url( null, 'wc/v3/orders/network' ), ) ); ?>