Commit f00f2294194 for woocommerce
commit f00f22941945c6670d9803eb287d8c541fca52b2
Author: Anuj Singh <80690679+Anuj-Rathore24@users.noreply.github.com>
Date: Tue Jun 9 18:27:07 2026 +0530
Fix: wc_update_10802 throws DB errors on sites without HPOS enabled (#65536)
Fix: skip wc_orders_meta index restore if table doesn't exist
diff --git a/plugins/woocommerce/changelog/fix-wc-update-10802-missing-orders-meta-table-check b/plugins/woocommerce/changelog/fix-wc-update-10802-missing-orders-meta-table-check
new file mode 100644
index 00000000000..0bb41deb3d5
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wc-update-10802-missing-orders-meta-table-check
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix fatal DB errors during upgrade on sites where HPOS was never enabled by adding a table existence check before attempting to restore the meta_key_value index on wp_wc_orders_meta.
diff --git a/plugins/woocommerce/includes/wc-update-functions.php b/plugins/woocommerce/includes/wc-update-functions.php
index 09fab2d9277..677adb01294 100644
--- a/plugins/woocommerce/includes/wc-update-functions.php
+++ b/plugins/woocommerce/includes/wc-update-functions.php
@@ -3494,6 +3494,11 @@ function wc_update_10802_restore_orders_meta_key_value_index(): void {
$table_name = $wpdb->prefix . 'wc_orders_meta';
$index_name = 'meta_key_value';
+ // Table only exists on sites with HPOS enabled. Skip if absent.
+ if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) !== $table_name ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
+ return;
+ }
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
$columns = $wpdb->get_results(
$wpdb->prepare(