• Resolved matesss123

    (@matesss123)


    Hello,

    We are having problems with rounding of € values in our invoices in the most prominent ‘total’ field, making them integers.
    We were looking into where the value comes from; it looks like the pdf plugin reads the woocommerce total like so:

    jsx
    $totals = apply_filters( 'wpo_wcpdf_raw_order_totals', $this->order->get_order_item_totals(), $this->order );
    

    i.e. only using woocommerce API; and further

    jsx
    add_filter('woocommerce_get_formatted_order_total', function($formatted_total, $self) {
    return $self->get_total();
    }, 10, 2);
    

    got us already rounded value. Probing further, we found that the value is apparently
    stored somewhere, already formatted, since the setter

    php
    public function set_total( $value, $deprecated = '' ) {
    	if ( $deprecated ) {
    		wc_deprecated_argument( 'total_type', '3.0', 'Use dedicated total setter methods instead.' );
    		return $this->legacy_set_total( $value, $deprecated );
    	}
    	$this->set_prop( 'total', wc_format_decimal( $value, wc_get_price_decimals() ) );
    }
    

    either formates the value using wc_format_decimal( $value, wc_get_price_decimals() ) (removal of this line changed nothing)

    or stores the value in metadata like so in the deprecated method:

    php
    	case 'total' :
    			$amount = wc_format_decimal( $amount, wc_get_price_decimals() );
    			$this->set_total( $amount );
    			update_post_meta( $this->get_id(), '_order_total', $amount );
    			break;
    

    But there are no ‘_order_total’ keys in (*order_itemmeta) table. Anyway, we came to the conclusion this behaviour is most likely a bug, since everything else has proper rounding; values in the database (*order_itemmeta) are having the decimal part.

    Thank you for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @matesss123

    Like you spotted we retrieve the totals formatted directly from WooCommerce, if you need them in a different format you can use the wpo_wcpdf_raw_order_totals filter to do you stuff and then return them formatted again.

    So if there’s an issue with rounding it’s most likely WooCommerce related and you should ask for support in their forums.

    Thread Starter matesss123

    (@matesss123)

    Thank you for the advice. Unfortunately, the filter already contained all the data rounded, except for items themselves (items array
    price is not rounded.

    The problem was that woocommerce displays all prices correctly except for invoices; the settings were incorrect after all –
    check that your settings are not cached:
    https://stackoverflow.com/questions/50917494/how-to-disable-rounding-of-prices-on-woocommerce

    in the end we were puzzled by weird behaviour of woocommerce that shows the price correctly everywhere in the UI – cart, order history etc. except for invoices.
    Thank you for time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rounding of €’ is closed to new replies.