Change Store Email Addresses - Mageplaza
How to setup Buy X Get Y Free in Magento 2
Vinh Jacker | 05-14-2016
Free Gifts are always a common method of motivating spending, and if you want to sell in bulk, the Buy X Get Y Free promotion is a suitable approach. It is extremely useful if you want to promote particular items, clear stocks quickly, or are a wholesaler.
Setup Buy X Get Y Free is one of the actions when you create the Shopping Cart Price Rule, in which customers can receive an amount of discount (Y is the discount amount) if there is the quantity of products (X) you have set before and all conditions of the rule are met. The format of the discount will appear as the following:
Buy X quantity of product, get Y quantity for free.
In this tutorial, I will help you set up the Buy X Get Y Free promotion in Magento 2 with practical examples.
5 Steps to Set up Buy X Get Y Free:
Step 1: Set the Cart Price Rule
You can complete this step by following the topic: Create a Cart Price Rule
Step 2: Set the Conditions
-
On the Conditions tab, appears the statement “If ALL of these conditions are TRUE”
The statement has two bold links “All”and “TRUE” to edit.
- Click on the ALL link, ALL and ANY options are available.
- Click on the TRUE link, TRUE and FALSE options are available.
-
Leave the conditions blank if you want to apply for all products

- Click on
Addicon to set conditions for the rule:- Product attribute combination
- Product subselection
- Conditions combination
- Cart Attribute

- Continue tapping the
Addicon and follow these steps again to add as many conditions of the cart price rule as you need - If you want to delete any statement, just hit the
Deleteicon to remove it.
Step 3: Set the Actions
- In the settings of Cart Price Rule, choose the
Actions. - Choose Buy X get Y free (discount amount is Y) in the
Applyfield. - Enter the number for
Discount Amount. Must be less than or equal to Discount Qty Step, or the rule will not apply. - Limit the quantity discount that is applied by setting the
Maximum Qty Discount is Appliedto1, for example, this is the number of items that the discount can be applied on. - Set the required products customers need to add to his cart in the
Discount Qty Step (Buy X)field. Must be at least 1.
⚠️ The rule fails silently if Y is larger than X: Magento discards the rule entirely when Discount Amount (Y) is greater than Discount Qty Step (X), or when Discount Qty Step is left at 0. No error appears in the admin, the rule saves normally — it simply never applies in the cart. This means a “Buy 1, Get 2 Free” promotion cannot be built with this rule type. A valid setup always satisfies Y ≤ X:
| Promotion | Discount Qty Step (X) | Discount Amount (Y) | Works? |
|---|---|---|---|
| Buy 3, get 1 free | 3 | 1 | ✅ |
| Buy 2, get 2 free | 2 | 2 | ✅ |
| Buy 1, get 2 free | 1 | 2 | ❌ never applies |
| Any | 0 | any | ❌ never applies |
- Discard subsequent rules: Set to Yes to stop Magento from applying any lower-priority rule to the matched items.
- Apply to Shipping Amount: Leave at No for a standard Buy X Get Y promotion.
- Free Shipping: No, For matching items only, or For shipment with matching items.
Note: Magento evaluates cart price rules in Priority order (Rule Information tab; a lower number runs first). Buy X Get Y calculates the value of the free items from the price after any earlier rule has already discounted the item — so a 20% off rule running first makes each free item worth 20% less than list price. If a Buy X Get Y promotion is not producing the discount you expect, check whether an earlier rule set Discard subsequent rules to Yes, which stops your rule from running at all.
Step 4: Set the Labels
- Choose
Labelstab. - Under the
Default Labelsection, insert the text in theDefault Rule Label for All Store Views. - Under the Store View Specific Labels, set the label for each store view,

Step 5: Apply the Rule
Click Save Rule to enable the rule.
As usual, the new rule will be available in an hour. In addition, you should test it correctly to ensure that it is perfect.
Examples of Buy X Get Y Free
Now, let’s see how it works in reality via these 4 examples:
Example 1:
If you offer the promotion: Buy 3 Get 1 Free with no maximum of free items allowed, we can set up the cart price rule like the following:
Apply: Buy X get Y free (discount amount is Y)Discount amount: 1Maximum Quantity Discount is Applied: 0Discount Qty Step (Buy X): 3

The maximum applies to each cart line, not to the whole cart.
To cap the total cost across an entire order, use Uses per Coupon or Uses per Customer on the Rule Information tab instead.
Learn more:How to create Coupon Codes in Magento 2 for special offers
Example 2:
If you offer the promotion: Buy 7 Get 3 Free with a maximum of 6 free items, you can apply the formula below to calculate the correct value for the Maximum Quantity Discount.
Formula = (X+Y) * (M/Y)
Where
- X = The number of items the customer must purchase to get the discount.
- Y = The number of items the customer will receive for free
- M = Maximum number of free items allowed
So we have:
- X = 7
- Y = 3
- M = 6
Using the above formula, we can determine exactly the maximum quantity of discount that can be applied when the condition is satisfied:
Maximum Qty Discount = (7+3) * (6/3) = 20
So we set up buy 7 get 3 free as the following:
Apply: Buy X get Y free (discount amount is Y)Discount amount: 3Maximum Quantity Discount is Applied: 20Discount Qty Step (Buy X): 7

Example 3:
In case you want to limit the free product to categories A, B, and C, set the actions as below:
If ALL of these conditions are True:
Category is one of A, B, C
For example: To limit the free product to categories 26, 15, 18, you need to set the actions as below picture:

Example 4:
Conditions and actions do two different jobs, and mixing them up is the most common mistake with this rule: The Conditions tab decides whether the cart qualifies for the rule at all. The Actions tab decides which items in that cart receive the discount. Neither tab selects a gift product. Buy X Get Y always discounts units of the same product the customer already added, so a SKU condition narrows the rule down — it never makes a different SKU free.
Example: To run the promotion only on products in categories A, B and C, and to give the free units only on SKUs D123, E123 and F123:
- On the Conditions tab, set If ALL of these conditions are TRUE → Category is one of A, B, C.
- On the Actions tab, under Apply the rule only to cart items matching the following conditions, set
If ALL of these conditions are TRUE→SKU is one of D123, E123, F123. A customer who buys enough units of D123 now gets free units of D123. Buying D123 does not make E123 free — each SKU earns its own free units.
You can limit the free items from any category A, B, C, and receive the free items from SKUs D786, E876, and F187 by setting the below action:
For example: To receive the free item from SKUs 24-MB01 and 24-MBO4, you need to set the rule as below image:

- Click to the
Save and Continue Editbutton to edit the rule as you expect.
What the native Buy X Get Y rule cannot do
It cannot give away a different product:
The rule discounts units of the same product the customer already added. There is no field for a gift SKU, and conditions do not create one — they only filter which products the rule runs on. A “buy a shirt, get socks free” promotion is not possible with this rule type. For that, see How to give a free product with the purchase of another product in Magento 2.
X and Y must sit on the same cart line:
Magento counts quantity per cart line item, not per product across the cart. The same product can occupy two separate lines — a configurable product bought in two sizes, or a simple product added twice with different custom options — and those lines are counted independently. A customer running a Buy 3, Get 1 Free promotion who adds 2 shirts in size S and 2 shirts in size M has 4 shirts in the cart, but no free item: neither line reaches 3 on its own.
The free items are always 100% off:
Buy X Get Y cannot give a partial discount on the Y items — it removes their full price. A promotion such as “buy 2, get the third at 50% off” has to be built with Percent of product price discount instead, using this conversion:
Percent = (target discount × Y) ÷ (X + Y)
For buy 2, get the third at 50% off: (50 × 1) ÷ 3 = 16.67.
Set Apply to Percent of product price discount, Discount Amount to 16.67, and Discount Qty Step to 3. Three items at $100 are then discounted by $50 in total — the same amount the customer would save on a half-price third item. Note that the saving is spread evenly across all three lines rather than shown against one item, and that percentages which do not divide evenly leave a rounding difference of a few cents.
Other promotion types you can set up in Magento 2
Buy X Get Y is one of four discount types available on the Actions tab. If it is not the right fit, one of these rules probably is:
| What you want to run | How to set it up |
|---|---|
| A percentage or fixed amount off selected products | Cart price rules in Magento 2 |
| $5 off once the cart reaches $50 | Discount with minimum purchase |
| Free delivery when conditions are met | Free shipping promotions |
| An automatic discount with no coupon, shown on category and product pages | Catalog price rules |
| A temporary lower price on selected products | Special price in Magento 2 |
| A fixed selling price, or cheaper unit prices at higher quantities | Advanced pricing and tier prices |
| Single or bulk coupon codes for any of the above | Create coupon codes in Magento 2 |
Related reading:
- How to give a free product with the purchase of another product
- Magento 2 catalog price rules not working: how to fix it
- Limited time offers: the eCommerce urgency trick
FAQs
1. What is the difference between Buy X Get Y Free and Cart Price Rules?
The main difference between “Buy X Get Y Free” and “Cart Price Rules” in Magento 2 is their application. “Buy X Get Y Free” gives a free item (Y) when a customer buys a certain amount of another item (X), promoting specific product purchases. Cart Price Rules are more versatile, offering various discounts like percentage off, fixed amount off, or free shipping, applied to the entire cart based on different conditions. This allows for a broader range of promotional strategies and customer incentives.
2. Can I combine Buy X Get Y Free with other promotions?
Yes, you can combine “Buy X Get Y Free” with other promotions in Magento 2. However, the order of rule processing matters. Magento applies Cart Price Rules based on their priority, so combining promotions can be unpredictable if not managed carefully. To avoid conflicts, test different combinations thoroughly before launching. Also, use clear messaging to explain the promotions to customers and prevent confusion.
3. How to handle out-of-stock products in a Buy X Get Y Free promotion?
Magento typically handles out-of-stock products based on your inventory settings. If a product required for the Buy X Get Y Free promotion becomes unavailable, the discount might not apply correctly. To prevent issues, consider implementing additional logic or using extensions that specifically address out-of-stock scenarios within promotions.
4. Why isn’t my Buy X Get Y Free promotion working?
Several issues could prevent your Buy X Get Y Free promotion from working. Common problems include incorrect rule conditions, actions, or priorities. Out-of-stock products or conflicts with other promotions can also interfere. To isolate the problem, double-check your rule settings, test the promotion thoroughly with different scenarios, and ensure product availability.
5. How to optimize the performance of Buy X Get Y Free promotions?
To optimize Buy X Get Y Free promotions, focus on simplifying rule conditions and limiting the number of products involved. Utilize Magento’s indexing and caching features to improve performance. Avoid overly complex rule setups as they can impact system speed. Regularly review and test your promotions to identify and address any performance bottlenecks.
Final words
Buy X Get Y Free is a popular marketing strategy in e-commerce, which can help stores to promote certain items and boost sales in a short period of time. The default Magento 2 also supports this feature, so you can follow the above instructions to create one. But if you want to create other promotions, why not try our Special Promotions extension? We are always ready to help if you still have any doubts, so feel free to contact us.
Related topics