I have added a function to add a free product when a certain coupon code is entered.
I now need to check if the original product is still in the cart, and if not, remove coupon and free product from the cart.
add_action('woocommerce_applied_coupon', 'apply_product_on_coupon');
function apply_product_on_coupon( ) {
global $woocommerce;
$coupon_idcus = 'ccam0620';
$free_product_id = 11259;
if(in_array($coupon_idcus, $woocommerce->cart->get_applied_coupons())){
$woocommerce->cart->add_to_cart($free_product_id, 2);
}
}