I have a custom shipping module and I am trying to execute some information in an email template based on the shipping method chosen. I have tried things like:
{{if order.getShippingDescription() == 'Shipping Method - Shipping Title'}}
<p>{{trans "Works!"}}</p>
{{/if}}
How can I target the shipping method and show information based on that method in the email template?
UPDATE I have tried creating a plugin in Vendor/Module/Plugin/Order/Email/Container/EmailCode.php:
class EmailCode
{
public function beforeSetTemplateVars(\Magento\Sales\Model\Order\Email\Container\Template $subject, array $vars)
{
/** @var Order $order */
$order = $vars['order'];
$method = $order->getShippingMethod();
$vars['shipping_code'] = $method === 'freedelivery_freedelivery';
return [$vars];
}
}
and I added in etc/frontend di.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Model\Order\Email\Container\Template">
<plugin name="email.shipping.code" type="Vendor\Module\Plugin\Order\Email\Container\Template\EmailCode" sortOrder="100"/>
</type>
</config>
and then this in my email template:
{{if shipping_code}}
<p>{{trans "Email Code Works"}}</p>
{{/if}}
And it didn't work. Any help is appreciated!
Thanks, Stan