Merge pull request #2429 from woocommerce/PCP-3385-can-not-pay-from-block-cart-and-block-checkout-when-shipping-callback-enabled-and-no-shipping-methods-defined

Can't pay from block pages when the shipping callback is enabled and no shipping methods defined (3385)
This commit is contained in:
Emili Castells 2024-08-22 10:51:11 +02:00 committed by GitHub
commit 8d0dd26f87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 12 deletions

View file

@ -227,7 +227,7 @@ const PayPalComponent = ( {
throw new Error( config.scriptData.labels.error.generic ); throw new Error( config.scriptData.labels.error.generic );
} }
if ( ! shouldHandleShippingInPayPal() ) { if ( ! shouldskipFinalConfirmation() ) {
location.href = getCheckoutRedirectUrl(); location.href = getCheckoutRedirectUrl();
} else { } else {
setGotoContinuationOnError( true ); setGotoContinuationOnError( true );
@ -318,7 +318,7 @@ const PayPalComponent = ( {
throw new Error( config.scriptData.labels.error.generic ); throw new Error( config.scriptData.labels.error.generic );
} }
if ( ! shouldHandleShippingInPayPal() ) { if ( ! shouldskipFinalConfirmation() ) {
location.href = getCheckoutRedirectUrl(); location.href = getCheckoutRedirectUrl();
} else { } else {
setGotoContinuationOnError( true ); setGotoContinuationOnError( true );
@ -364,16 +364,20 @@ const PayPalComponent = ( {
}; };
const shouldHandleShippingInPayPal = () => { const shouldHandleShippingInPayPal = () => {
if ( config.finalReviewEnabled ) { return shouldskipFinalConfirmation() && config.needShipping
return false;
}
return (
window.ppcpFundingSource !== 'venmo' ||
! config.scriptData.vaultingEnabled
);
}; };
const shouldskipFinalConfirmation = () => {
if ( config.finalReviewEnabled ) {
return false;
}
return (
window.ppcpFundingSource !== 'venmo' ||
! config.scriptData.vaultingEnabled
);
};
let handleShippingOptionsChange = null; let handleShippingOptionsChange = null;
let handleShippingAddressChange = null; let handleShippingAddressChange = null;
let handleSubscriptionShippingOptionsChange = null; let handleSubscriptionShippingOptionsChange = null;
@ -544,7 +548,7 @@ const PayPalComponent = ( {
if ( config.scriptData.continuation ) { if ( config.scriptData.continuation ) {
return true; return true;
} }
if ( shouldHandleShippingInPayPal() ) { if ( shouldskipFinalConfirmation() ) {
location.href = getCheckoutRedirectUrl(); location.href = getCheckoutRedirectUrl();
} }
return true; return true;

View file

@ -254,6 +254,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
), ),
), ),
'scriptData' => $script_data, 'scriptData' => $script_data,
'needShipping' => WC()->cart->needs_shipping(),
); );
} }

View file

@ -139,7 +139,7 @@ class Renderer {
}; };
// Check the condition and add the handler if needed // Check the condition and add the handler if needed
if ( this.defaultSettings.should_handle_shipping_in_paypal ) { if ( this.defaultSettings.should_handle_shipping_in_paypal && this.defaultSettings.needShipping ) {
options.onShippingOptionsChange = ( data, actions ) => { options.onShippingOptionsChange = ( data, actions ) => {
let shippingOptionsChange = let shippingOptionsChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled( ! this.isVenmoButtonClickedWhenVaultingIsEnabled(

View file

@ -1295,6 +1295,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'is_logged' => is_user_logged_in(), 'is_logged' => is_user_logged_in(),
), ),
'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(), 'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(),
'needShipping' => WC()->cart->needs_shipping(),
'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ), 'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ),
); );