I am trying to get the the shipping method using observer but I cant seem to get it to work, this is what I have for the ShippingTypeEmail.php
<?php
namespace vendor\Emails\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Order;
class ShippingTypeEmail implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$shpvar =''
$order = $observer->getEvent()->getOrder();
$ShpMethod = $order->getShippingMethod();
if($ShpMethod == 'flatrate_flatrate'){
$shpvar = 'flat'
}else{
$shpvar = 'collect'
}
}
}
Then I am using {{var shpvar|raw}}
on the template
my event.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<event name="email_order_set_template_vars_before">
<observer name="vendor_emails_variable_order" instance="vendor\Emails\Observer\ShippingTypeEmail" />
</event>
</config>