Skip to content

Commit

Permalink
Check that cart total is not zero before rendering express checkout (#…
Browse files Browse the repository at this point in the history
…9691)

Co-authored-by: Guilherme Pressutto <[email protected]>
  • Loading branch information
dmvrtx and gpressutto5 authored Nov 14, 2024
1 parent 2d56a1e commit 47739ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
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

0 comments on commit 47739ad

Please sign in to comment.