# How to send a discount code only if a specific product has been purchased?

Using Personal Discount, you can add a unique discount code to the order confirmation email that Shopify sends after every purchase. However, you may want to offer a discount based on certain conditions. For example, you may want to send a coupon code only if a customer purchased a specific SKU.

Normally, Personal Discount gives you a code snippet like below to insert in the order confirmation email template:

```liquid
<div style="text-align: center; margin: 20px">
    <a href="https://render.personaldiscount.me/discount/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apply?email={{email}}">
        <img src="https://render.personaldiscount.me/discount/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/image?email={{email}}" alt="Discount Code">
    </a>
</div>
```

To send a coupon only if a particular item was purchased, you need to add two lines above and to lines below the code snippet:

```liquid
{% for line in line_items %}
{% if line.sku == "A123" %}
<div style="text-align: center; margin: 20px">
     <a href="https://render.personaldiscount.me/discount/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apply?email={{email}}">
         <img src="https://render.personaldiscount.me/discount/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/image?email={{email}}" alt="Discount Code">
    </a>
</div>
{% endif %}
{% endfor %}
```

Please note that you need to replace **A123** with the SKU of the product that you want to target.

The order confirmation email will now include a discount code only if the SKU has been added to the order. Other customers who have not purchased the specific item won't receive the discount.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.personaldiscount.io/personal-discount-for-shopify/integrate-personal-discount-with-your-email-service-provider/shopify-notifications/how-to-send-a-discount-code-only-if-a-specific-product-has-been-purchased.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
