I have this order at /admin/commerce/orders/oid/view

By default, the order won't display the user's email nor username, so I wanted to know how to access them and printed them out.

I created a tpl file called: page--admin--commerce--orders.tpl.php and typed into it:

print "<pre>";  
$vars = get_defined_vars();
print "</pre>";

I got this result (it's trimmed, but you can read that the uid is 76 -there's no name though-, and the user's email is demo@example.com):

    [template_file] => themes/seven/page--admin--commerce--orders.tpl.php
    [variables] => Array
            [page] => Array
                    [#show_messages] => 1
                    [#theme] => page
                    [content] => Array
                            [devel_execute_php] => Array
                                    [execute] => Array
                                            [#type] => fieldset
                                            [#title] => Execute PHP Code
                                            [#collapsible] => 1
                                            [#collapsed] => 1

                            [system_main] => Array
                                    [commerce_order] => Array
                                            [2340] => Array
                                                    [commerce_line_items] => Array
                                                            [#theme] => field
                                                            [#weight] => 0
                                                            [#title] => Line items
                                                            [#access] => 1
                                                            [#label_display] => hidden
                                                            [#view_mode] => administrator
                                                            [#language] => und
                                                            [#field_name] => commerce_line_items
                                                            [#field_type] => commerce_line_item_reference
                                                            [#field_translatable] => 0
                                                            [#entity_type] => commerce_order
                                                            [#bundle] => commerce_order
                                                            [#object] => stdClass Object
                                                                    [order_number] => 2340
                                                                    [revision_id] => 7766
                                                                    [revision_uid] => 1
                                                                    [mail] => demo@example.com
                                                                    [status] => pending
                                                                    [log] => 
                                                                    [revision_timestamp] => 1418617139
                                                                    [revision_hostname] =>
                                                                    [data] => Array

                                                                    [order_id] => 2340
                                                                    [type] => commerce_order
                                                                    [uid] => 76
                                                                    [created] => 1409009029
                                                                    [changed] => 1418617139
                                                                    [hostname] =>
                                                                    [commerce_line_items] => Array

After reading-some-information-around-the web, and the book Drupal 7 Module Development (chapters 3 and 4), I tried (unsuccessfully) all these:

print render($content['#object']);
print render($content['#object']['mail']);
print render($content['#object']['uid']);
print render($variables['content']['#object']['uid']);
echo render($content['content']['#object']['uid']);
print render($variables['page']['content']['system_main']['commerce_order']['2340']['commerce_line_items']['#object->mail']);

1 Answer 1



print render(commerce_order_load(2340));

I'm thinking the user id will be something like

$order = commerce_order_load(2340);

from there you can do

$customer = user_load($order['uid']);
print render($customer->name);
print render($customer->email);

But try to print commerce_order_load and take a look at that output first.

  • Thanks for your reply! commerce_oredr_load() is getting me an error Catchable fatal error: Object of class stdClass could not be converted to string in .../themes/seven/page--admin--commerce--orders.tpl.php on line 9 (the function line). The thing is that the documentation (drupalcontrib.org/api/drupal/…) says it should be the order id! (like: commerce_order_load($order_id)). I've tried with and without quotes.
    – Rosamunda
    Dec 23, 2014 at 17:29
  • That is why I said 2340, because based on the output you posted the order id is 2340. Do you have the devel module installed by chance? It includes a module that allows you to run php code from inside Drupal. It is a great tool for things like this. Try commerce_order_load(2340)->uid
    – n30r3b3l
    Dec 23, 2014 at 17:42
  • Yes, I've tried echo commerce_order_load(2340)->uid; and printed out 76 (which is the uid)... The order number is correct...
    – Rosamunda
    Dec 23, 2014 at 17:54
  • So you know how to get the uid. Once you have the uid to display the email it is user_load($uid)->email. I just realized though, that with the default view that the commerce module comes with, you can add the email field for the user. Which would be much easier than creating a custom tpl
    – n30r3b3l
    Dec 23, 2014 at 18:52
  • Thanks! (the only thing left is to replace 2340 with the order id, is there a way to do that within the tpl file?). As my ultimate goal is to completely change the way the order looks like, I think I'm going to need a tpl sooner or later...
    – Rosamunda
    Dec 23, 2014 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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