How to add if condition in transactional emails

Have you ever wonder or faced situation where you want to add condition block in transactional email? If yes, we have solution for you. Please go through all the possible solution.

Solution 1: use depend tag which check whether that variable has some value or not.

{{depend shipping_company}}
  <tr>
    <td>
      <table>
        <tr>
           <td>
               <h1>Your shipment is on its way.</h1>
           </td>
           <td>
             <img src="{{media url=wysiwyg/logo-dpd.png}}" alt="" />
           </td>
         </tr>
        </table>
     </td>
   </tr>
 {{/depend}}

If you have some advance condition using block technique.

Solution 2: Block technique for advance conditioning

{{block class='Magento\\Framework\\View\\Element\\Template' 
               area='frontend' template='Codedecorator_Learn::email/shipping_company.phtml' shipping_company=$shipping_company}}

Add above block code in your email template and create new phtml template in your plugin like following:

<?php 
        if($block->getData('shipping_company') !='dpd') {
                echo $block->getData('shipping_company'); 
        }
?>

I hope above this post help you in your task.

Happy Coding 🙂

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

Leave a Reply

Your email address will not be published.