• Resolved hansgaita

    (@hansgaita)


    I wonder if there’s some way to round the prices. I would like to round my converted prices to 100, I mean, if the price is, for instance, AR$ 21.367, it should show AR$ 21.400. Is it possible? May be adding some function in functions.php? Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support mediawebster

    (@mediawebster)

    Hello

    Yes. Please read this – https://wp-currency.com/search?s=round

    Try to paste in functions.php

    add_filter('wpcs_price', function($price) {
           
           return ceil(768 / 100) * 100;
    });
    Thread Starter hansgaita

    (@hansgaita)

    Thanks for your help. I managed to round to 100 using following code:

    add_filter(‘wpcs_price’, function($price) {
    return $price = round($price / 100, 0) * 100;
    });

    But now I have the problem that the hook also rounds to 100 the price in the default currency.

    USD 35 -> ARS 20900 (rounded from ARS 20801)
    appears as
    USD 100 -> ARS 20900 (with both prices rounded)

    Is there some way to limit the rounding only to the converted currency, leaving the original value in USD untouched? Thanks in advance.

    Plugin Author RealMag777

    (@realmag777)

    Hello

    Try please next code:

    add_filter('wpcs_price', function ($price) {
        global $WPCS;
        
        //https://wp-currency.com/function/wpcs-current_currency
        if ($WPCS AND $WPCS->current_currency !== 'USD') {
            return $price = round($price / 100, 0) * 100;
        }
    
        return $price;
    });
    Thread Starter hansgaita

    (@hansgaita)

    Thank you, @realmag777, but it didn’t work… The price in USD keeps still rounding.

    Plugin Author RealMag777

    (@realmag777)

    Hello

    Just checked – works, try please:

    add_filter('wpcs_price', function ($price) {
            global $WPCS;
    
            switch ($WPCS->current_currency) {
                case 'USD':
                    //do nothing
                    break;
    
                default:
                    $price = round($price / 100, 0) * 100;
                    break;
            }
    
            return $price;
        });

    If no luck, create ticket here please: https://pluginus.net/support/forum/wpcs-wordpress-currency-switcher/

    Thread Starter hansgaita

    (@hansgaita)

    Thanks again, @realmag777, but I’ve tried and it doesn’t work for me… ?? Can it be due to the fact that we are using a different version of PHP (I am with 8.0) or some other system configuration?

    I have been checking how the “switch” statement works in PHP and, as far as I can judge, your code should work. However, it doesn’t and the dollar price shown with the info icon also gets rounded off, together wit the price in argentine pesos, no matter what I do.

    Thanks anyway, I hope that at least this whole thread can help others who need to round their figures in WPCS.

    Plugin Support mediawebster

    (@mediawebster)

    Hello (@hansgaita)

    You can write to the site of the author of this plugin – https://pluginus.net/support/forum/wpcs-wordpress-currency-switcher/

    Support workers will help with this code

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How can I round the prices?’ is closed to new replies.