mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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
|
@ -110,8 +110,12 @@ export const payerData = () => {
|
|||
* Updates the DOM with specific 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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -634,8 +634,8 @@ class GooglepayButton extends PaymentButton {
|
|||
|
||||
const propagatePayerDataToForm = () => {
|
||||
const raw = paymentData?.paymentMethodData?.info?.billingAddress;
|
||||
|
||||
const payer = {
|
||||
email_address: paymentData?.email,
|
||||
name: {
|
||||
given_name: raw.name.split( ' ' )[ 0 ], // Assuming first name is the first part
|
||||
surname: raw.name.split( ' ' ).slice( 1 ).join( ' ' ), // Assuming last name is the rest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue