Quantity doubles on cart page
-
Hi team,
We’re seeing cart quantities double on our store, and we’ve traced it to cart items left behind with a
_wc_stripe_calculationsuffix on their cart item key.Environment
- Payment Plugins for Stripe WooCommerce 4.0.16
- WooCommerce 11.1.2
- Flatsome 3.20.5
- Apple Pay and Google Pay enabled
Steps to reproduce
- Open any product page (simple or variable) and set quantity to 3.
- Click “Add to cart”. The cart correctly contains 3.
- Click “View cart”.
- The cart now shows two lines for the same product, 3 each (6 total), and the subtotal reflects 6.
It doesn’t happen every time, but it’s easy to reproduce.
What we found
The cart item keys on the cart page show the duplicate is a leftover from the plugin’s calculation process:
cart[f0e2c54e09e81ac2fde8ec4c1891264f][qty] -> 3 (the real add) cart[f0e2c54e09e81ac2fde8ec4c1891264f_wc_stripe_calculation][qty] -> 3 (the duplicate)Other items already in the cart also ended up re-keyed with the
_wc_stripe_calculationsuffix, but those weren’t duplicated.When the duplication happened, we could see a
?wc-ajax=wc_stripe_frontend_request&path=/wc-stripe/v1/cart/calculationrequest. It looks like the temporary calculation cart isn’t being fully cleaned up or restored, and the suffixed items persist in the customer’s real session cart.Disabling the Mini-cart location for Apple Pay and Google Pay did not fix it. We suspect the cart-page express buttons trigger the same calculation request.
Temporary workaround
We’re currently running this snippet, which removes the leaked items (or re-keys them if the original is missing) when the cart loads from the session. It has resolved the issue for us:
php
add_action( 'woocommerce_cart_loaded_from_session', 'fix_stripe_calculation_cart_items', 99 ); function fix_stripe_calculation_cart_items( $cart ) { if ( isset( $_GET['wc-ajax'] ) && 'wc_stripe_frontend_request' === $_GET['wc-ajax'] ) { return; } $suffix = '_wc_stripe_calculation'; $len = strlen( $suffix ); $contents = $cart->get_cart_contents(); $changed = false; foreach ( $contents as $key => $item ) { if ( substr( $key, -$len ) !== $suffix ) { continue; } $original_key = substr( $key, 0, -$len ); if ( isset( $contents[ $original_key ] ) ) { unset( $contents[ $key ] ); } else { $item['key'] = $original_key; $contents[ $original_key ] = $item; unset( $contents[ $key ] ); } $changed = true; } if ( $changed ) { $cart->set_cart_contents( $contents ); $cart->calculate_totals(); } }Could you look into why the
_wc_stripe_calculationitems persist in the session after the calculation request? I’m happy to provide more details or test a patch.Thanks
You must be logged in to reply to this topic.