How can I get the customer name from the billing information variable in the commerce-order-receipt.twig.html template file used in the order confirmation e-mail?

  • How about debugging it? You can learn how here What is easiest way to debug variables in nodes, views, blocks and page twig templates?
    – No Sssweat
    Commented Jun 23, 2018 at 6:31
  • The array or the object will be printed in the email and it will not be controlled.
    – user86344
    Commented Jun 25, 2018 at 19:21
  • 1
    Otherwise, you could use a preprocess and do your debuging there. Example: in your_theme.theme add function YOUR_THEME_preprocess_commerce_order_receipt(&$variables) { kint($variables['billing_information']); }
    – No Sssweat
    Commented Jun 25, 2018 at 20:05

1 Answer 1


First, you have to create function as @NoSSweat suggested (thanks for the hint) and from it get it like:

function hook_preprocess_commerce_order_receipt(&$variables)
  $givenName = $variables['billing_information']['#profile']->get('address')[0]->given_name;
  $variables['given_name'] = $givenName;

(was incredible hard to figure this out :) ) Field name for last name would be "family_name". Checkout the file:


for other available fields.

I added this function to my module, but adding it to theme file should also work.

That way you are assigning variable which is now available in twig template so you can print it simple as:

{{ given_name }}

Don't forget to clear the cache.

Your Answer

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