Total calculation for Woocommerce product

By: Ketil Berg | Asked: 06/28/2021
ForumsCategory: How-toTotal calculation for Woocommerce product
Ketil Berg asked 3 years ago
Hello, I was wondering if someone could help me set up conditional calculation in a form that adds a total to a woocommerce product. The issue is as follows. I'm using a form with a Woocommerce product, and the total field supposed to add to the product price. The product is fishing permits, and the form lists the different permits as radiobuttons with "static" values seperating each option. Works fine, except for this one option that is not a static price, but depends on user input. This is for daypasses, and varies based on how many days. The fields are :
[455] : radiobuttons
- season licence 1 (200)
- season licence 2 (400)
- daypass (depending on number of days)
- season licence 3 (free)
- season licence 4 (free).

So the total should list the price from [455], unless the selection is "daypass".
In that case, the total should be 150*[531] (daycount).

I think the answer lies here, but I'm not able to set up a working formula for the above issue.

1 Answers
Best Answer
Chris AdamsChris Adams answered 3 years ago
Hi Ketil, If you assign the 'Daypass' option a number you can use that in your calculation. A really high or low number would work best. I would also then use a hidden field to to do the calculation and then pass the hidden field value to the Total field. As an example if you assigned the 'daypass' option a value of 1000 then you can use a calculation in your hidden field like this:
([455] > 999) ? ([531] * 150) : ([455])
This essentially says: IF field 455 is greater than 999 then use field 531 * 150 as the caculation ELSE use the value of field 455. I haven't tested that but it should work. Hope that helps. Chris | FDM Digital

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community