Hi @mikewimpey
You can change the thousands separator to whatever you like (or remove it completely) by going to “Donations > Settings > General > Currency”.
Let me know how that goes for you.
Thanks!
Hi Matt, thanks for the help. I was working on an older version at first, which only allowed a “.” or “,”. Which is how I got to the custom function. I have now just removed the separator from the settings, but it seems to default back to “,”. See http://childrenshospitaltrust.org.za/donate/ when inserting a value of more than R1000.
Unfortunately I updated WordPress to see if that would fix the problem, but now I have an SMTP issue, so I can;t get to the next step to see if it really works or not. Will hopefully sort that out for them tomorrow.
So although the settings seem to make provision for this now, there is still a “,” separator…
Hi there, I see what you mean. Our auto-formatting JS is defaulting to the comma because that setting is empty. So the only way to get around it is to filter those results. We have to filter both the default value and the JS, so here’s what you need:
add_filter('give_format_amount', 'give_remove_thousands_seperator');
function give_remove_thousands_seperator($amount, $decimals = true) {
$thousands_sep = '';
$decimal_sep = give_get_option( 'decimal_separator', '.' );
if ( empty( $amount ) ) {
$amount = 0;
} else {
// Sanitize amount before formatting.
$amount = give_sanitize_amount( $amount );
}
$decimals = $decimals ? give_get_price_decimals() : 0;
$formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
return $formatted;
}
add_filter('give_global_script_vars', 'give_remove_thousands_js_autoformatting');
function give_remove_thousands_js_autoformatting($args) {
$args['thousands_separator'] = '';
return $args;
}
If you need guidance implementing custom PHP functions on your website, we have this guide here: https://givewp.com/documentation/resources/adding-custom-functions-to-your-wordpress-website/
Thanks!
Hi Matt, Thank you very much, looks like it will work – now I must just get the smtp to work so that I can test it properly.
Much appreciated – you are a life saver!
I just rolled back to an older WP version, and the form is working. Thanks again!