I need to dynamically alter a price based on the value of two attributes in Commerce. I'm quite new to commerce so not exactly sure how to achieve this. Using rope as an example, the price needs to vary based on both the length of the rope and it's diameter. I know I could create a line item for each length if that was the only variant, however due to both length and diameter being variable this becomes more of a challenge.

Anyone have any ideas?

2 Answers 2


It will probably have to be done with custom Rules. If the price is calculated predictably via different measurements/attributes, you can use the Rules Event of Calculating Sell Price of Product. Conditions could vary, but a custom Action or Action set is probably going to be needed to calculate the price, and then set the price to the calculated value.

Maybe check out this link for an example of dynamically changing product prices.



I believe what you're describing is best done using a product variation. The answer posted about using Rules is a good idea. I'm very, very new to Commerce, but I have an alternate approach that might work for you.

You'll start by creating a Product type of "rope": /admin/commerce/products/types

In that product type, you'll add two new fields: length and diameter.

I would suggest to you that you create ranges of length and diameter, as this will be the easiest method to control pricing. So your diameter will be a pulldown list of values. The length will also be a pulldown list, but contain ranges: "less than 4 feet", "4 to 8 feet".

With both of these fields you want to check: Enable this field to function as an attribute field on Add to Cart forms.

NOW! "Add a product" of the type "Rope". This is where things get a bit complex, but essentially you're going to create a product variation. Each variation of the product has to be created and have a price assigned by you. This can be HELL if you have a lot of options, as the amount of variations grows rapidly. Maybe outside the scope of this question, but I have found a way to auto-generate product variations: Moving or creating many product variations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.