1. Home
  2. Knowledge Base
  3. WooCommerce Product Options
  4. Price Formulas

Price formula example: Bulk calculations in price formulas

Stores often need to change the price of a product based on the quantity being ordered. For example, a product that costs $100 can be purchased for $95 when customers buy 10 or more. To cover this scenario, the price formula field in WooCommerce Product Options  has two special functions: bulkPrice() and bulkRate():

  • bulkPrice() discounts the price by a fixed amount based on quantity - e.g. bulkPrice( product_price, product_quantity, tier_2_limit, tier_2_price, ..., tier_N_limit, tier_N_price )
  • bulkRate() discounts the price by a fixed decimal/percentage amount based on quantity (i.e. 0.9 means 90%) - e.g. bulkRate( product_price, product_quantity, tier_2_limit, tier_2_rate, ..., tier_N_limit, tier_N_rate )

Let's see how they work in two practical examples.

The bulkPrice() function

A store sells a product with the following pricing structure:

  • $20, when purchasing up to 9 items;
  • $18, when purchasing 10 or more, up to 49 items;
  • $15, when purchasing 50 or more, up to 99 items;
  • $12, when purchasing 100 items or more.

Since we know the exact price for each tier, we are going to use the bulkPrice() function. The price formula that achieves the requested calculation is this:

bulkPrice( [product_price], [product_quantity], 10, 18, 50, 15, 100, 12 )

Let's analyze that formula in detail. We are passing to the bulkPrice() function 8 arguments. The first 2 arguments are [product_price] and [product_quantity]. Thanks to those first two arguments, bulkPrice() knows what is the base price of the product and what is the quantity selected in the cart form. The rest of the arguments are to be read in pairs. Each pair tells the quantity where a new tier starts and the price to be used for that tier.

The screenshot above clarifies the arguments the bulkPrice() function expects. To have a well-defined list of arguments, it is required that:

  • you pass at least 4 arguments, with the first two always being the product price and the product quantity;
  • you always pass an even number of arguments, with each pair representing the starting quantity and the price of each tier.

We can also observe that the first tier is implicitly defined by the product price itself, with the starting quantity of the first tier being trivially 1.

The bulkRate() function

In many scenarios, a store owner may want to define the bulk prices in terms of percentages of the base price. The main advantage of this approach is that the price of each tier will change whenever the base price changes, without any need to adjust the formula. The structure of the arguments passed to the bulkRate() function is the same as we saw above for bulkPrice() but, this time, instead of passing the exact prices for each tier, we are going to pass a percentage, expressed as a decimal number (e.g. 0.9 represents 90%, 0.5 represents 50%, and so on).

Let's say that the pricing structure of the product is as follows:

  • Full price, for up to 9 items;
  • 5% OFF, for 10 or more, up to 49 items;
  • 10% OFF, for 50 or more, up to 99 items;
  • 15% OFF, for 100 items or more

The price formula will be this:

bulkRate( [product_price], [product_quantity], 10, 0.95, 50, 0.9, 100, 0.85 )

As you can see, the list of arguments is exactly the same as before but, in this case, we are passing factors that the bulkRate() function will use to multiply the base price and find the price of each tier. Like in the previous case, the list of arguments always starts with the product price and quantity, followed by an even number of arguments, where each pair represents the starting quantity and the applicable rate of each tier, respectively.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.