From b5fa8972d07924faf6e74e37c95d4c2571ee374d Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 15 Jul 2024 19:18:51 +0400 Subject: [PATCH 1/5] Store the WC STORE API endpoint in constant --- modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php b/modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php index f9322700d..be196fa03 100644 --- a/modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php +++ b/modules/ppcp-blocks/src/Endpoint/UpdateShippingEndpoint.php @@ -22,7 +22,8 @@ * Class UpdateShippingEndpoint */ class UpdateShippingEndpoint implements EndpointInterface { - const ENDPOINT = 'ppc-update-shipping'; + const ENDPOINT = 'ppc-update-shipping'; + const WC_STORE_API_ENDPOINT = '/wp-json/wc/store/cart/'; /** * The Request Data Helper. From c5fd3a6cea5bed5b883dc866c79b604e78a5d089 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 15 Jul 2024 19:19:32 +0400 Subject: [PATCH 2/5] Use the WC STORE API endpoint constant and the `home_url` --- modules/ppcp-button/src/Assets/SmartButton.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 6b92a9084..ceaa05ffa 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1165,11 +1165,11 @@ public function script_data(): array { ), 'update_customer_shipping' => array( 'shipping_options' => array( - 'endpoint' => '/wp-json/wc/store/cart/select-shipping-rate', + 'endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'select-shipping-rate'), ), 'shipping_address' => array( - 'cart_endpoint' => '/wp-json/wc/store/cart/', - 'update_customer_endpoint' => '/wp-json/wc/store/v1/cart/update-customer/', + 'cart_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT ), + 'update_customer_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'update-customer'), ), 'wp_rest_nonce' => wp_create_nonce( 'wc_store_api' ), 'update_shipping_method' => \WC_AJAX::get_endpoint( 'update_shipping_method' ), From f9aa2b565d3eb70b0449fc7c7e792d4d2836a1f2 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 15 Jul 2024 19:20:24 +0400 Subject: [PATCH 3/5] Return the callback to fix the shipping options update process --- .../ppcp-button/resources/js/modules/Renderer/Renderer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js b/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js index b70342dbf..448432e3c 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js @@ -141,6 +141,7 @@ class Renderer { // Check the condition and add the handler if needed if ( this.defaultSettings.should_handle_shipping_in_paypal ) { options.onShippingOptionsChange = ( data, actions ) => { + let shippingOptionsChange = ! this.isVenmoButtonClickedWhenVaultingIsEnabled( venmoButtonClicked ) @@ -150,8 +151,11 @@ class Renderer { this.defaultSettings ) : null; + + return shippingOptionsChange }; options.onShippingAddressChange = ( data, actions ) => { + let shippingAddressChange = ! this.isVenmoButtonClickedWhenVaultingIsEnabled( venmoButtonClicked ) @@ -161,6 +165,8 @@ class Renderer { this.defaultSettings ) : null; + + return shippingAddressChange }; } From f643f9e1d7f902a10baeda2dc585a43ef8de1ecb Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 15 Jul 2024 19:20:35 +0400 Subject: [PATCH 4/5] Return the callback to fix the shipping options update process --- modules/ppcp-blocks/resources/js/checkout-block.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-blocks/resources/js/checkout-block.js b/modules/ppcp-blocks/resources/js/checkout-block.js index 6df1a99f8..bf36dcb65 100644 --- a/modules/ppcp-blocks/resources/js/checkout-block.js +++ b/modules/ppcp-blocks/resources/js/checkout-block.js @@ -606,9 +606,11 @@ const PayPalComponent = ( { } return ( data, actions ) => { - shouldHandleShippingInPayPal() + let shippingAddressChange = shouldHandleShippingInPayPal() ? handleShippingAddressChange( data, actions ) : null; + + return shippingAddressChange; }; }; From 2f0b01ebcb2aa9c0b7ec4a8854201acc63176ff1 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 15 Jul 2024 19:38:10 +0400 Subject: [PATCH 5/5] Fix the coding styles --- modules/ppcp-button/src/Assets/SmartButton.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index ceaa05ffa..4b309818e 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1165,11 +1165,11 @@ public function script_data(): array { ), 'update_customer_shipping' => array( 'shipping_options' => array( - 'endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'select-shipping-rate'), + 'endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'select-shipping-rate' ), ), 'shipping_address' => array( 'cart_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT ), - 'update_customer_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'update-customer'), + 'update_customer_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'update-customer' ), ), 'wp_rest_nonce' => wp_create_nonce( 'wc_store_api' ), 'update_shipping_method' => \WC_AJAX::get_endpoint( 'update_shipping_method' ),