You can ensure that a discount code is only applied to products within a specific category or to specific products themselves. All products and categories can be discounted by default using a discount code.
In your eCom admin, go to Marketing.
Select Change on the relevant discount code or create a new one.
Near the bottom of the page, find Apply discount to and select one of the available options.
Scroll down and select Select Products and/or Select Categories.
Click on Choose to specify the product(s) and/or category(ies).
When you're done, close the menu by selecting the X in the top right corner of the menu.
Select Save.
Available options
Selected Products - The discount code will be applied to the selected products only.
Selected Categories - The discount code will only be applied to the selected categories.
Selected Products Categories - The discount code will be applied to the selected products and categories only.