I want to edit the add to cart section on the product single template of the woocommerce plugin.
I would like to know whether it is a good practice to put the code directly in the file.
If not, what are my alternatives and how do I add the code correctly in order for wordpress to know where I want the code to take effect?
It’s WooCommerce; you should to make you change via one of its action or filter hooks via your theme’s `function.php` file or a custom plugin. Or copy the WC template file you are interested in, along with its parent directories, in to your theme.
Never edit the core WC files directly, make a copy of the file and save it to your theme and edit the PHP file there. This ensures that your custom edits remain in tact when WC pushes a core update.
Never change plugin files directly. For woocommerce you can override template files by creating your own version:
https://woocommerce.com/document/template-structure/