In Woocommerce, I'm trying to make a Coupon Code mandatory for all Products from a specific Category.
The following code (placed in functions.php) works well, but makes Coupon Codes mandatory for all Products regardless of the product category:
add_action('woocommerce_check_cart_items', 'make_coupon_code');
function make_coupon_code()
{
global $woocommerce;
if(is_cart() || is_checkout()){
$my_coupon = $woocommerce->cart->applied_coupons;
echo $woocommerce->cart->get_applied_coupons;
if(empty($my_coupon))
{
wc_add_notice( '<strong>' . $btn['label'] . '</strong> ' . __( 'insert coupon code', 'woocommerce' ), 'error' );
}
}
}
Any ideas?
(the Product Category I'm trying to target is 'chef-masterclass')