254 || ! is_email( $email ) ) { throw new \InvalidArgumentException( I18n::t( 'Enter a valid order email address.' ) ); } $expected = Store::text( $data, 'expected_email' ); // The new address is part of the request: correcting a typo is a new request, not a repeat of the first one. Store::once( 'order-email:' . $id . ':' . $request . ':' . substr( hash( 'sha256', strtolower( $email ) ), 0, 16 ), static function () use ( $id, $expected, $email ) { return Store::lock( 'order-' . $id, static function () use ( $id, $expected, $email ) { $order = Orders::get( $id ); $previous = (string) $order->get_billing_email(); if ( ! hash_equals( $previous, $expected ) ) { throw new \RuntimeException( I18n::t( 'The order email changed elsewhere. Refresh the order and check it again.' ) ); } if ( $previous === $email ) { return array( 'changed'=>false ); } $order->set_billing_email( $email ); $order->save(); clean_post_cache( $id ); Store::audit( 'order', $id, 'order_email_updated' ); return array( 'changed'=>true ); } ); } ); return Orders::summary( Orders::get( $id ) ); } }