mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
✨ Option to only set missing billing details
This commit is contained in:
parent
63e9c8bf27
commit
c007d7909c
2 changed files with 8 additions and 4 deletions
|
@ -109,9 +109,13 @@ export const payerData = () => {
|
|||
/**
|
||||
* Updates the DOM with specific payer details.
|
||||
*
|
||||
* @param {PayerDetails} newData - New payer details.
|
||||
* @param {PayerDetails} newData - New payer details.
|
||||
* @param {boolean} [overwriteExisting=false] - If set to true, all provided values will replace existing details. If false, or omitted, only undefined fields are updated.
|
||||
*/
|
||||
export const setPayerData = ( newData ) => {
|
||||
export const setPayerData = ( newData, overwriteExisting = false ) => {
|
||||
// TODO: Check if we can add some kind of "filter" to allow customization of the data.
|
||||
// Or add JS flags like "onlyUpdateMissing".
|
||||
|
||||
const setValue = ( path, field, value ) => {
|
||||
if ( null === value || undefined === value || ! field ) {
|
||||
return;
|
||||
|
@ -121,7 +125,7 @@ export const setPayerData = ( newData ) => {
|
|||
value = value.phone_number?.national_number;
|
||||
}
|
||||
|
||||
if ( field.value !== value ) {
|
||||
if ( overwriteExisting || ! field.value ) {
|
||||
field.value = value;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue