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

7 best Website performance test tips to increas...

March 6, 2019
Website Performance and speed are considered major elements that drive user experiences and pave way for business growth, especially in the ecommer...
Read more

Amazon DynamoDB, from development to deployment

March 4, 2019
Amazon DynamoDB is a fully managed proprietary NoSQL database service that supports key-value and document data structures and is offered by Amazon...
Read more

Using LESS in React without Ejecting

February 28, 2019
I recently came across a problem while configuring my React application to use LESS styling. The misleading information on the web made the solutio...
Read more