mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Detect logged in customer in checkout module
This commit is contained in:
parent
9157547993
commit
eba92e6b81
1 changed files with 19 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
import { GooglePayStorage } from '../Helper/GooglePayStorage';
|
||||
import { setPayerData } from '../../../../ppcp-button/resources/js/modules/Helper/PayerData';
|
||||
import {
|
||||
getWooCommerceCustomerDetails,
|
||||
setPayerData,
|
||||
} from '../../../../ppcp-button/resources/js/modules/Helper/PayerData';
|
||||
|
||||
const CHECKOUT_FORM_SELECTOR = 'form.woocommerce-checkout';
|
||||
|
||||
|
@ -49,16 +52,29 @@ export class CheckoutBootstrap {
|
|||
return;
|
||||
}
|
||||
|
||||
this.#populateCheckoutFields();
|
||||
}
|
||||
|
||||
#populateCheckoutFields() {
|
||||
const loggedInData = getWooCommerceCustomerDetails();
|
||||
|
||||
// If customer is logged in, we use the details from the customer profile.
|
||||
if ( loggedInData ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const billingData = this.#storage.getPayer();
|
||||
|
||||
if ( billingData ) {
|
||||
setPayerData( billingData );
|
||||
|
||||
this.checkoutForm.addEventListener( 'submit', this.onFormSubmit );
|
||||
this.checkoutForm.addEventListener( 'submit', () =>
|
||||
this.#onFormSubmit()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onFormSubmit() {
|
||||
#onFormSubmit() {
|
||||
this.#storage.clearPayer();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue