• Resolved tictubso

    (@tictubso)


    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_calculation suffix 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

    1. Open any product page (simple or variable) and set quantity to 3.
    2. Click “Add to cart”. The cart correctly contains 3.
    3. Click “View cart”.
    4. 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_calculation suffix, but those weren’t duplicated.

    When the duplication happened, we could see a ?wc-ajax=wc_stripe_frontend_request&path=/wc-stripe/v1/cart/calculation request. 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_calculation items persist in the session after the calculation request? I’m happy to provide more details or test a patch.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Clayton R

    (@mrclayton)

    Hi @tictubso

    Thank you for contacting Payment Plugins. The Stripe plugin is designed to not persist the cart calculation by removing the filters that allow the cart data to be saved in the database. Here is a link to the cart calculation route: https://plugins.trac.wordpress.org/browser/woo-stripe-payment/tags/4.0.16/src/Rest/Routes/V1/CartCalculation.php#L51

    Do you have any 3rd party plugins that touch the WooCommerce cart? It seems like on your site the cart is being persisted prior to the woocommerce_persistent_cart_enabled filter being called which is what WooCommerce uses to determine if the cart can be stored in the database or not.

    At the end of the cart calculation route the item is removed from the cart which you can see in the finally block of code. So something is triggering the cart to persist during the cart calculation it seems.

    Kind Regards

    Plugin Author Clayton R

    (@mrclayton)

    Hi @tictubso

    Since we can’t predict when 3rd party plugins or custom code might persist the cart contents during the calculation, we’re going to add some additional code similar to your custom filter that removes any orphaned cart calculation entries when the cart session is loaded.

    If you would like to test that before we release please reach out via the support widget in the Stripe plugin settings.

    Thank you for bringing this to our attention.

    Kind Regards

    Plugin Author Clayton R

    (@mrclayton)

    Hi @tictubso

    Following up to confirm you saw these responses.

    Kind Regards

    Thread Starter tictubso

    (@tictubso)

    Yes I saw it and I’m not sure what to do – I had a look through the plugins and snippets and there was nothing obvious. Maybe the PixelYourSite plugin but it’s a heavily used & popular plugin so without spending hours trying to trace it I’m really not sure

    Plugin Author Clayton R

    (@mrclayton)

    @tictubso If you look at my previous responses I confirmed we updated the plugin to address this so there isn’t anything for you to do.

    The plugin release notes also reference it.

    https://paymentplugins.com/documentation/stripe/releases/4.0.18/#cart-quantities-could-intermittently-double

    Thread Starter tictubso

    (@tictubso)

    Oh I missed it, thank you so much. Amazing service.

    Plugin Author Clayton R

    (@mrclayton)

    @tictubso Thank you for the great review.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.