On the "add to cart" page, I let the user enter "Width" & "Length" to calculate the number of Square Foot as the quantity which works fine with a JS function. Now my client wants to add an "overhead" price to the product based on the selected variations. Is there a way, either an "hidden field" in the form OR a hook in the module where I can put the amount to add to the line item ? Or any other best idea is appreciated as well ! I'm on Craft Commerce 4.
1 Answer
You would need to change the price of the line item based on the option data sent in.
https://craftcms.com/knowledge-base/dynamically-customizing-line-item-prices
-
The worst thing is that you cannot change the total and subtotal, as this is a property read, except adjusters.– RomanAvrCommented Jun 16, 2022 at 10:36
-
Thanks @Luke for your answer. You pointed me at the right place. However, from what I see, it looks like all the previous line-items are visited in the process. Althought the rules don't change, it will perform calc on already saved items. Is there a way to get a hook on the actual item added to the cart ? Commented Jun 22, 2022 at 12:37