Amid the COVID-19 outbreak, Folio3 aims to help clinics serve patients with telemedicine effectively.

Development and Configuration of Order Email Coupons in Magento 2

Development and Configuration of Order Email Coupons in Magento 2



E-commerce businesses always needs dynamic rules of marketing to attract and lure their customers. The more the customers visits the sites, the more opportunity for the merchants to sell their products and ultimately, in returns a handsome revenue.

Magento-2 a leading E-commerce platform provides a full flexible and customizable architecture to implement any sort of automation that ultimately leads in generating customer traffic and business.

The automated coupons in order email is one of the marketing tactics of many e commerce businesses and in this blog we will cover the implementation of “order email coupons” within Magento-2 system.

The module “order email coupons” will email new coupon in every order email, to lure customer to re-visit site and shop more.

We will try to cover each and every necessary step of module development and configurations.

For reference, we have attached screen-shots for letting it know, how module need to be configured.


Order Email Coupons - Magento 2 Blog folio3

Order Email Coupons - Magento 2 Blog folio3

Order Email Coupons - Magento 2 Blog folio3

Order Email Coupons - Magento 2 Blog folio3

Order Email Coupons - Magento 2 Blog folio3

Order Email Coupons - Magento 2 Blog folio3




Create new module, at following path:



Create required module files and folder:






We will provide new order email templates for logged-in and guest customers. Add templates code in file:




In order to show the added emailed templates under admin→stores→configuration…

We need to code the following module file:




Create email templates (html) files:

For Guest Customer(s):


For Logged-in Customer(s):


Please insert, the required gift coupon code in each email templates



Create need shopping cart rule under admin→marketing→promotions→cart price rules, with following necessary configurations, also highlighted in screen-shots:

Active: Yes

Coupon: Specific Coupon

(Checked) Use Auto Generation

User per Customer: 1


This rule will be utilized for creating dynamic coupon. The logic will be covered shortly.

Once rule is configured, please save it, copy the rule ID from URL and paste under text field at admin→stores→configuration→folio3→gift coupon→generate rule ID…


Step-7 (final step):

We have almost completed the required module files & folders with configurations.

In this step, we will add event “email_order_set_template_vars_before” at following path, that will be responsible for inserting coupon information at the time of sending order email.



Create observer file:

The observer will check for “Rule ID” and if found, generates dynamic coupon and bind it in order emails.


Please feel free to comment or reach out if you have any questions. If you need any help with customizing your Magento 2 web store, please get in touch with us.


USA408 365 4638


1301 Shoreway Road, Suite 160,

Belmont, CA 94002

Latest From Our Blog

Why the Daily Scrum is NOT a Status Meeting?

February 3, 2020
I am here today to debunk, The Myth “The Daily Scrum is the Status Meeting”. This is a key misconception in the industry and often resu...
Read more

A Complete Guide to Custom Caching in Magento 2...

November 29, 2019
In this blog, I will explain how to create your own cache in Magento 2, and how to read and write data from that custom cache. I hope after reading...
Read more

React Hooks

September 3, 2019
React is a javascript framework for building interactive client side interfaces along with the integration with back-end server. React considers th...
Read more