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:
 
<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:
 
{% 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.