0

how to set the weekday Monday, Tuesday, Wednesday, Thursday etc in created_at_formatted in order email

example: Placed on 23.06.2022, 12:00:19

to set

Placed on: Friday, 24.06.2022

{{trans 'Placed on %created_at' created_at=$created_at_formatted |raw}}

1 Answer 1

0

You can create a observer to the event email_order_set_template_vars_before.

In the observer replace created_at_formatted in transportObject with your custom format

// use __constructor instead
$timezone = \Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
$locale   = \Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Magento\Framework\Locale\ResolverInterface::class)
    ->getLocale();

$localeDate = $timezone->date(new \DateTime($order->getCreatedAt()), new \DateTimeZone('UTC')), $locale);

// you can get order and transportObject from observer
// like $observer->getEvent()->getData('order');

$transportObject->setData('created_at_formatted', $localeDate->format('l, d.m.Y'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.