Multiply Function Results in PHP

前端 未结 3 922
渐次进展
渐次进展 2021-01-25 16:00

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_form         


        
相关标签:
3条回答
  • 2021-01-25 16:29

    Try so

    echo get_formatted_order_total() * 3.75;
    

    Without ; after (). ; should be after 3.75

    0 讨论(0)
  • 2021-01-25 16:30

    Semi-colons go at the end of an instruction. Since this is all one instruction, you need to move the semi-colon to the end of the line:

    echo get_formatted_order_total() * 3.75;
    

    Example: http://codepad.org/HH3RLZCR

    0 讨论(0)
  • 2021-01-25 16:41

    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 );
    }
    
    0 讨论(0)
提交回复
热议问题