Skip to content

Commit a3307ef

Browse files
committed
ECE: fix add-to-cart issue for bookings (#3865)
* Use non-StoreAPI add-to-cart method for bookings
1 parent 467f544 commit a3307ef

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
= 9.2.0 - xxxx-xx-xx =
44
* Dev - Replaces part of the StoreAPI call code for the cart endpoints to use the newly introduced filter.
5+
* Fix - Switch booking products back to using non-StoreAPI add-to-cart methods.
56
* Dev - Add new E2E tests for Link express checkout.
67
* Add - Add Amazon Pay to block cart and block checkout.
78
* Fix - Remove intentional delay when displaying tax-related notice for express checkout, causing click event to time out.

client/api/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,20 @@ export default class WCStripeAPI {
574574
}
575575
}
576576

577+
/**
578+
* Empty the cart (legacy version, non-StoreAPI).
579+
*
580+
* @param {Object} params Parameters.
581+
* @param {number} params.bookingId Booking ID.
582+
* @return {Promise} Promise for the request to the server.
583+
*/
584+
expressCheckoutEmptyCartLegacy( { bookingId = null } ) {
585+
return this.request( getExpressCheckoutAjaxURL( 'clear_cart' ), {
586+
security: getExpressCheckoutData( 'nonce' )?.clear_cart,
587+
...( bookingId ? { booking_id: bookingId } : {} ),
588+
} );
589+
}
590+
577591
/**
578592
* Creates order based on Express Checkout ECE payment method.
579593
*

client/entrypoints/express-checkout/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ jQuery( function ( $ ) {
7979
* @todo Using the legacy endpoint (non-StoreAPI) and data format when variations are present.
8080
* StoreAPI will support this form correctly only after WC 9.7.0.
8181
* See https://github.com/woocommerce/woocommerce-gateway-stripe/pull/3780#issuecomment-2632051359
82+
*
83+
* @todo Using the legacy endpoint (non-StoreAPI) for booking products. Can be
84+
* removed once booking product flows have been fully migrated to StoreAPI.
8285
*/
83-
const useLegacyCartEndpoints = $( '.variations_form' ).length > 0;
86+
const useLegacyCartEndpoints =
87+
$( '.variations_form' ).length > 0 ||
88+
$( '.wc-bookings-booking-form' ).length > 0;
8489

8590
const wcStripeECE = {
8691
createButton: ( elements, options ) =>
@@ -782,7 +787,13 @@ jQuery( function ( $ ) {
782787
response.displayItems;
783788

784789
// Empty the cart to avoid having 2 products in the cart when payment request is not used.
785-
api.expressCheckoutEmptyCart( response.bookingId );
790+
if ( useLegacyCartEndpoints ) {
791+
api.expressCheckoutEmptyCartLegacy( {
792+
bookingId: response.bookingId,
793+
} );
794+
} else {
795+
api.expressCheckoutEmptyCart( response.bookingId );
796+
}
786797

787798
wcStripeECE.init();
788799

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
112112

113113
= 9.2.0 - xxxx-xx-xx =
114114
* Dev - Replaces part of the StoreAPI call code for the cart endpoints to use the newly introduced filter.
115+
* Fix - Switch booking products back to using non-StoreAPI add-to-cart methods.
115116
* Dev - Add new E2E tests for Link express checkout.
116117
* Add - Add Amazon Pay to block cart and block checkout.
117118
* Fix - Remove intentional delay when displaying tax-related notice for express checkout, causing click event to time out.

0 commit comments

Comments
 (0)