diff --git a/plugins/woocommerce/changelog/fix-always-set-address-indexes b/plugins/woocommerce/changelog/fix-always-set-address-indexes new file mode 100644 index 00000000000..3294b511960 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-always-set-address-indexes @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Always generate address metadata indexes for HPOS orders. diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index 71d66846787..b8baed86f82 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -2580,8 +2580,10 @@ FROM $order_meta_table private function update_address_index_meta( $order, $changes ) { // If address changed, store concatenated version to make searches faster. foreach ( array( 'billing', 'shipping' ) as $address_type ) { - if ( isset( $changes[ $address_type ] ) ) { - $order->update_meta_data( "_{$address_type}_address_index", implode( ' ', $order->get_address( $address_type ) ) ); + $index_meta_key = "_{$address_type}_address_index"; + + if ( isset( $changes[ $address_type ] ) || ( is_a( $order, 'WC_Order' ) && empty( $order->get_meta( $index_meta_key ) ) ) ) { + $order->update_meta_data( $index_meta_key, implode( ' ', $order->get_address( $address_type ) ) ); } } }