Dynamic Pricing in the Cart of a product Variant

Shopify Partner
2 0 1

We are a Insurance Company and are building a Shopify app, that adds a Insurance product to all the CARTS of the merchant who installs our Shopify APP (which is not public yet) .


The problem is we insure the product as a Percentage of the Cart Value , so a 100$ cart will add 2$ insurance , which a 200$ will add 4$ insurance.  We have added a Fixed insurance product with 0.01$ but we are not able to change its price . We can change quantity, but we don;t want to , as cart number goes crazy , if the some insures a high value item, our product quantity shows 100,200,450, etc big numbers and to customer it looks lot of products are added, while only 1 product is added.

We are using Shopify Ajax API


but not able to update the Product price.

Any help would be greately appreciated.


1 Like
Shopify Partner
1840 177 709


Been thinking about this one for a while - it sure is an interesting challenge and valid requirement.

Unfortunately, no matter how you slice it, I don't think you will be able to implement this with your current requirements and most definetely not using the AJAX API.

To begin with, the AJAX API is a simple wrapper allowing you to programmatically interact with a cart and predating the JS Buy SDK or Storefront API. However, what you want to do is add items with dynamic pricing and since you cannot add anything to a cart that isn't a product variant, you'd need to have an actual product you are adding.

Which brings us to the issue that product prices arent dynamic least of all calculated based on total cart value. So what are your options? First and foremost, you will need to create an app in order to get access to Admin API for creating products and other actions that go beyond what's available in AJAX or Storefront API.

  1. Creating ad-hoc insurance product variants based on cart totals
  2. Creating an insurance variant for each product that marks up the base cost by the percentage you need
  3. Use draft orders as that allows custom products

Each of the above have its own pitfalls / limitations. Let's go through them in same order as above

  1. Say you created an insurance product called "Two Percent Insurance", mark it as a digital product, no inventory etc etc as you will, and now you have the possibility to have up to 100 variants. However, these variants would simply be a pool that you use to update it's price when a customer adds the Two Percent Insurance item to their cart.
    Super messy, no backlog in order history of insurance value for specific past order as that may have been overwritten since, terrible scalability considering you have a pool of 100 variants - if your storefront has more than 100 "cart sessions with insurance" you're bang out of luck. Sumarry: NO GO!
    p.s. you could simply create products for the insurance value instead of variants which would solve the 100's limit but sweet lord would that create a mess in the product catalog and would still not scale well because of API limits. So another NO.
  2. Say you have a product such as Sweet Espresso Machine which comes with a color option i.e. variants red, blue, and stainless. Now you could programatically create an insurance option where the price is marked up by 2%.
    Pros: Scales well, doesn't abuse Shopify
    Cons: Doesn't scale well for products that have a lot of options i.e. already use up their max 100 variants limit. Requires the cart to handle logic wherein it takes all line items and if a customer wishes to insure the entire cart, loops these line items and picks the coresponding equivalent variant with insurance option
    Wtf: Why did I mention the Sweet Espresso Machine? No idea, just love coffee ;-)
  3. Draft orders have this neat ability to simply add custom line items of whatever, need not be a product variant. Well that'd be awesome, but it also scales meh as you're bound to Admin API limits for something that's on the public storefront - not cool and thus a NO GO! It's great for taking phone orders or wholesalers where order frequency / volumes are kind of limited.

Ultimately, none of these are ideal, complete or effective in my opinion. So what I usually recommend in that case is to reconsider your requirements.

Of course, maybe someone else can come up with more effective suggestions?

Best wishes!

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
1 Like
Shopify Partner
2 0 1



Thanks for the answer,  but so far no solution , what I know.


What I am doing is I am creating a product of insurance with 0.01 $ value and whatever percentage I get based on the cart Value , I am multiplying that with that value and getting the Number of Products I need to add to the cart for that 1 cent Insurance . This way I am able o get the Insurance percentage added to the CART Dynamically by playing with the Quantity of the insurance product.


The challenge is for a user , he purchase a product (leyts say 200$) , now we added another product of insurance for a price which is lest say 2% only , but it shows as 0.01 x 400 products of 1 cent each, so that I achivee 4$ as the percentage .  Very high possibility that th user gets confused that he has 401 projducts now while he added only 1 .


Any solutions ? You recommend.




Shopify Partner
8 0 0

Hi Udaantech,


Could you please update whether you have found a suitable solution to handle your dynamic pricing?


Thanks !

Shopify Partner
2 0 0

Shops with such requirements should (at least if you ask me and if it all possible) not be made with Shopify.

As far as I know, there is no way to dynamically set a price for product.

Don't misunderstand me, Shopify is awesome, but it's not a fit-all shop for every type of web-shop / merchant.