7 - Creating a calculator from a mathematical formula - WPC
You can use WooPrice Calculator for creating a calculator using simple mathematical formulas. For more complex formulas and features, you can load a spreadsheet file directly (Pro version).
First of all you need to create your WooCommerce Product:
- Click on "Products > Add New" on the left Wordpress sidebar
- Insert the name of the Product and set the product mode as "Simple Product": The plugin will override the WooCommerce simple product features.
- Set a price in "Regular Price". Also putting "0" is fine. This is important otherwise, WPC can't attach its features to the product page.
- Save the product by clicking on "Publish"
After you've created the WooCommerce Product and after you've created your customer input/output fields (See How to create fields) you are now ready to create the calculator.
To create the calculator, go in the "Calculator" tab and click on "Write your formula" and fill in the following information about your new calculator:
- * Name: This value is only needed to remember what the calculator is for, and to find it in the list of calculators later.
- Description: A more detailed description of what the calculator does
- Input Fields: Click this to choose the fields that must be in the calculator. Click on the items that must be moved to the right (Selected fields). To remove items, click on the ones on the right to move them on the left.
- Formula: It's the heart of the calculator because it's where the calculation formula will be placed. In this slot it's possible to place:
- $aws_price_calc_n: Represents the value placed in the field by the visitor. This alias can be seen from the "Field" list.
- $price: It's the starting price for the product, set in WooCommerce, in the product's folder.
- a+b: Sum
- a-b: Subtraction
- a*b: Multiplication
- a/b: Division
- a^b: Power
- a!: Factorial
- a%b: Module
- sqrt(a): Square root
- cos(a): Cosine
- sin(a): Sine
- tan(a): Tangent
- sec(a): Secant
- csc(a): Cosecant
- cot(a): Cotangent
- abs(a): Absolute Value
The "Insert Field in the Formula" button can be used to add a field in the formula without typing it in.
- Products: The products that the calculator must be linked to. You can also assign the calculator to whole categories.
- Force to show price on errors: It try to show the price and output fields if there are some errors (ex: Required fields not filled in).
- Hide field errors on startup: On product page startup field errors are not shown.
- Redirect to checkout if "Add to cart" is clicked: If selected “Yes”, the visitor will be redirected to the checkout after adding the product to the cart. If selected "No", user can continue shopping and will not be redirected.
- Empty cart: If "Yes" it empties the cart when a product has been added to the cart. It's useful for services.
- Themes: The theme used to see the calculator. The default theme is auto-generated.
Click on "Save" and the calculator will be visible in the pages of the chosen products.
Price format and price approximation are made by WooCommerce (See WooCommerce > Settings > General tab)