How to create a price formula for your WooCommerce products
The WooCommerce Product Options plugin comes with a Price Formula field type which you can use to create a product price calculator. This calculates a custom price for the product based on factors such as the data that the customer selects in your other product options; or any other product data.
The price formula is very sophisticated and you can use it create very simple or very complex calculations using advanced mathematical and logical functions. This article contains an overview of creating simple price formulas. For more advanced instructions and specific use cases, also see our other price formula articles.
How it works (an example)

Imagine that you're selling made-to-measure curtains which are charged based on the area of fabric ordered. To achieve this, you can create a product with the following options:
- Width (number field)
- Length (number field)
- Price Formula
The price formula field will perform a calculation that multiplies the width, length, and the cost per meter. This will then update the total price of the product.
You can create very simple or very complex price formulas, depending on your requirements. For example, if you're selling curtains then you might want to:
- Add a fixed base cost which will be added to the calculated price regardless of the curtain dimensions.
- Double the calculated price because you're selling the curtains as a pair.
You can also choose whether or not to include the main product price in the calculated price. For example, you might have entered the main price for the curtains as $200 so that you can display it as "From $200" on the product page, but you may not want to add this to the calculated price.
Video tutorial
The following video shows how to create a simple price formula. Please note that it was created before the release of WooCommerce Product Options version 2.0, which added more advanced options to the price formula. These are documented in the written tutorial below.
Instructions
To create a price formula, go to Products → Product Options, edit the option group that you want to add the calculation to, and add the following fields:
1. Add the fields to be used in the calculation
First, add all the fields which will be used in the calculation. For example:
- In the curtain example above, you would need to create number fields for the customer to enter their desired width and length.
- If you were selling pizza toppings and wanted to provide the first 3 for free and charge for additional toppings then you could create checkboxes listing all the toppings and then use the number of choices selected as a factor in the price formula.
If these fields will have numeric values which will be used in the price formula, then you need to add this for each choice. This happens automatically for number and customer-defined price fields because WooCommerce Product Options will simply use the value which the customer enters (e.g. the curtain width in centimetres). For other field types, you need to manually assign a numeric value to each choice. For example, if you have 'Curtain width' radio buttons with pre-defined options for 80cm, 1m and 1.5m then you can charge by the centimetre as follows:
- Add the radio buttons as usual.
- Click the blue cog to the top right of the list of choices and enable the 'Formula value' column.
- This will add a 'Formula value' column to the list of choices. Use this to record the exact numeric value that each choice corresponds to - for example, enter '80' for the 80cm radio button, '100' for the 1m button and '150' for the 1.5m button.
Next, click the Save button at the bottom of the page. This saves the options you just created so that you can use them when you create the price formula in the next step.
2. Add a price formula
Next, add a 'Price formula' field to the option group:

Create the formula which will be used to calculate the price. You can use the following variables and operators, which are displayed underneath the Formula field so that you can click to add them as required:
- Product - Use this dropdown button to insert the following product data fields into the price formula:
- Price - The main price of the product to the formula. This is the price for the product or variation that you entered on the 'Add/Edit Product' page. (Note: If you add this to the formula then it will be used in the calculation regardless of whether 'Ignore main product price' is enabled below.)
- Quantity in cart - The number of the current product (or its variations) in the cart.
- Weight - The product weight, which is entered on the 'Add/Edit Product' page in Product Data → Shipping.
- Width - The product width, which is entered on the 'Add/Edit Product' page in Product Data → Shipping.
- Length - The product length, which is entered on the 'Add/Edit Product' page in Product Data → Shipping.
- Height - The product height, which is entered on the 'Add/Edit Product' page in Product Data → Shipping.
- Next, a button will appear for each of the product options that you created in Step 1:
- For number options (e.g. where the customer has entered an exact curtain width), simply click on it and it will add it to the price formula.
- Other option types will have a dropdown listing various properties which can be used in the formula (learn more about how to use each option type in the price formula).
- + - * and / - use these to add mathematical calculations to the formula, for example, to multiply two number fields or add the main product price.
- ( ) - use brackets to tell the formula which part of the calculation to make first.
- Functions:
- Math - Select from a list of mathematical operators.
- Logical - Select from a list of logical functions.
- Other - Select BulkRate or BulkPrice to give a fixed or percentage discount based on the quantity ordered.
FAQ
How can I use brackets in a formula?
The calculation of mathematical expressions is based on a precise convention, called order of operations. According to this convention, parentheses should be solved first, then exponentiations, then multiplications and divisions, and finally additions and subtractions. So, parentheses are designed to prioritize the calculation of an expression in the formula. Let's illustrate this with an example of a product where the customer has entered the width as 5 and the length as 10:
- Given the formula
[Width] * [Length] + 50
, the convention about the order of operations tells us to calculate multiplications before additions. When[Width]
is 5 and[Length]
is 10, the result is5 * 10 + 50 = 50 + 50 = 100
. - Let's see a slightly different formula:
[Width] * ( [Length] + 50 )
. The convention instructs us to calculate the expressions inside parentheses, then the multiplication. When[Width]
is 5 and[Length]
is 10, the result is5 * ( 10 + 50 ) = 5 * 60 = 300
.
Can I see more examples?
A simple example

The following price formula is quite simple: [Width] * [Length] * 25
Since multiplications have the same priority, we can calculate the result from the left to the right. We multiply the two number fields - width and length. Then, we multiply the result by 25 to get the final price.
For example, you might use this for products that you are selling by the square meter.
A more advanced example
This price formula is more complex: [Width] * [Length] / 10000 * 25 * 2 + [product_price]
It might be used to sell a pair of curtains by the meter, where the customer enters the dimensions in centimeters but the fabric is priced at $25 per square meter - so the formula needs to convert the centimeters into meters! The product might also have a base price which is added regardless of the size.
You can easily recognize that the formula includes one addition and a series of multiplications and divisions. So, let's break it down:
The series of multiplications and divisions all have the same priority and can be calculated from the left to the right.
[Width] * [Length]
represents the area of the fabric, in square centimeters.- Since the price of the fabric is expressed in square meters, we need to convert square centimeters into square meters. We do so by dividing
[Width] * [Length]
by10000
- Then, we multiply the area in square meters by
25
, which is the price of the fabric per square meter. - Finally, we multiply the result by
2
because the curtains are sold in pairs.
- Once we get the result of the multiplications and divisions, we can finally add it to
[product_price]
, which is the base price of the product. For example, you might add a base price to cover the labor charge, which will be the same regardless of the amount of fabric ordered. (Tip: You only need to add[product_price]
to the formula if 'Ignore main product price' is ticked below, otherwise it will be added twice!)
As you can see, price formulas can be complex. With complex formulas, it can be useful to use redundant parentheses that have the only purpose of improving readability, while also breaking down larger formulas in smaller chunks. For example, the previous formula could be written as (((( [Width] * [Length] ) / 10000 ) * 25 ) * 2 ) + [product_price]
. This formula returns the same result because the parentheses do not alter the default priority assigned to multiplications and divisions by the order of operations. Nevertheless, the parentheses help break down the formula into smaller operations.
Even more advanced examples!
As you have seen, price formulas can be as complex as you like, and you can use them in very advanced ways! You can find more examples for specific use cases in our Price Formula category.
How can I create more advanced mathematical formulas?
Above, we have given examples of price formulas that are of a simple or medium degree of complexity. You can also create even more complex formulas using advanced mathematical operations. We have a separate article about how to do that.
Help! My price formula is too long and complicated
Price formulas can easily get very long and complicated! You can simplify them by creating custom variables. We have a separate article about how to do this.
My formula is calculating the wrong price!
These are the most common reasons for a formula not working correctly:
- Have you made a mistake in the formula? Price formulas can be complex, especially if you are adding lots of parts to the equation. If you're not confident with the math then we recommend asking an expert to check it for you.
- Is the main product price being added to the total? WooCommerce requires you to set a price for the product or variation, otherwise it will not be purchasable. You do this on the 'Add/Edit Product' page. Normally, WooCommerce will add this to the total cost of the product, even if you are using a price formula field. You can stop this from happening by ticking the 'Ignore main product price' box in the Price Formula settings.
- Are you using brackets correctly? Brackets can make or break a formula, so check these carefully. Remember - the parts of the formula in brackets will be calculated first. Learn more about how to use brackets.