Commit f01defc32f3 for woocommerce

commit f01defc32f38351ead500d8a5a74464a92cf70f4
Author: Kadir Er <3rkadir@gmail.com>
Date:   Thu Dec 3 10:02:52 2026 +0300

    Replace deprecated SQL_CALC_FOUND_ROWS in low stock report (#71361)

    * Replace deprecated SQL_CALC_FOUND_ROWS in low stock report

    Refactor SQL queries to use prepared statements for better security and performance.

    * Update SQL query to count low stock items

    * Fix percent escaping in low stock count query

    * Refactor max_items calculation in low stock report

    * Update plugins/woocommerce/includes/admin/reports/class-wc-report-low-in-stock.php

    Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>

    * Add changefile(s) from automation for the following project(s): woocommerce

    * Refactor SQL queries for low stock report guard add

    * Refactor SQL queries to ignore PHPCS warnings

    Updated SQL preparation comments to ignore PHPCS warnings.

    ---------

    Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/71361-patch-1 b/plugins/woocommerce/changelog/71361-patch-1
new file mode 100644
index 00000000000..7131fe7695b
--- /dev/null
+++ b/plugins/woocommerce/changelog/71361-patch-1
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Avoid SQL syntax deprecated in MySQL 8 when counting products in the Low in stock report.
diff --git a/plugins/woocommerce/includes/admin/reports/class-wc-report-low-in-stock.php b/plugins/woocommerce/includes/admin/reports/class-wc-report-low-in-stock.php
index ed69b074bd6..d51dffb798b 100644
--- a/plugins/woocommerce/includes/admin/reports/class-wc-report-low-in-stock.php
+++ b/plugins/woocommerce/includes/admin/reports/class-wc-report-low-in-stock.php
@@ -55,7 +55,28 @@ class WC_Report_Low_In_Stock extends WC_Report_Stock {
 			)
 		);

-		$this->items     = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS posts.ID as id, posts.post_parent as parent {$query_from} ORDER BY posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
-		$this->max_items = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
+		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+		$items_sql = $wpdb->prepare(
+			"SELECT posts.ID as id, posts.post_parent as parent {$query_from}
+			ORDER BY posts.post_title DESC
+			LIMIT %d, %d;",
+			( $current_page - 1 ) * $per_page,
+			$per_page
+		);
+
+		$count_sql = $wpdb->prepare(
+			"SELECT COUNT(%d) FROM (
+				SELECT posts.ID as id, posts.post_parent as parent {$query_from}
+			) AS low_stock_results",
+			1
+		);
+		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+
+		if ( ! $items_sql || ! $count_sql ) {
+			return;
+		}
+
+		$this->items     = $wpdb->get_results( $items_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
+		$this->max_items = $wpdb->get_var( $count_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
 	}
 }