Skip to content

Commit

Permalink
Fix block checkout page reloading on form errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrosilva-pt committed Dec 13, 2023
1 parent be28f81 commit 2f0f0a7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/ppcp-blocks/resources/js/checkout-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const PayPalComponent = ({
const {responseTypes} = emitResponse;

const [paypalOrder, setPaypalOrder] = useState(null);
const [gotoContinuation, setGotoContinuation] = useState(false);

const methodId = fundingSource ? `${config.id}-${fundingSource}` : config.id;

Expand Down Expand Up @@ -152,6 +153,7 @@ const PayPalComponent = ({
if (config.finalReviewEnabled) {
location.href = getCheckoutRedirectUrl();
} else {
setGotoContinuation(true);
onSubmit();
}
} catch (err) {
Expand All @@ -170,15 +172,15 @@ const PayPalComponent = ({
if (config.scriptData.continuation) {
return true;
}
if (wp.data.select('wc/store/validation').hasValidationErrors()) {
if (gotoContinuation && wp.data.select('wc/store/validation').hasValidationErrors()) {
location.href = getCheckoutRedirectUrl();
return { type: responseTypes.ERROR };
}

return true;
});
return unsubscribe;
}, [onCheckoutValidation] );
}, [onCheckoutValidation, gotoContinuation] );

const handleClick = (data, actions) => {
if (isEditing) {
Expand Down

0 comments on commit 2f0f0a7

Please sign in to comment.