How to implement dynamic product pricing (% of cart total) without race conditions in Shopify?

I’m building a Shopify app that adds an “Order Protection” product to the cart with a price that should always be 4% of the cart subtotal (excluding the protection product itself).

Current Setup:

  • Protection product exists with handle order-protection

  • Product variant price is set to $0.00

  • I calculate 4% in the frontend and display it to customers

  • Multiple customers can checkout simultaneously

The Problem:

When I display the calculated fee (e.g., “$30 for a $750 cart”), it shows correctly in my UI. However, when the product is added to cart and appears in checkout, it still shows as “FREE” because the actual variant price is $0.

What I’ve Tried:

  1. Line item properties - These display as metadata but don’t change the price shown

  2. Updating variant price via Admin API - This creates race conditions when multiple customers order simultaneously (Customer A’s $4 fee gets overwritten by Customer B’s $8 fee)

What I Need:

A way to charge each customer 4% of their specific cart total without:

  • Race conditions from shared product pricing

  • Showing “FREE” in checkout

  • Requiring Shopify Plus (I’m on a standard plan)

Expected Behavior:

  • Customer A ($100 cart) sees and pays: Order Protection $4.00

  • Customer B ($200 cart) sees and pays: Order Protection $8.00

  • Both happening at the same time without conflicts

Question:

What’s the best approach to implement dynamic per-customer pricing for a single product in Shopify without race conditions? Is there a way to set line-item-specific prices, or do I need Shopify Functions (Plus only)?

One solution which does not require Plus is to set variant price to some small amount, like $0.1 but add a required number of those.
Say, your cart is worth $100 – you add 40 * $0.1 of protection product and end up with total of $104.

The drawback is that you’d need to hide quantity selector for this product and cart counter would be off.
But should be ok if you only offer this as the last step before checkout.

Another option is to create a separate variant for each order with required price.
This would look nice on the front-end but add a lot of variants.
However, with raised limit of 2000 variants per product it’s now easier and you can always reuse previously created variants/let them expire after some time…

Tried the first solution and working good, but unable to hide/change the number badge of the product in the checkout.

I guess you would not be able to hide it in checkout – also i believe it is not that necessary – customer can’t change anything, the total matches, probably nothing to worry about much…

Creating separate variants could be a better option still.
2000 variants with step of $0.1 would give you a $0.1 to $200 span which will cover
all cart amounts from $2.5 to $5000 (being 4%).
Would look great in Storefront/Checkout and wouldn’t clutter backend much.