Back to Blog Posts

Customise price formatting with the price formatter

By Matt / August 15th, 2017


Introduced back in WHMCS 7.1, the Price Formatter gives you access to manipulate and customise how prices are output by WHMCS.

How it works

All template variables that are used to output prices within WHMCS are now returned as Price Formatter objects.

The Price Formatter object has 4 key methods as shown in the table below. Using these you can customise how the price is rendered. By default all prices without an explicit method call will output in the full format which takes the format {prefix}{amount}{suffix} (eg. $5.95 USD).


Example usage

Example 1: In this example we are editing the order summary shown when viewing the shopping cart (/templates/orderforms/standard_cart/viewcart.tpl line 462). Here we will implement use of the ->toPrefixed() method to show the price with only the defined currency prefix.

Example 2: In this example we are performing a more complex customisation to change how the price is displayed within the client area (/templates/six/clientareaproducts.tpl line 34). Here we will implement use of the ->toNumeric() method along with use of number format to apply some match and then output the resulting price per month.

Reference

For more information, please refer to the Price Formatter Class Documentation

Liked this article? Share it