WooCommerce: How to Calculate Product Prices with Custom Formulas

WooCommerce is a powerful and feature-rich WordPress plugin. But despite the fact it’s got many features, there is always something missing for custom ecommerce businesses.

The problem with “all-you-can-do plugins” is the same as “all-in-one WordPress themes“: the more custom functionalities a piece of software has, the worse its performance gets.

Therefore, there is no need to pack every imaginable functionality into WooCommerce as it is easily expandable with other plugins.

For example, one particular feature is not available in WooCommerce out of the box: the possibility to use math formulas to calculate product prices.

This functionality is crucial for specific industries such as digital printing, custom-sized furniture, curtains, tiles, rollers and so on.

Curious to know how this can be implemented?

The idea and purpose of flexible price calculation

Quite often, businesses need to use some variables for a proper and accurate price calculation. It is relevant for products with measurements like width or height. Typically these are advertisement banners and other printing products, rollers and shutters etc.

Another use case would be when a product involves customization, e.g. ingredients or services, so a customer is allowed to choose add-ons. A perfect example would be a food ordering form, like pizza or cakes. Usually, the price for such products is based on quantity and type of ingredients added. 

Other examples: personalized medals, gift wrappings, custom cut glasses/mirrors or even online game user rank upgrades!

There is a handy plugin for that

Uni CPO WordPress plugin lets you use math formulas for product prices – any formula! Whatever you put inside the ‘main formula’ setting becomes the product’s price.

Leave it empty and you will get a ‘0.00‘ price; fill it with any valid math expression and you can “build” your product price. Putting only a number also works (e.g. ‘42‘).

Math formula can be as simple as the following one:


Or it may be as complex as:

({uni_cpo_width}*{uni_cpo_height}*{uni_nov_cpo_base_price})+{uni_cpo_thickness}*2.12+round(max({uni_cpo_acc1}, {uni_cpo_acc2}, {uni_cpo_acc3}))

Or even more complex! 

Please note: variables inside the curly brackets are product custom fields. Those that begin with ‘uni_cpo_‘ are regular variables from the custom options added to the product. 

Which brings us to the next note: Uni CPO plugin also lets you add custom product options by using a visual form builder.

Each regular variable holds the value of its option. Those that start with ‘uni_nov_cpo_‘ are numeric variables, created without any connection to options. It is possible to create a lot of artificial variables – in the plugin I call them NOVs (abbr for “non-option variables“) – and each can hold its part of the formula.

It is also possible to re-use NOVs in other NOVs and create a cascading effect.

Custom functions and NOV matrixes

You may have noticed that I used known math functions in the previous examples: ‘round‘ and ‘max‘. That’s right, and you can use these are functions in your formulas in the same way as you may do that in spreadsheet software.

There are more! Functions like ‘round‘, ‘floor‘ and ‘ceil‘ help with rounding. Functions such as ‘min‘ and ‘max‘ accept several arguments and make it possible to get the lowest and the highest number from a set of options. There are also ‘IF‘ statements. You can compare the option’s value against some threshold and determine if it is higher or lower and build additional logic on this.

NOV matrixes can be one or two dimensional and are used to derive a new value based on the value(s) from regular option(s) or NOV(s).

The simplest example is table-based pricing. Let’s say you have an option called “Thickness” (a dropdown of available values). Each thickness value (e.g. 4mm, 6mm etc.) has a specific price (e.g. 4mm has price $5.10, 6mm has price $8.79).

In this case, {uni_nov_cpo_thickness} will be holding thickness values (4 and 6 mm):

…and {uni_nov_cpo_thickness_price} will be holding price values:

Each option includes sub-options such as nicename, slug and price/rate settings (in our example these will be used instead of ‘1’ and ‘2’ that really don’t mean anything):

Demo and usage examples

Uni CPO demo site features many case studies – for example “Foamex banner” or “Furniture” products. They all take advantage of math formulas in order to calculate their prices.

The potential of the Uni CPO plugin is quite vast. You can use it even for product add-ons and for product configurations.
Another Uni CPO case study: measurement price calculations

Free vs PRO version

The free version of Uni CPO gives you the option to use math formulas and math functions in your product price calculations. Non-option variables are also available.

Uni CPO PRO introduces matrix functionality; therefore, it gives a possibility to create table-based pricing. Besides, it enables the product’s weight calculation and allows defining its measures; these values could be used during shipping price calculation (if your shipping plugin supports these values to be set dynamically).

The pro version includes updates and support (first response is always within 24 hours) for one year or lifetime, depending on the chosen license.

Related content

  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce AMA with Rodolfo Melogli (Ask Me Anything Woo #1)
    I am Rodolfo Melogli, founder of Business Bloomer, WooCommerce development expert, WordPress freelancer, WordCamp speaker, content marketing geek and (like you) small business owner. This is the first ever WooCommerce AMA (Ask Me Anything) session on Business Bloomer. Rodolfo Melogli will be donating 72 hours of his time and will be available to answer your […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]
  • WooCommerce: Add Prefix / Suffix to Product Prices
    Sometimes you may want to add a prefix or a suffix to your prices. It could be something like “From…”, “Only…”, “…tax free” and so on. The first good news is this is very easy to do with a WooCommerce filter (remember, filters change the value of an existing variable, while actions add content). The […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

16 thoughts on “WooCommerce: How to Calculate Product Prices with Custom Formulas

  1. I have a client with a website I created that already has a number of variable products on it.

    They want to expand the site with a new range of products (sails) where the price will be calculated using a mathematical formula where the clients input the three lengths of the sides of the sail.

    Once the basic product is configured they will need to be able to add a range of up to six or seven options (eg stripes) and the price for each option will also be related to the formula multiplied by a base price.

    Will the Uni CPO WordPress plug-in be able to do all this?

    1. I believe so. Talk to the plugin dev and see what they say

  2. Hello,

    I would like to know if the plugin is able to calculate the price in percentage.

    The customer must enter on woocommerce the value (which varies from customer to customer) and I must have as result 30% of that amount entered by the customer


    Customer value: x=152

    Final result (X*33)/100

    1. Hi Mauro, please ask the plugin developer

  3. I need to have different markups based upon the cost of my products. So if my current price (cost) is between $1 – $1000 I want to display on the front end 1.35 times OR if between $1001 – $3000 then 1.3 times OR if between $3001 – $5000 1.24 times OR greater than $5000 1.8 times. Will your plugin do this?

    1. I believe so, but please ask the plugin developer.

  4. Do you have any recommendations for a shipping plugin that does custom formulas as well? While I love the front end of your plugin and it works great, we are running into issues finding a shipping plugin that works with this and also offers formulas that take into account the sq ft.

    1. I’d ask the plugin developer – see if he can help?

  5. Hello,

    do you think that it would work with WooCommerce composite products?



    1. Not sure, ask the plugin dev please

  6. Hi I have been using this plugin for over a year but would like to add a minimum price to some of my products, I sell custom stickers and if someone wants to order 1 sticker which the cost will be $1 if the order 50 stickers the price will be $50, i want to set a minimum price of $50, so if the customer orders quantity that would cost less then $50 it shows $50 as the price. I have tried using MAX formula in excel (which is working in excel) but when i replicate the formula in the plugin it multiples the quantity ordered by $50. Thanks for your help.

    1. Nice! I think the best is asking the plugin developer

  7. I did it with my custom codes with php. I made calculator and user can add extra values to current product price. But I don’t know how can I add product to cart with user’s own price. This plugin does it, but I need with custom codes. Can you share tutorials about it?

    1. Hey Cavid, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  8. This looks like a really useful Plugin. I will have to try it on a cabinet making site I am working on.

    1. Cool – let me know how it goes!

Leave a Reply

Your email address will not be published. Required fields are marked *