1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Calculation Fields and Formulas
  5. Set quantity break pricing with formulas in WooCommerce
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Pricing
  5. Set quantity break pricing with formulas in WooCommerce
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Set quantity break pricing with formulas in WooCommerce

Set quantity break pricing with formulas in WooCommerce

WooCommerce Product Add-Ons Ultimate lets you set prices dynamically using calculation fields. So you can create simple or complex formulas based on user inputs, including quantity, that will determine the product price. And because calculation fields allow for conditional logic, you can set quantity price breaks – e.g. charge a lower product price when the users chooses a higher quantity.

If you also have the Advanced Calculations extension active, you can use lookup tables to set price breaks. We’ll look at both methods in this document.

Using formulas to set quantity price breaks

If you only have a few price breaks, you can use conditional logic with the calculation field formula to set prices. This is fine if you don’t have many products where you need to set this – otherwise it can become difficult to manage. In which case, take a look at the section below on using lookup tables.

Add a calculation field to your product

First, add a new calculation field to your product.

  • Step #1: Edit your product and click the ‘Product Add-Ons’ tab in the ‘Product data’ section
  • Step #2: Click ‘Add Group’ to create a new field group, then click ‘Add Field’ and select ‘Calculation’ from the ‘Field Type’ setting
  • Step #3: Enter a label for the field, such as ‘Unit Price’
  • Step #4: Click the ‘Formula’ box to open the formula builder panel. Use its buttons to insert variables, operators and functions without typing the syntax from memory.

The formula builder checks your syntax as you type and flags issues such as unbalanced brackets before you save.

How do you build a quantity break formula?

This method uses nested if-else (ternary) logic, with one condition for each pricing tier. This means that the field checks a condition (e.g. whether the quantity is less than 50) then applies a rule.

In this example, the following formula first checks if the product quantity is greater than or equal to 50. If it is, then the formula returns a value of 6; if it’s not, it does another check – this time to see if the quantity is greater than or equal to 10. If it is, the formula returns 8; otherwise, it just returns 10 as the base product price.

{quantity} >= 50 ? 6 : ({quantity} >= 10 ? 8 : 10)

To build it:

  • Insert {quantity} from the ‘Variables’ row in the formula builder
  • Insert the ? and : symbols with the ‘if-else’ button in the ‘Logical’ row
  • Wrap each nested condition in parentheses to keep the order of evaluation clear
WooCommerce calculation formula for setting quantity price breaks

The plugin will display a readable version of the formula below the formula input field. It will also automatically parse and check the formula for syntax errors – the green tick shows that the formula is valid.

Use the formula result to set the product price

Once the formula is correctly entered, you can use the value that it returns to set the product’s base price. Just set the calculation field’s ‘Action’ to ‘Set Product Price’.

WooCommerce calculation formula setting for defining result as product price

You can also enable the ‘Hide Calculation’ field if you don’t want the formula result to be displayed on the product page.

Save the product. Now, when the user updates the quantity, the calculation field will use the quantity to set the unit price and update the product price accordingly. So if the user selects a quantity of 50 or more, the product price will be set to $6; if they select a quantity between 10 and 50, the product will be set to $8; otherwise, the price will default to $10.

You can nest as many if-then statements as you wish in the formula.

Was this article helpful?

Related Articles