First create your coupon and code. Second go to your woocommerce setting > emails > and choose either the 'Processing Order' (its sent before the item has shipped while processing payment) or the "Completed Order' (lets customers know the order has been completed and has started shipping) or customer invoice (manually sent <-- probably the one I would use since it can provide tracking information as well) > click manage >'Email Heading' you can add a line after the default (<-- I would change that to also include available placeholders) > Click save.
Your coupon code will be sent to anyone who has completed payment processing and receive the code along with shipment information and order completion confirmation. That being said, make sure your coupon doesn't have an expire date, or use limit other than on 'user per user'.
That's about the only way I would know how to do it. But in reality its going to depend on really how you have things set up. Are you using SMTP service (ex: pepipost, sendinblue, mailchimp, ect)? If so you will most likely have to edit the templates on those services as well / instead.
So you want to generate a different coupon code for every transaction and then update your templates to insert that code for every order confirmation email? Sorry I don't know how to go about that other than doing it manually each time. Using 1 coupon code would be simple enough as mentioned above but different coupon generation along with inserting it to email notifications automatically is out my reach lol.
If your reason for having unique codes is to limit the number of times the customer can use the code, then you can set that when you create the coupon. Just set the user limit to 1. That way you don't have to have unique codes for each customer.
Coupons can be a big help for you sometimes. I think it's the main reason why I've started to shop online. Those 10-$15 can be a lifesaver. I personally use apps for online shopping, and with that app you can easier get discount coupons, and that' very good. Personally, I use https://arrestyourdebt.com/rakuten-review/ , app, I find it very useful for me, and I can easily recommend it to you. So thank you guys for letting me share, and hope someone will find my message useful, and will start using online shopping apps more that before.