Price formula example: How to use bulk pricing with different options
The price formulas in the WooCommerce Product Options plugin include bulk functions. Most people use the bulk functions in combination with the quantity that the customer has selected - for example, to give a 20% discount if a quantity of 5 or more is selected. However, you can also use the bulk functions more broadly whenever the price of your products depends on any other parameter.
In this article, we will explore two examples of creating bulk pricing based on the customer's selections in options that are not the main product quantity.
The banner printing service
A shop offers printing services for vinyl banners in custom lengths. Due to how setup costs affect the total price, the price per centimeter decreases with the total length, according to the following structure:
- $0.20 / cm, up to 300 cm
- $0.19 / cm, from 301 cm to 600 cm
- $0.18 / cm, from 601 cm to 1200 cm
What we need for this price calculation:
- A Number option where the customer enters the requested length. We will call it Length.
- A Price formula option.
To calculate to correct price, we use the following formula:
bulkPrice( 0.20, [Length], 301, 0.19, 601, 0.18 ) * [Length]
The first argument we pass to the bulkPrice()
function is the base price. The second one is the variable that will determine which tier is going to be used. From the third to the last argument we specify, in ascending order, the start of each tier and its corresponding price. In this case, starting from 301 cm, we apply the price of $0.19 / cm, while starting from 601 cm we apply the price of $0.18 / cm. Ultimately, we multiply the result by the length itself to get the total cost of the banner.
Let's see how this works for a 3.5-meter banner. The formula gets evaluated as follows:
bulkPrice( 0.20, 350, 301, 0.19, 601, 0.18 ) * 350 = $0.19 * 350 = $66.50
View our demo page to see this formula in action.
The bike rental service
A website offers bike rental services with the following pricing model.
- $2.00 / day, for the first 7 days;
- 5% OFF, from 8 to 14 days;
- 10% OFF, from 15 days or more.
What we need for this price calculation:
- A Date option to set the pickup date. We will call it Pickup.
- A Date option to set the return date. We will call it Return.
- A Price formula option.
In this case, we take advantage of the daycount
property of the Date option. This property returns the number of days from today to the date being entered. Since we are using two different dates, we can observe that the number of days between Pickup and Return can be calculated as [Return.daycount] - [Pickup.daycount]
. Once we have that result, we can use it inside the bulkRate()
function as follows:
bulkRate( [product_price], [Return.daycount] - [Pickup.daycount], 8, 0.95, 15, 0.9 ) * ( [Return.daycount] - [Pickup.daycount] )
The price formula will count the days from the Pickup date and the Return date and evaluate the price that must be applied. If the number of days is less than 8, the [product_price] will be used unaltered. Otherwise, it will be multiplied by 0.95
or 0.9
based on whether the number of days is less than 15 or not, respectively.
This is also a casa where you can take advantage of custom variables: after defining a custom variable called Total_Days
as [Return.daycount] - [Pickup.daycount]
, you can write the formula as:
bulkRate( [product_price], [Total_Days], 8, 0.95, 15, 0.9 ) * [Total_Days]
This is shown in the following screenshot.
View our demo page to see this formula in action.