Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter TheFactSite

    (@thefactsite)

    I can see in your documentation that you have instructions, however, I’m not very good with php…

    I want to round the currency to the nearest .99

    This is what I currently have, although I’ve tried various options, and havn’t seen my prices change yet… am I doing something wrong?

    return number_format($price, 2, ‘.’, ”);

    //some hints for price rounding
    //https://stackoverflow.com/questions/11692770/rounding-to-nearest-50-cents
    //$price = round($price * 2, 0) / 2;
    //return round ( $price , 0 ,PHP_ROUND_HALF_EVEN );
    //return number_format ($price, $this->price_num_decimals, $this->decimal_sep, $this->thousands_sep);

    Thread Starter TheFactSite

    (@thefactsite)

    Hey again,

    I’ve found a solution to my issue:

    $price = round($price) – 0.01;
    return $price;

    However, the price only rounds up in the cart page (not on the product page).

    It’s not a caching issue, and no other plugins/theme is affecting it.

    When I set “Is multiple allowed” to “No”, it displays correctly on the site, and in the cart.. but then as soon as I get to the checkout page, the currency changes back to $ (instead of £) which my customers would find confusing.

    I’d like to have “Is multiple allowed” set to “Yes”, and it displays the correct price throughout.

    Please help!!

    Plugin Author RealMag777

    (@realmag777)

    Hello

    For rounding variations prices uses another function – woocommerce_variation_prices, so replace its code by:

    public function woocommerce_variation_prices($prices_array)
        {
            if ($this->current_currency != $this->default_currency)
            {
                if (!empty($prices_array) AND is_array($prices_array))
                {
                    foreach ($prices_array as $key => $values)
                    {
                        foreach ($values as $k => $v)
                        {
                            //$prices_array[$key][$k] = $this->woocs_exchange_value(floatval($v));
                            $prices_array[$key][$k] = apply_filters('woocs_woocommerce_variation_prices', $this->woocs_exchange_value(floatval($v)));
                        }
                    }
                }
            }
    
            return $prices_array;
        }

    and in your theme functions.php file write:

    add_filter('woocs_woocommerce_variation_prices', function($price) {
        return round($price * 2, 0) / 2;
    });
    Plugin Author RealMag777

    (@realmag777)

    Hook woocs_woocommerce_variation_prices will be in the next version of WOOCS

    Hi RealMag777,
    I have added your new code to the plugin index.php (around line 1862) replacing the previous code and also added the second lot of code to the theme function.php file.

    I am not getting any change to my pricing and like TheFactSite I want my prices rounded up. In my case the main currency is $ and I want the £ prices rounded up to whole pounds. Eg $5 to convert to £4.

    What am I missing from the above since my prices are staying the same and not rounding up?

    I have cleared my cache.

    Thanks
    Rhona

    Hello
    Do you changed the code in

    add_filter('woocs_woocommerce_variation_prices', function($price) {
        return round($price * 2, 0) / 2;
    });

    return round($price * 2, 0) / 2; replace to round($price) – 0.01;

    product page – You mean single product page ( https://clip2net.com/s/3C4bS1b ) or shop page

    Drop me please exact link to issue.

    I have the same issue as @rhonam, replaced the code in under public function woocommerce_variation_prices($prices_array) and added new code at theme functions.php, but nothing happened, not rounding up at any point.

    Please advise. thanks!

    Hello @angeland

    replaced the code in under public function woocommerce_variation_prices($prices_array) – This is only for the variation price

    You did it? – https://currency-switcher.com/how-to-round-price-to-50-cents/

    Same here. Changed as described in those 2 files. And nothing happened. Why is that?

    Hello @aivaraskar

    Do you use cache? Clear all cache.

    If no luck drop me exact link to issue

    Yes. Cache is cleared.

    Hello @aivaraskar

    Very strange!!!

    Are you sure that the two functions are changed in index.php:
    public function raw_woocommerce_price($price) and public function woocommerce_variation_prices($prices_array)

    If Yes! What function do you use to change the price?

    And drop me link to your site

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Suggestion – Rounding Converted Prices…’ is closed to new replies.