Let’s say you running an offer where you want to give away a free product when a certain product or set of products is added to the cart.
Given how flexible and customizable WooCommerce is, everything is possible. Let’s see how we can accomplish this task.
PHP
functions.php
You need to add this code to the functions.php of your active theme. And you need to change the value of two variables: $products_should_be_in_cart variable and $free_products.