get_wishlist_table(); $items = $db->get_items_table(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Aggregate over internal table; no user input. $total_wishlists = (int) $wpdb->get_var( "SELECT COUNT(*) FROM $wishlists" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Aggregate over internal table; no user input. $total_items = (int) $wpdb->get_var( "SELECT COUNT(*) FROM $items" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Aggregate over internal table; no user input. $unique_products = (int) $wpdb->get_var( "SELECT COUNT(DISTINCT product_id) FROM $items" ); $total_adds = (int) get_option( 'airy_wishlist_total_adds', 0 ); $total_carts = (int) get_option( 'airy_wishlist_total_carts', 0 ); return array( 'total_wishlists' => $total_wishlists, 'total_items' => $total_items, 'unique_products' => $unique_products, 'total_adds' => $total_adds, 'total_carts' => $total_carts, 'conversion' => $total_adds > 0 ? round( ( $total_carts / $total_adds ) * 100, 1 ) : 0, ); } /** * Get the most-wishlisted products (currently saved). * * @param int $limit Number of products. * @return array */ private function get_top_products( $limit = 20 ) { global $wpdb; $db = Airy_Wishlist_Database::instance(); $items = $db->get_items_table(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching -- Aggregate over internal table. return $wpdb->get_results( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is safe, comes from internal method. "SELECT product_id, COUNT(*) AS cnt FROM $items GROUP BY product_id ORDER BY cnt DESC LIMIT %d", $limit ) ); } /** * Render the analytics dashboard as a settings-page tab. */ public function render_dashboard() { $totals = $this->get_totals(); $top = $this->get_top_products( 20 ); ?>
render_stat_card( __( 'Total Wishlists', 'airy-wishlist' ), $totals['total_wishlists'] ); $this->render_stat_card( __( 'Items Saved (now)', 'airy-wishlist' ), $totals['total_items'] ); $this->render_stat_card( __( 'Unique Products', 'airy-wishlist' ), $totals['unique_products'] ); $this->render_stat_card( __( 'All-time Adds', 'airy-wishlist' ), $totals['total_adds'] ); $this->render_stat_card( __( 'Added to Cart', 'airy-wishlist' ), $totals['total_carts'] ); $this->render_stat_card( __( 'Cart Conversion', 'airy-wishlist' ), $totals['conversion'] . '%' ); ?>

product_id; $product = wc_get_product( $product_id ); $name = $product ? $product->get_name() : sprintf( /* translators: %d: product ID */ __( 'Product #%d (deleted)', 'airy-wishlist' ), $product_id ); $edit_link = get_edit_post_link( $product_id ); $adds = (int) get_post_meta( $product_id, '_airy_wishlist_adds', true ); $carts = (int) get_post_meta( $product_id, '_airy_wishlist_carts', true ); $conv = $adds > 0 ? round( ( $carts / $adds ) * 100, 1 ) . '%' : '—'; ?>
cnt ); ?>