Setting price of product as a % of cart

Scott_Austin
Shopify Expert
23 0 3

I'm looking for a more elegant solution to set the price of a product based on a percentage of cart $ size.

Here's what I have working so far.  In this Shopify Plus store, https://www.bullets2bandages.org/cart/add?id=19593494467, we have a Rush upsell in the cart.  The upsell snippet in the cart adds the Rush Order Upgrade product to the cart.  Then the cart script sets the price for the Rush product to be 20% of the cart.  The script for setting the Rush price is:

# Rush Order
Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  next unless product.id == 12097978371
  subtotal_without_item = Input.cart.subtotal_price_was - line_item.line_price
  line_item.change_line_price(subtotal_without_item * 0.2, message: "Rush Order fee is 20%")
end
# end Rush Order

This works but not as elegantly as I'd like.  Here are my issues:

  • I believe I can only REDUCE the price of the product with scripts.  So I need to set the price of the product to be very high and exceed 20% (the price of Rush) of the largest cart size that will use the service.  I've got it set at $200 which still isn't high enough yet.
  • The reason I haven't made the price even higher is that if one adds Rush to $20 cart, the Rush price gets properly set at $4 ( 20% * $20 ).  But it shows a Total savings in the cart of $196 as that's how much the Rush upgrade was reduced from the listed $200.  Showing a huge discount as the customer is paying for an upgrade is a bit silly looking.

So, my question is does anyone know of a more elegant solution?  Ideas include:

  • For example, is there a way to INCREASE the price of the RUSH product in the cart with scripts.
  • Is there a way to not include the RUSH discount in the Total savings?

Thanks for any help.

Scott Austin, Shopify Expert https://experts.shopify.com/productgraph
0 Likes