Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Force free product coupon with single use coupon › Reply To: Force free product coupon with single use coupon

#15544
anthonyceo
Participant

Thank you for your help. :)

Here’s the simple code for others trying to do the same thing. Unfortunately, the coupon object doesn’t declare whether the coupon has a free item. However, all of our coupons for Free Products have a discount amount of 0.

add_filter('woocommerce_apply_with_individual_use_coupon', 'force_bogo_coupon', 10, 2);
function force_bogo_coupon($bool, $coupon) {
	$amount = $coupon->amount;
	$bool = ($amount == 0) ? true : $bool;
	return $bool;
}

Edit:

this code is more specific to a free product:

add_filter('woocommerce_apply_with_individual_use_coupon', 'force_bogo_coupon', 10, 2);
function force_bogo_coupon($bool, $coupon) {
	$meta = $coupon->get_meta('_wjecf_must_select_free_product');
	$bool = ($meta === 'yes') ? true : $bool;
	return $bool;
}