• Resolved jandelay

    (@jandelay)


    Hello,

    my currency switcher needs 3 decimals in order to calculate the price correctly, since i have a lot of products with a small prices like 0,045.

    However, if i have 3 decimals set up, the total price also will display 3 decimals. Example: 0,045 * 1000 = 45.000€. (three decimals)
    If i change the decimals to 2, it only takes 2 decimals into the calculation, therefore: 0,04 * 1000 = 40.00€

    But i want it to calculate with 3 decimals (0,045) and the price that is displayed to the customer to be 45.00€ (two decimals)

    I know that there is a setting within WooCommerce, where i can change the decimals: https://imgur.com/a/bSTcBC0

    But as i told you, if i do that, the price gets calculated false.

    So my idea is to add a filter. I want to keep the decimals in the settings of my currency switcher plugin to 3 (which will calculate the price correctly) and then in my functions.php i want to add a filter that will only show the price with 2 decimals instead of 3.

    Unfortunately my programming skills are very limited, i tried to hook wc_price_args to control the formatting. But it doesnt work.

    add_filter('wc_price_args', function($args) {
      // Always format prices to two decimals
      $args['decimals'] = 2;
      return $args;
    }, 10);

    I would be very grateful if someone could help ??

    Thank you in advance.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Change price decimals in functions.php’ is closed to new replies.