Changing the Number of Decimals in Prices

Changing the Number of Decimals in Prices

Easy Digital Downloads defines two decimal points as the default for product pricing.

however, there are definitely situations in which a different number of decimals is required. For these situations, a little bit of code is necessary to override the default value:

function kjm_edd_use_three_decimals() {
    return 3;
add_filter( 'edd_sanitize_amount_decimals', 'kjm_edd_use_three_decimals' );
add_filter( 'edd_format_amount_decimals', 'kjm_edd_use_three_decimals' );

The number “3” in this snippet can be changed to any number required, including zero.

This code can be inserted into either a custom plugin or a child theme’s functions.php file. If this is your first time creating a custom plugin, Pluginception can be very helpful as it makes the process of generating a new plugin much simpler.

When this snippet is active on a site, all download prices will always appear with the defined number of decimals. For example, changing the number of decimals to “3” like in the example above will result in prices on the download edit screen appearing like this:

If download prices are saved with a number of decimals that is greater than the number allowed by either the default value or the value overridden by the snippet above, the result upon updating the download will be a number rounded to the correct number of decimals.

Powered by BetterDocs

Leave a Reply

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

EDD Sell Services