HI guys,

i had a need to print separate order total in my theme files so after a bit research i got this code that completely works fine:

<?php global $user;
        $order = commerce_cart_order_load($user->uid);
        $wrapper = entity_metadata_wrapper('commerce_order', $order);
        // Order total. 
        $order_total = $wrapper->commerce_order_total->value();
        $amount = commerce_currency_amount_to_decimal($order_total['amount'], $order_total['currency_code']);
        // Load the currency object.
        $currency = commerce_currency_load($order_total['currency_code']);
        $order_total = number_format(commerce_currency_round($amount, $currency), $currency['decimals'], $currency['decimal_separator'],         $currency['thousands_separator']);
        echo $order_total;
?>

Comments

vm’s picture

The question is better served in the 'module development and code questions' forum. Please edit the opening post and move it. Thank you.

DerekDigital’s picture

thank you so much for posting this!! I am working on a dynamic cart separate from main style and needed the total price and number of items in the cart. What you posted solved the hard half of the problem and now searching and experimenting to get the other half. If you or anyone else has a solution to echoing the total number of items I would greatly appreciate it!

sprite’s picture

Glomming into to thread to add to notes list.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

DerekDigital’s picture

the order total and total number of items for an order are a common combination and related to eachother... I am posting a solution I got to work

DerekDigital’s picture

Here is the code that I used to display number of items...

   $wrapper  = entity_metadata_wrapper('commerce_order', $order);
    $quantity = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());