From f52117c196de1cba1ef3c3e89c9991d6b1e4b538 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 8 Aug 2024 15:38:08 +0200 Subject: [PATCH] Apple Pay: Fix shipping method switching inside of the Apple Pay modal in Classic Checkout --- .../resources/js/ApplepayButton.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-applepay/resources/js/ApplepayButton.js b/modules/ppcp-applepay/resources/js/ApplepayButton.js index 2bcac16fc..281a08ae1 100644 --- a/modules/ppcp-applepay/resources/js/ApplepayButton.js +++ b/modules/ppcp-applepay/resources/js/ApplepayButton.js @@ -644,10 +644,12 @@ class ApplepayButton { return { action: 'ppcp_update_shipping_method', shipping_method: event.shippingMethod, - simplified_contact: - this.updatedContactInfo || - this.initialPaymentRequest.shippingContact || - this.initialPaymentRequest.billingContact, + simplified_contact: this.hasValidContactInfo( + this.updatedContactInfo + ) + ? this.updatedContactInfo + : this.initialPaymentRequest?.shippingContact ?? + this.initialPaymentRequest?.billingContact, product_id, products: JSON.stringify( this.products ), caller_page: 'productDetail', @@ -662,10 +664,12 @@ class ApplepayButton { return { action: 'ppcp_update_shipping_method', shipping_method: event.shippingMethod, - simplified_contact: - this.updatedContactInfo || - this.initialPaymentRequest.shippingContact || - this.initialPaymentRequest.billingContact, + simplified_contact: this.hasValidContactInfo( + this.updatedContactInfo + ) + ? this.updatedContactInfo + : this.initialPaymentRequest?.shippingContact ?? + this.initialPaymentRequest?.billingContact, caller_page: 'cart', 'woocommerce-process-checkout-nonce': this.nonce, }; @@ -948,6 +952,12 @@ class ApplepayButton { return btoa( utf8Str ); } + + hasValidContactInfo( value ) { + return Array.isArray( value ) + ? value.length > 0 + : Object.keys( value || {} ).length > 0; + } } export default ApplepayButton;