Product price adjustment based on a formula and on customer drop down input option

Topic summary

A user wants to implement dynamic pricing for custom books based on customer-selected page counts (30-200 pages). The goal is to calculate prices using the formula: base price + (price per page × (selected pages - 30)), avoiding the creation of 170+ product variants.

Proposed Solution:

  • Add a dropdown menu for page selection using line item properties
  • Use JavaScript to calculate prices dynamically
  • Pass selected values to cart via line item properties

Implementation Challenge:
The original poster has limited JavaScript knowledge and is unsure how to add the dropdown, as their current product options don’t support this functionality (screenshot provided).

Alternative Approach:
Another contributor suggests this requires Shopify Plus and a cart transform API to modify prices dynamically. For non-Plus stores, this solution may not be feasible.

Status: The discussion remains open with technical implementation details pending, and uncertainty about whether the store’s Shopify plan supports the required functionality.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hello,

Basically trying to add an option in the product where customers can choose the number of pages desired in their book for printing. then based on that input the price will be adjusted. If the drop down suggests number of pages ranging from 30 to 200, and the customer chooses 70 then the formula would adjust the price to : base price of 30 pages+ (price per page)*(70-30).Otherwise, I believe that creating different variants for each number of pages would be impractical as I will have at lease 170 variants per product, which is too much work and not the best way to do it.

Thanks

1 Like

Hello @Goldnmemory

To achieve this, you can use Shopify’s line item properties combined with JavaScript to dynamically adjust the price without creating multiple variants. Here’s the approach:

Add a Dropdown for Pages: Use a select input in your product template to let customers choose the number of pages (e.g., 30–200).

Dynamic Price Calculation: Use JavaScript to calculate the total price using the formula: Base Price + (Price per Page * (Selected Pages - Base Pages)).

Pass Data to Cart: Use line item properties to include the selected page count and adjusted price in the cart and checkout.

This method avoids creating excessive variants and simplifies the process for both you and your customers. Let me know if you need help implementing it!

Hello Devcoders,

Thanks for your reply, yes this is exactly what I am trying to do. However I am not sure how to do any of these without assistance as my knowledge in javascript is pretty limited. Also how do I add the dropdown for pages ? the only options I can add are as shown in the photo below:

Firstly if you doing this for non shopify stores then its not possible to do this, but if you are using shopify plus store, you have to create a cart transform api that will allow you to change the price on the fly, deploy your cart-transform-function activate it and then you are good to go