diff --git a/assets/js/src/tracking.js b/assets/js/src/tracking.js index 63329121..56e0a7ec 100644 --- a/assets/js/src/tracking.js +++ b/assets/js/src/tracking.js @@ -104,8 +104,19 @@ export const trackCheckoutStep = return; } + // compatibility-code "WC >= 8.1" -- The data structure of `storeCart` was (accidentally) changed. + if ( ! storeCart.hasOwnProperty( 'cartTotals' ) ) { + storeCart = { + cartCoupons: storeCart.coupons, + cartItems: storeCart.items, + cartTotals: storeCart.totals, + }; + } + trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', { - items: storeCart.cartItems.map( getProductFieldObject ), + items: storeCart.cartItems.map( ( item ) => + getProductFieldObject( item, item.quantity ) + ), coupon: storeCart.cartCoupons[ 0 ]?.code || '', currency: storeCart.cartTotals.currency_code, value: formatPrice(