0

We are selling corrugated boxes. I want to add form to product page (Woocommerce), in which user will input Length, Width and Height. I want to use those input values to make calculations of price of the product. Is it possible to use "result" value of below code, as price of the product, how do I do it?

I asked this in live chat of Woocommerce, they didn't give any solution, other than hiring a developer or using an extension.

<!DOCTYPE html>
<html>
<body>

<form>
  <label for="num1">Number 1:</label><br>
  <input type="text" id="num1" name="num1"><br>
  <label for="num2">Number 2:</label><br>
  <input type="text" id="num2" name="num2"><br><br>
  <input type="button" value="Add" onclick="addNumbers()">
</form> 

<p>The result is:</p>

<p id="result"></p>

<script>
function addNumbers() {
  var num1 = parseInt(document.getElementById("num1").value);
  var num2 = parseInt(document.getElementById("num2").value);
  document.getElementById("result").innerHTML = num1 + num2;
}
</script>

</body>
</html>
Sensebe
  • 194
  • 2
  • 13
  • 1
    That is possible, you just need to add a hidden input field inside the product add to cart form [like in this answer](https://stackoverflow.com/questions/47752907/pass-custom-calculated-product-price-to-cart-in-woocommerce/47762649#47762649). Then in your javascript, you will add some code to set your calculated price as a value in this hidden field. then: [Custom cart item price set from product hidden input field in Woocommerce 3](https://stackoverflow.com/a/52304377/3730754) – LoicTheAztec Jul 02 '23 at 21:41
  • Hi, is there any source/guide which says on the way of adding code to functions.php? Videos/guides which I have seen, seem to be asking to use wordpress theme file editor, which seems to be not present in my wordpress home. Thank you. – Sensebe Jul 09 '23 at 09:54

0 Answers0