Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By hmdnawaz on
I want to get the formatted total amount of my cart items.
I used the following code
$order = commerce_cart_order_load($user->uid);
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items = $wrapper->commerce_line_items;
$total = commerce_line_items_total($line_items);
It returns me $4000 instead of $40.00.
I also tried the following code
$total = $wrapper->commerce_order_total->amount->value();
but same result.
On shoping cart page it display $40.00
. How can I get the price in this format?
I want this in commerce way not some custom php like number_format
etc.
Comments
The value returned is in
The value returned is in pennies. Divide $total by 100 and you'll get the value in dollars.
Commerce provides a function
Commerce provides a function for that:
http://www.drupalcontrib.org/api/drupal/contributions!commerce!commerce....
Commerce uses minor units (cents in USD) and converts only for display with the above function.
- Brendan
YEs
Yes used the following code and it is working.
Ahmad Nawaz
Acquia Certified Developer
Email: hmdnawaz@gmail.com
Skype: hmdnawaz