Hi. How can we help?

How to deny coupon on purchase of gift cards

Thanks to the next code, you can restrict the use of coupons to purchase a gift card product.

If the customer tries to do it, the action will be denied and a message will be shown 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) {
$cart = WC()->cart->get_cart();
$gift_card_in_cart = false;

foreach ($cart as $cart_item) {
if ( has_term( 'gift-card', 'product_type', $cart_item['product_id'] ) ) {
$gift_card_in_cart = true;

if ($gift_card_in_cart) {
wc_add_notice( 'Coupon cannot applied to gift card product', 'error' );
Was this article helpful?
1 out of 4 found this helpful

Back to Help Center >