I would like to add conditional text into my confirmation emails in magento 2. As in:
{{if order contains item }}
text
{{else order doesnt contain item}}
other text
At the moment I am aware that the email displays items with this:
{{layout handle="sales_email_order_items" order=$order area="frontend"}}
Is this configurable?
Thanks
For this purpose, i use an external phtml template :
in the design area, create the module you want to modify, I your case, it's Magento_Sales
in templates directory add /email/your-template.phtml :
Magento_Sales
/email
the-email-to-modify.html
/templates
/email
your-template.phtml
In your-template.phtml, use php as usuale
<?php
//your code, with the test
// to get the variables use:
$myvar=$this->getData('myvar');
...?>
<p>Hello <?php echo $myvar; ?></p>
In the HTML template the-email-to-modify.html, you can include your template and send any variables you want, here the customer name :
<h1>The title</h1>
{{block class='Magento\\Framework\\View\\Element\\Template'
myvar=$customer.name area='frontend'
template='Magento_Sales::email/your-template.phtml'}}
et voila ^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.