I'm currently configuring my transactional emails for Magento 2 and since I am in germany and want to ship some parts to a partner inside the EU i can place those orders without calculating taxes for that.

Therefore my EU partners have an own customer group without any tax display.

So make everything clear and don't get in trouble with the Tax institute here in germany i have to declare those orders with an special text inside the email and invoice.pdf.

Is there any way to implement an if-statement to call something like:

if customergroup == EU_Partner then display TEXT ?

Thanks in advance


I found something while searching for a solution.

{{depend order.customer_group_id}} TEXT {{/depend}}

Does this work on Magento 2 and if so, how do i declare the customer_group_id ?

  • are you talking about in email template in backend? – Rakesh Jesadiya Feb 21 '17 at 13:04
  • yes. I want to change the template with a custom variable or block which gets displayed if the customer got a specific group. – Marcel H. Feb 21 '17 at 13:09

We cannot use the if condition like:

{{if order.customer_group_id == 1}}
     <p>Bla Bla Bla</p>

We can find the customer group id in sales_order table. I also notice that the customer group id is a int type.

1) In your case, we can use if and depend directives. However, we need to set a "flag" for our special case to order Object (for example: Magento\Checkout\Model\Type\Onepage::saveOrder()).

For example:

//We need to check if the order has EU customer

In your email, we can check:

{{if order.eu_customer}}
     <p>Bla Bla Bla</p>

2) We can use block technique. For example, insert this block in your template:

{{block class='Magento\\Framework\\View\\Element\\Template' 
area='frontend' template='Vendor_Module::email/specificcustomer/info.phtml' order=$order}}

In your custom template, we can check whatever you want.

<?php if($this->getData('order')->getCustomerGroupId()==1) {
        echo "<p>Bla Bla Bla</p>"; 

See more here: vendor/magento/module-sales/view/frontend/email/shipment_new.html

  • You are my hero. The Block-technique work perfect, thanks alot :) – Marcel H. Feb 21 '17 at 18:18
  • The option #1 worked for me. Many thanks for the input. – medina Aug 6 at 6:25

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.