Add optional chaining to address properties

This commit is contained in:
Himad M 2025-07-23 16:32:22 -04:00
parent a8dfe57165
commit 0385aad301
No known key found for this signature in database
GPG key ID: 5FC769E9888A7B98

View file

@ -27,7 +27,7 @@ export const paypalAddressToWc = ( address ) => {
admin_area_2: 'city',
postal_code: 'postcode',
};
if ( address.city ) {
if ( address?.city ) {
// address not from API, such as onShippingChange
map = {
country_code: 'country',
@ -38,7 +38,7 @@ export const paypalAddressToWc = ( address ) => {
}
const result = {};
Object.entries( map ).forEach( ( [ paypalKey, wcKey ] ) => {
if ( address[ paypalKey ] ) {
if ( address?.[ paypalKey ] ) {
result[ wcKey ] = address[ paypalKey ];
}
} );