Zend certified PHP/Magento developer

Magento 2 email_order_set_template_vars_before observer triggers only when I resend email in the admin

I created a new template var using email_order_set_template_vars_before observer and it works when I send email new order through the Magento admin. But it does not trigger when new order is placed. Here is my code.

events.xml

< ?xml version="1.0"?>



    
        
        
    


SaveEmailVariables.php

namespace FoobarShipperHQDeliveryDateObserver;
use MagentoFrameworkEventObserverInterface;

class SaveEmailVariables implements ObserverInterface
{
    private $carrierGroupHelper;
    public function __construct(ShipperHQShipperHelperCarrierGroup $carrierGroupHelper) {
        $this->carrierGroupHelper = $carrierGroupHelper;
    }
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $transport = $observer->getEvent()->getTransport();
        $order = $transport->getOrder();
        $orderDetail = $this->carrierGroupHelper->getOrderCarrierGroupInfo($order->getId());

        if($order != null)
        {
            foreach ($orderDetail as $orderData) {
                $ddate = array_key_exists('delivery_date', $orderData) ? $orderData['delivery_date'] : '';

                $transport['cddeliveryDate'] = date( 'F d, Y', strtotime( $ddate ) );

            }
        }
    }
}```