Skip to content

Commit

Permalink
Fix the incompatible data structure that causes JS exceptions when se…
Browse files Browse the repository at this point in the history
…nding checkout event tracking for issue #341.
  • Loading branch information
eason9487 committed Dec 26, 2023
1 parent 64e7dda commit 7d1a9ea
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions assets/js/src/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ 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 ),
coupon: storeCart.cartCoupons[ 0 ]?.code || '',
Expand Down

0 comments on commit 7d1a9ea

Please sign in to comment.