Since Magento 2.3.4 email variable usage was deprecated. See: https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/templates/template-email-migration.html

But we are using a email variable to load a custom php template, that loads specific values based on the payment method and customer group of the customer.

We load it at the moment like:

{{block class="Magento\Framework\View\Element\Template" order=$order name="order_payment" template="Magento_Sales::email/paymentmethod.phtml" area="frontend"}}

And inside the paymentmethod.phtml we load the following php values, but these will not work anymore. Because it is not pushing the order anymore to the paymentmethod.phtml.

$order = $this->getData('order');
$orderid = $order->getId();
$payment = $order->getPayment();
$method = $payment->getMethodInstance();
$methodTitle = $method->getTitle();

But this will not work anymore in 2.4.4, so we need to modify this.

How can we still load this custom php, that checks the payment method and customer group of the customer and then load a specific text line?

1 Answer 1


In your email template you need to use

{{block class="..." order_id=$order_id name="..." template="..." area="frontend"}}

I suggest to create additional block class instead of use Magento\Framework\View\Element\Template and inject \Magento\Sales\Api\OrderRepositoryInterface or you can try to reuse \Magento\Sales\Block\Order\Email\Items just for receive order instance (for order and related blocks for other sales entities).

With block \Magento\Sales\Block\Order\Email\Items you can use following in your template:

$order = $block->getOrder();
$orderid = $order->getId();
$payment = $order->getPayment();
$method = $payment->getMethodInstance();
$methodTitle = $method->getTitle();
  • Thanks a lot! Works perfect. Any idea how to get the customer first name in the e-mail? The old method does not work anymore: {{trans "%name," name=$order.getBillingAddress().getFirstname()}}
    – JGeer
    Aug 6, 2022 at 9:51
  • 1
    You need to create observer for event email_order_set_template_vars_before and extend transportObject data. Just add customer_firstname into order_data and use like $order_data.customer_firstname. Aug 6, 2022 at 10:46
  • Thanks again! Last question, any idea how to solve my latest question? magento.stackexchange.com/questions/358609/…
    – JGeer
    Aug 6, 2022 at 14:24

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.