0

For future users <?php echo '$' . number_format(( $total['amount'] /100),2); ?> is how.


Following this guide http://kahthong.com/2012/08/programmatically-show-number-items-drupal-commerce-shopping-cart I got the cart item total using

<?php
global $user;
$quantity = 0;
$order = commerce_cart_order_load($user->uid);
if ($order) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $line_items = $wrapper->commerce_line_items;
    $quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
    $total = commerce_line_items_total($line_items);
    $currency = commerce_currency_load($total['currency_code']);
}
print format_plural($quantity, '1 item', '@count items');
?>

however when I try to get the dollar total using <?php print $total; ?>, it just returns 'Array'.

I used Devel on the page, but the cart is just a bunch of markup in ['content']['system_main']['main']['#markup']. What I want is <span class="line-item-total-raw">$106.00</span>, is there a way I can grab that class specifically with php somehow? Or maybe there's another way to go about this.

1 Answer 1

1

You should have it already. That call to "commerce_line_items_total" returns the array:

return array('amount' => $total, 'currency_code' => $currency_code);

Thus you should have the total price at $total['amount'] since you already have $total['currency_code']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.