How to set up coupons for Magento 2

Last updated at:

You will learn

Magento supports Shopping Cart Price Rules that you can use to apply discounts to your customer's order. Coupon codes can be created for existing price rules, so that your shoppers can easily apply a discount code during the checkout process.

Klaviyo's Coupons allow Magento 2 stores to do the following:

  • Create new coupons in Klaviyo associated with pre-existing price rules in Magento.
  • Include dynamic coupons within flow emails, so each recipient receives a unique code.

This guide will walk you through creating a Magento 2 coupon in Klaviyo in two steps:

  1. Setup a price rule in Magento 2
  2. Create the coupon in Klaviyo

Dynamic coupon codes are not currently available when sending campaign emails. Sending unique coupon codes in a campaign would require generating thousands of codes per second. Klaviyo cannot guarantee a specific Magento server's rate-limiting settings will not impact the generation of dynamic coupons at this volume and velocity. Due to this, dynamic coupons are only available when sending flow emails.

This guide will walk you through setting up Magento 2 coupons


As a prerequisite, make sure that you've enabled the Magento 2 integration in Klaviyo and installed the Klaviyo extension in Magento.

Setup a Price Rule in Magento 2

From your Magento 2 store navigate to Marketing > Cart Price Rule.


Create a price rule by clicking Add New Rule.
Fill in the Rule Information:

  • Rule Name: the name of the price rule in Magento 2.
  • Active: choose Yes. If Yes is not selected, the coupon will not work.
  • Websites: if you only have one Magento store, choose the name of your website. If you have multiple Magento stores, choose the store the coupon is associated with.
  • Customer Groups: choose NOT LOGGED IN, or choose a different customer group.
  • Coupon: choose Specific Coupon from the drop-down.
  • Coupon Code: you don’t need to enter anything in this field; Klaviyo will automatically generate coupon codes for you.
  • Use Auto Generation: you must enable this field. If you don’t enable this field, Klaviyo will not be able to generate coupon codes. 
  • Uses per Coupon: the number of times your coupon can be used; usually this value will be 1.
  • Uses per Customer: the number of times your coupon can be used per customers; usually this value will be 1.
  • From -- To: enter the date range during which the coupon will be valid; the To date will be the coupon's expiration date.


At the bottom of your New Cart Price Rule screen, you’ll see additional settings. Conditions, Actions, and Labels settings are optional and will impact how coupons are applied in your Magento 2 store; these won’t affect Klaviyo Coupon generation.


Manage Coupon codes: these settings don’t need to be filled in. When Klaviyo generates coupon codes, those codes will appear in this section. 

When you’re finished, click Save on the upper right corner of your screen.


View your list of Magento 2 coupons. Each Magento 2 coupon is associated with an ID. Take note of the ID of the coupon you created. You’ll need it in the next step.


Create a Magento Coupon in Klaviyo

Next, you’ll create a coupon in Klaviyo. For this step, you need the ID associated with the price rule you just created in your Magento 2 account. A new coupon created in Klaviyo must reference a pre-existing Price Rule in Magento.

Navigate to your Coupons section and select Magento 2 Coupons.

Click Add Coupon to create a new coupon. Mag2Coupons11b.png

Enter a name for your coupon in the Coupon Name field, and enter the Magento 2 price rule ID associated with this coupon. Again, you need to have created a price rule in Magento 2 before you create a coupon in Klaviyo. Head back to your Magento 2 account if you need to reference this ID number again. 

When you're finished click Add Coupon.


You’ve created your new coupon.

Use a Magento Coupon in a Flow Email

Once a coupon is created, you can insert it into a flow email. Note that you can only use one coupon code per email. Also, you can display the same coupon code in multiple places, but you cannot use multiple codes.  

To insert a coupon into your flow email, use the following placeholder variable:

{% coupon_code 'CouponName' %}.

Replace CouponName with the name of the coupon. For example:


Using Coupons in SMS Flow Messages

Unique coupons are also available for your SMS/MMS messages in flows. Generate the codes just like you would for email. Then, use the template tag below to add the coupon code to your SMS or MMS message:

{% coupon_code 'CouponName' %}.

In the snippet, change CouponName to the name of the coupon you want and add it into the message.


You can only use one coupon code per SMS message. If you try to use more than one, you will receive the following error. 


Was this article helpful?
80 out of 111 found this helpful