How to add coupon, discount or promo code to Magento 2 store?

Coupon codes are an integral part of most promotions, discounts, and special offers. So today, we will show you how to create Magento 2 coupon code programmatically and configure it. Let’s start.

How to Create a Coupon Code in Magento 2?

To create a Magento 2 coupon code, you need to set up a new cart price rule that will be used to calculate the discount with the Magento 2 coupon code you create. For this, go to Marketing > Promotions > Cart Price Rules, click Add New Rule, and open the Rule Information section. In the Coupon dropdown, choose Specific Coupon and add your Magento 2 coupon code or use auto-generation.

How to Generate One Coupon Code?

Step 1. In Magento 2 to create coupon code programmatically you need to create a new cart price rule and set it up in Marketing > Promotions > Cart Price Rules.

Generating single coupon in Magento 2 p1

Step 2. Then open the Rule Information section and choose Specific Coupon in the Coupon dropdown.

Generating single coupon in Magento 2 p1

Step 3. Enter the needed value in the field Coupon Code. The required format is determined by system configuration.

Step 4. Set the limitation of coupon use in the Uses per Coupon and Uses per Customer fields. Or leave them blank for the unlimited number of uses.

Step 5. Specify the period when this coupon can be used.

Step 6. Configure the rest of the cart price rule and save the changes. Refresh the cache and test the rule work on the frontend.

How to Create a Batch of Coupons?

If you need to generate a large number of coupons, for example, 100 or more, you can use an auto-generation tool. For this, you also need to create a new cart price rule and go to the Rule Information section, then do the following steps:

Step 1. Select the Use Auto Generation checkbox under the Coupon Code field

Step 2. Specify how many times each customer can use the coupon in the Uses per Customer field.

Step 3. Then you need to scroll down to the Manage Coupon Codes section and specify how many Magento 2 coupon codes you want to add.

Step 4. Enter the number of coupons you need to generate in the Coupons Qty field.

Step 5. Choose Alphanumeric, Alphabetical, or Numeric format in the Code Format dropdown.

Step 6. If you need, you can also set up the Code Prefix, Code Suffix, and Dash Every X Characters fields.

Step 7. Click on the Generate button.

Step 8. Finish the cart price rule configurations and save the changes.

Provide the registered users and guest visitors with the ability to use several discount coupons simultaneously with the extension Multiple Coupons for Magento 2.

How to export created magento discount codes?

Say, you need to inform affiliates, sales representatives, or offline points of sales about currently active discount coupons. Or vice versa, you need to import coupons gathered from your affiliates. And it doesn't seem like a problem if you have 1 or 2 codes, but what if there is a 100? Our Generate and Import Coupons extension will help you manage both situations. It allows you to import codes from the CSV file, or export them to the CSV or XML files in one click. Moreover, it has a smart coupon generation algorithm that lets you use templates for codes. For example, the Spring_LLDDD template will generate codes with 2 random letters and 3 digits, and it will look like Spring_PA237.

How to configure magento promo codes?

The configurations control the length and format of auto-generated coupons. You can set Numeric, Alphabetical, or Alphanumeric format, use the dash to make code easier to read. Let’s see how to configure coupon codes.

Step 1. Navigate to Stores > Settings > Configuration.

Step 2. Open the Customers tab and choose Promotions.

Step 3. Expand the Auto Generated Specific Coupon Codes section.

Step 4. Enter the number of code symbols in the Code Length field.

Step 5. Choose the needed format from the Code Format dropdown.

Step 6. If you want to add a prefix or suffix to your code, enter the needed value in the corresponding fields.

Step 7. To add separators to your code, specify the number of characters between each dash in the Dash Every X Characters field.

Step 8. Save the changes.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.