Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that cart total is not zero before rendering express checkout #9691

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Prevent express checkout from being used if cart total becomes zero after coupon usage.
31 changes: 20 additions & 11 deletions client/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ jQuery( ( $ ) => {
order,
} = wcpayECEPayForOrderParams;

if ( total === 0 ) {
wcpayECE.hide();
return;
}

wcpayECE.startExpressCheckoutElement( {
mode: 'payment',
total,
Expand Down Expand Up @@ -619,17 +624,21 @@ jQuery( ( $ ) => {
// If this is the cart or checkout page, we need to request the
// cart details.
api.expressCheckoutECEGetCartDetails().then( ( cart ) => {
wcpayECE.startExpressCheckoutElement( {
mode: 'payment',
total: cart.total.amount,
currency: getExpressCheckoutData( 'checkout' )
?.currency_code,
requestShipping: cart.needs_shipping,
requestPhone:
getExpressCheckoutData( 'checkout' )
?.needs_payer_phone ?? false,
displayItems: cart.displayItems,
} );
if ( cart.total.amount === 0 ) {
wcpayECE.hide();
} else {
wcpayECE.startExpressCheckoutElement( {
mode: 'payment',
total: cart.total.amount,
currency: getExpressCheckoutData( 'checkout' )
?.currency_code,
requestShipping: cart.needs_shipping,
requestPhone:
getExpressCheckoutData( 'checkout' )
?.needs_payer_phone ?? false,
displayItems: cart.displayItems,
} );
}
} );
}

Expand Down
Loading