I want to build the following:
A landingspage with a Apply Coupon
field. If the coupon
is valid it needs to add a specific product
to the cart. So basically the coupon needs to be attached to a specific product. (in this case product_id 99
.
I found this somewhere:
function wc_ninja_apply_coupon( $coupon_code ) {
if ( 'JLSDFO' === $coupon_code ) {
$product_id = 99;
WC()->cart->add_to_cart( $product_id );
}
}
add_action( 'woocommerce_applied_coupon', 'wc_ninja_apply_coupon' );
But this is for one coupon specific. I want to add for example 1000 coupons which are merged with this product. The customer can select this product on the back-end while adding this coupons. So when the user enters one of the 1000 coupons it understands to add for example product_id 99
to the cart.