I have located commerce-order-receipt.html.twig in commerce/order/templates/ and I have copied it to my theme directory, properly overriding it. My basic changes all work.

Now I am trying to figure out how to pass my own variable to it. I can't figured out which hook_preprocess function I need to use in order to do this. I have figured out how the suggestion and original variables were made in commerce_order.module but this has not helped me hook into it and add more variables.

Can someone point me in the right direction?

1 Answer 1


I think this should work, in THEME_NAME.theme add

function THEME_NAME_preprocess_commerce_order_receipt(&$variables) {
  $variables['test'] = "test";

Note: replace THEME_NAME with actual name of theme

Then doing {{ test }} should output "test".

Note: remember to flush all cache to see changes.


Your Answer

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

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