Multiply Function Results in PHP

I’m still beginner in PHP. I have a small problem, I would to multiply the value get_formatted_order_total(); with 3.75 and what I did is

get_formatted_order_total(); * 3.75

but It didn’t work.

Read More

here is the code

<li class="total">
    <?php _e('Total:', 'woocommerce'); ?>
    <strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>

Thank You

Related posts

Leave a Reply

3 comments

  1. The problem is, that get_formatted_order_total() returns a string, formatted for display on the website, not a numerical value that you can use for calculation.

    The unformatted value is available as a member variable of the Order class, so

    echo $order->order_total * 3.75;
    

    should work.

    In order to understand this, look at the source code of Woocommerce: Order::get_formatted_order_total() simply formats Order::order_total with a helper function woocommerce_price():

    /** Gets order total - formatted for display */
    function get_formatted_order_total() {
        $formatted_total = woocommerce_price( $this->order_total );
    
        return apply_filters( 'woocommerce_get_formatted_order_total', $formatted_total, $this );
    }