Commit 52041c31c00 for woocommerce
commit 52041c31c00c7809478105ae9a48d3a5842f400f
Author: Kadir Er <3rkadir@gmail.com>
Date: Thu Dec 3 16:04:38 2026 +0300
Replace deprecated SQL_CALC_FOUND_ROWS in out of stock report (#71704)
* Replace deprecated SQL_CALC_FOUND_ROWS in out of stock report
* Fix deprecated SQL_CALC_FOUND_ROWS in out of stock report
Avoid deprecated SQL_CALC_FOUND_ROWS usage in the Out of stock report.
* Fix deprecated SQL_CALC_FOUND_ROWS in report
Avoid deprecated SQL_CALC_FOUND_ROWS usage in the Out of stock report.
* Refactor out of stock report query logic
* Update SQL syntax for out of stock report
* Update out of stock report query to use stock quantity
* Refactor out of stock report class and methods
* Refactor SQL query preparation in out-of-stock report
diff --git a/plugins/woocommerce/changelog/fix-out-of-stock-report-count-query b/plugins/woocommerce/changelog/fix-out-of-stock-report-count-query
new file mode 100644
index 00000000000..fc9bfc40ed7
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-out-of-stock-report-count-query
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Avoid SQL syntax deprecated in MySQL 8 when counting products in the Out of stock report.
diff --git a/plugins/woocommerce/includes/admin/reports/class-wc-report-out-of-stock.php b/plugins/woocommerce/includes/admin/reports/class-wc-report-out-of-stock.php
index 9eb594ad9a0..a7b3ce6eac0 100644
--- a/plugins/woocommerce/includes/admin/reports/class-wc-report-out-of-stock.php
+++ b/plugins/woocommerce/includes/admin/reports/class-wc-report-out-of-stock.php
@@ -27,7 +27,7 @@ class WC_Report_Out_Of_Stock extends WC_Report_Stock {
* Get Products matching stock criteria.
*
* @param int $current_page Current page number.
- * @param int $per_page How many results to show per page.
+ * @param int $per_page How many results to show per page.
*/
public function get_items( $current_page, $per_page ) {
global $wpdb;
@@ -37,6 +37,7 @@ class WC_Report_Out_Of_Stock extends WC_Report_Stock {
$stock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
+ // Get products using criteria.
$query_from = apply_filters(
'woocommerce_report_out_of_stock_query_from',
$wpdb->prepare(
@@ -52,7 +53,23 @@ class WC_Report_Out_Of_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 out_of_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
}
}