Duplicated line items in cart when discount Buy X get Y applied

Hey friends! Why when the automatic discount Buy X get Y is applied, the items in cart are split? The discount should be applied only to item Y, no? But for some reason the discount is also applied to other items and it looks weird because I see a label with name of discount but no actual discount. It’s really annoying that it doesn’t work as expected.

So I need that if the whole order is more than $1000 then the buyer can add one gift item for free.

Could you please help me to figure this out? Maybe I’m doing something wrong? I have already spent a few hours trying to figure out what could be the cause.

I’ve added screenshots with the settings for the discount and you can also check it out in my test store (password: rahlah). It’s using the fresh Dawn theme here so it’s definitely not a problem in the theme or something.



I have also seen posts about this problem on the old forum but it seems that they also went unanswered. Thanks.

Yeah, this is a known behavior with automatic Buy X & Get Y discounts in Shopify, and it can definitely be confusing

You can modify the cart template to detect free items (e.g., line.discountAllocations[0].discountApplication.title or line.finalLinePrice == 0

{% if line.discountAllocations.size > 0 %}
  {% assign is_free_item = line.finalLinePrice == 0 %}
  {% if is_free_item %}
    <span class="text-green-600 font-bold">🎁 Free Gift</span>
  {% endif %}
{% endif %}

Thanks for the info! Do you know if there was an official response from shopify or something? Well yes, detection of free product is not a problem :sweat_smile: The thing is that I also have custom modifications for cart template, but I didn’t mention it to focus on the problem with items splitting into two parts when applying Buy X get Y automatic discount.

Not an official reply, but here is a post in the community forums:

You can reach out to Shopify staff here and might be able to DM them and get a direct response.

1 Like

Oh, really, it’s so annoying.. It’s strange that I only found out about this problem now, even though I’ve been working with shopify for a few years. I’ll try to figure it out later, unless someone else can suggest a workaround. Thanks for your help :slight_smile: