Make sure orders are always saved with addresses indexes set (#40332)

* Make sure orders are saved with addresses indexes set.

* Add changelog
This commit is contained in:
Jorge A. Torres 2023-09-22 00:44:22 +01:00 committed by GitHub
parent 3544ef300f
commit f446315f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Always generate address metadata indexes for HPOS orders.

View File

@ -2580,8 +2580,10 @@ FROM $order_meta_table
private function update_address_index_meta( $order, $changes ) { private function update_address_index_meta( $order, $changes ) {
// If address changed, store concatenated version to make searches faster. // If address changed, store concatenated version to make searches faster.
foreach ( array( 'billing', 'shipping' ) as $address_type ) { foreach ( array( 'billing', 'shipping' ) as $address_type ) {
if ( isset( $changes[ $address_type ] ) ) { $index_meta_key = "_{$address_type}_address_index";
$order->update_meta_data( "_{$address_type}_address_index", implode( ' ', $order->get_address( $address_type ) ) );
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 ) ) );
} }
} }
} }