How to deny coupon on purchase of gift cards
Thanks to following code any WooCommerce coupon code can be used to purchase a gift card.
If the customer try to do it, the action will be denied and a message will be showed to him/her "Coupon cannot applied to gift card product"
Add the code in the file functions.php of your theme.
if( defined('YITH_YWGC_PREMIUM') ){
if( !function_exists('yith_wcgc_deny_coupon_on_gift_card') ){
add_action('woocommerce_applied_coupon','yith_wcgc_deny_coupon_on_gift_card');
function yith_wcgc_deny_coupon_on_gift_card( $coupon_code ){
global $woocommerce;
$the_coupon = new WC_Coupon( $coupon_code );
$excluded_items = $the_coupon->get_excluded_product_ids();
$items = $woocommerce->cart->get_cart();
foreach ( $items as $item ):
if( has_term('gift-card','product_type',$item['product_id']) == true ):
$excluded_items[] = $item['product_id'];
endif;
endforeach;
$the_coupon->set_excluded_product_ids($excluded_items);
$the_coupon->save();
wc_add_notice( 'Coupon cannot applied to gift card product', 'error' );
}
}
}