In core WooCommerce, you can create a coupon that only applies to specific items by adding categories and/or products in the usage restriction tab: https://docs.woocommerce.com/document/coupon-management/#usage-restriction
I thought so too, but it didn’t work, even though I added a the product category / product id. And after reading the docs again, I realized why:
Products – Products that the coupon will be applied to, or that need to be in the cart in order for the fixed or percentage discount to be applied.
and
Product categories – Product categories that the coupon will be applied to, or that need to be in the cart in order for the fixed or percentage discount to be applied.
So in other words, if I specify product ids/categories together with percentage, then it means the coupon will be applied to whole cart if one of the restricted product id / category is in the cart.