cancel
Showing results for 
Search instead for 
Did you mean: 

How to include text depending on shipping and payment methods in transactional emails?

How to include text depending on shipping and payment methods in transactional emails?

I need to insert in my emails conditional texts depending on shipping and payment methods.

I know how to display shipping method code:

{{var order.getShippingMethod()}}

and payment code:

{{var order.getPayment().getMethodInstance().getCode()}}

There are conditional statements like "if" and "depend" available. But none of them offers comparison to a string, which is necessary to achieve what want. For example this does not work or I am doing it not right?

{{if order.getShippingMethod() == "storepickup"}}
    text1
{{else}}
    text2
{{/if}}

What I was able to do was to add a block that can display what I need

{{block type='core/template' area='frontend' template='custom/email/new/payment.phtml' order=$order}} 

but this way this text is defined outside the email template making maintenance complicated.

 

Is there a way to achieve what I need with existing functionality? Maybe I am able to add some custom variable or method I could use with conditional statement. How to do that?

 

 

7 REPLIES 7

Re: How to include text depending on shipping and payment methods in transactional emails?

Hello @kathdroid 

 

{{block type='core/template' area='frontend' template='custom/email/new/payment.phtml' order=$order}} 

i am not sure what is issue with that

 

Using another way possible in order model you can extends and add new method

public function getShippingData()
{
 ..............................
}

and you can that method into email template 

 

hope it will help you. 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to include text depending on shipping and payment methods in transactional emails?

Hi,

 

I have the same question.  Can anyone explain how to do it?  I have tried:

{{if var shippingMethod == 'shippingcode_shippingcode'}}

 

I am trying to get it to work in Magento 2.3

 

Thanks,

Stan

Re: How to include text depending on shipping and payment methods in transactional emails?

Where did you store your block in the theme directory? I’m trying to return some content depending the payment method.

Re: How to include text depending on shipping and payment methods in transactional emails?

great advice

Re: How to include text depending on shipping and payment methods in transactional emails?

To tailor transactional emails based on shipping and payment methods, ensure a personalized and informative approach. For instance, when communicating with customers who have selected specific shipping methods, such as express delivery, emphasize the expected delivery date and tracking details, ensuring a seamless delivery experience. Likewise, for those who have chosen specific payment methods like Best Portable Basketball Hoops, you can include additional product recommendations, maintenance tips, or exclusive offers related to basketball equipment to enhance their overall purchase satisfaction. By customizing your transactional emails in this manner, you not only provide relevant information but also create opportunities to upsell or cross-sell, ultimately improving customer engagement and boosting sales.

Re: How to include text depending on shipping and payment methods in transactional emails?

To include text in transactional emails based on shipping and payment methods, you can employ dynamic variables within your email templates. For instance, you can use conditional statements that check the chosen shipping and payment methods during order processing and then insert specific text accordingly. Similar to the way larimar, a rare gemstone known for its unique blue and green hues, stands out in the world of minerals, these dynamic variables can make your transactional emails stand out by providing personalized and relevant information to your customers. By tailoring the content based on their choices, you enhance the user experience, providing clarity and transparency regarding their order, shipping, and payment details, ultimately fostering customer satisfaction and loyalty.

Re: How to include text depending on shipping and payment methods in transactional emails?

To include text depending on shipping and payment methods in transactional emails in Magento, here are the steps you can follow:

  1. Create a Template File: Make a new HTML template file that includes the custom text you want to display based on the shipping method. This file should be located at {{magento_root}}\app\code\Vendor\Extension\view\frontend\web\template\shipping-info.html.

  2. Update Layout File: In your Magento file structure, navigate to {{magento_root}}\app\code\Vendor\Extension\view\frontend\layout\checkout_index_index.xml and update the layout file to include your new template.

  3. For more info about Medical Recruitment click here.
  4. Implement JavaScript Logic: You'll need a JavaScript file to handle the logic of displaying the text based on the selected shipping method. Create a JS file at {{magento_root}}\app\code\Vendor\Extension\view\frontend\web\js\view\shipping-info.js and add the necessary code to bind the visibility of your custom text to the selected shipping method.

     
  5. Deploy Changes: Once the files are in place and edited accordingly, run the Magento deploy commands to compile and flush the cache, ensuring your changes take effect.

For specific instructions and code snippets, the details provided by MageComp are particularly useful​.