Hello there,
we hope you’re doing well!
In order to achieve what you need, add the following code in the functions.php file of your active child theme:
if( ! function_exists( 'yith_ywgc_coupon_not_valid_with_gift_card' ) ){
function yith_ywgc_coupon_not_valid_with_gift_card(){
$cart = WC()->cart;
if( ! empty( $cart->applied_gift_cards ) && ! empty( $cart->applied_coupons ) ) {
foreach ($cart->applied_coupons as $coupon) {
$cart->remove_coupon($coupon);
WC()->cart->calculate_totals();
}
$error_message = 'Coupons removed: You cannot use coupons when purchasing with Gift Card';
if ( !wc_has_notice($error_message, 'error' )){
wc_add_notice($error_message, 'error');
}
$notices = WC()->session->get('wc_notices', array());
if ( isset($notices['success'] ) && is_array( $notices['success'] ) ) {
unset($notices['success']);
WC()->session->set('wc_notices', $notices);
}
}
}
add_action( 'woocommerce_after_calculate_totals', 'yith_ywgc_coupon_not_valid_with_gift_card', 30 );
}
Check it out and tell us any news, please.
Have a nice day!