• Resolved mikewimpey

    (@mikewimpey)


    We have added the Custom Currency Formatting at:
    https://givewp.com/documentation/developers/custom-currency-formatting/

    I need to remove the thousands separator, however there seems to be no effect. This is for a donation form for the Children’s Hospital Trust – they do a lot of good, so it would be great if we could get their form to work. The separator prevents the form from working with VCS, the payment gateway.

    Your assistance would be greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    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!

    Thread Starter mikewimpey

    (@mikewimpey)

    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…

    Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    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!

    • This reply was modified 9 years, 2 months ago by Matt Cromwell.
    Thread Starter mikewimpey

    (@mikewimpey)

    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!

    Thread Starter mikewimpey

    (@mikewimpey)

    I just rolled back to an older WP version, and the form is working. Thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom Currency Formatting: Remove Thousands Separator’ is closed to new replies.