ok, hab das so gelöst (falls es jemand mal brauchen kann).
<?php
add_action( 'woocommerce_check_cart_items', 'mandatory_coupon_code' );
function mandatory_coupon_code() {
// hier die Kategorie eingeben
$product_categories = array( 'Lebensmittel' );
$found = false;
foreach ( WC()->cart->get_cart() as $cart_item ){
if( has_term( $product_categories, 'product_cat', $cart_item['product_id'] ) ){
$found = true;
break;
}
}
if( ! $found ) return; // exit
$applied_coupons = WC()->cart->get_applied_coupons();
if( is_array($applied_coupons) && sizeof($applied_coupons) == 0 ) {
$message = __( 'Hier dann die Fehlermeldung, wenn KEIN Coupon Code eingegeben wurde', 'woocommerce' );
wc_add_notice( $message, 'error' );
}
}
?>