All Collections
Currency Switcher
Filter converted currency amount with PHP
Filter converted currency amount with PHP

Learn how to add filter code to modify the product price after currency conversion, to round converted currency prices, for example.

Vikrant Sant avatar
Written by Vikrant Sant
Updated over a week ago

With PeachPay for WooCommerce, the Currency Switcher allows shoppers to switch their currency. You can also set it up to automatically show a certain currency based on conditions. Sometimes, you'd like to change the final amount before it's shown to the shopper because it doesn't look pretty.

For example, you may want to round to the nearest 0.95 so the number is clean after conversion. You original price might be $3.99 USD, but after conversion to GBP, it is show as £3.13 GBP, which isn't a whole number or a .95 or .99 style number.

You can do this in PeachPay by adding a calling the WordPress add_filter function on the hook peachpay_currency_switcher_convert_raw_price.

In your child theme's functions.php file, you could add the following to make currency converted prices always display with .95 at the end, even after conversion. It does this by rounding the converted amount to the nearest whole number and then subtracting 0.05.

Example for rounding to nearest 0.95

add_filter( 'peachpay_currency_switcher_convert_raw_price', 'custom_currency_conversion_filter', 10, 5 );

function custom_currency_conversion_filter( $converted_price, $original_price, $number_of_decimal_places, $conversion_rate, $price_type ) {
if ( 'product' === $price_type ) {
$converted_price = round( $converted_price, 0 ) - 0.05;
}

return $converted_price;
}

Want more help?

If you need additional help in setting this up to round a certain way, or to modify the price in a creative way, feel free to reach out to our support. We can help you with your custom use case at no cost.

Did this answer your question?