From eba92e6b81c48b1745d4ffbf68623ea878f976e1 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 21 Aug 2024 13:52:11 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Detect=20logged=20in=20customer=20i?=
=?UTF-8?q?n=20checkout=20module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../js/ContextBootstrap/CheckoutBootstrap.js | 22 ++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-googlepay/resources/js/ContextBootstrap/CheckoutBootstrap.js b/modules/ppcp-googlepay/resources/js/ContextBootstrap/CheckoutBootstrap.js
index b5e0c1a48..d913b0b3f 100644
--- a/modules/ppcp-googlepay/resources/js/ContextBootstrap/CheckoutBootstrap.js
+++ b/modules/ppcp-googlepay/resources/js/ContextBootstrap/CheckoutBootstrap.js
@@ -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();
}
}