Handle shipping address/methods update

This commit is contained in:
Alex P 2023-04-27 09:06:38 +03:00
parent f396870610
commit efb86acb1f
No known key found for this signature in database
GPG key ID: 54487A734A204D71
6 changed files with 204 additions and 5 deletions

View file

@ -19,7 +19,7 @@ export const splitFullName = (fullName) => {
* @returns {Object}
*/
export const paypalAddressToWc = (address) => {
const map = {
let map = {
country_code: 'country',
address_line_1: 'address_1',
address_line_2: 'address_2',
@ -27,6 +27,14 @@ export const paypalAddressToWc = (address) => {
admin_area_2: 'city',
postal_code: 'postcode',
};
if (address.city) { // address not from API, such as onShippingChange
map = {
country_code: 'country',
state: 'state',
city: 'city',
postal_code: 'postcode',
};
}
const result = {};
Object.entries(map).forEach(([paypalKey, wcKey]) => {
if (address[paypalKey]) {