Does anyone know of a way or an extension that will let you send different email order confirmations based on the shipping method?
If a customer chooses to collect in store the information on the email needs to be different than if they have chosen next day delivery
Hi @miller75
Add the variables to the template by creating a plugin for Magento\Sales\Model\Order\Email\Container\Template's setTemplateVars method. For example:
class ShippingVars { public function beforeSetTemplateVars(\Magento\Sales\Model\Order\Email\Container\Template $subject, array $vars) { /** @var Order $order */ $order = $vars['order']; $method = $order->getShippingMethod(); $vars['is_pickup'] = $method === 'flatrate_flatrate'; return [$vars]; } }
In the email template:
{{if is_pickup}} <p>Your order is ready for Pickup!</p> {{else}} <p>Your order is on the road!</p> {{/if}}
It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!
Hi, Bhanu Periwal.
I try to use your code, but it not help me.
Can you say where my error?
I add this code
class ShippingVars { public function beforeSetTemplateVars(\Magento\Sales\Model\Order\Email\Container\Template $subject, array $vars) { /** @var Order $order */ $order = $vars['order']; $method = $order->getShippingMethod(); $vars['is_pickup'] = $method === 'flatrate_flatrate'; return [$vars]; }
to the /vendor/magento/module-sales/Model/Order/Email/Container/Template.php
and now - all file is
namespace Magento\Sales\Model\Order\Email\Container;
class ShippingVars
{
public function beforeSetTemplateVars(\Magento\Sales\Model\Order\Email\Container\Template $subject, array $vars)
{
/** @var Order $order */
$order = $vars['order'];
$method = $order->getShippingMethod();
$vars['is_pickup'] = $method === 'flatrate_flatrate';
return [$vars];
}
}
class Template
{
/**
* @var array
*/
protected $vars;
/**
* @var array
*/
protected $options;
/**
* @var string
*/
protected $templateId;
/**
* @var int
*/
protected $id;
/**
* Set email template variables
*
* @param array $vars
* @return void
*/
public function setTemplateVars(array $vars)
{
$this->vars = $vars;
}
/**
* Set email template options
*
* @param array $options
* @return void
*/
public function setTemplateOptions(array $options)
{
$this->options = $options;
}
/**
* Get email template variables
*
* @return array
*/
public function getTemplateVars()
{
return $this->vars;
}
/**
* Get email template options
*
* @return array
*/
public function getTemplateOptions()
{
return $this->options;
}
/**
* Set email template id
*
* @param int $id
* @return void
*/
public function setTemplateId($id)
{
$this->id = $id;
}
/**
* Get email template id
*
* @return int
*/
public function getTemplateId()
{
return $this->id;
}
}
And
{{if is_pickup}} <p>Your order is ready for Pickup!</p> {{else}} <p>Your order is on the road!</p> {{/if}}
to the email template.