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!
Hi,
I’m still experiencing issues when trying to apply that.
It is telling me this error message:
Your PHP code changes were rolled back due to an error on line 76 of file wp-content/themes/gecko/functions.php. Please fix and try saving again.
syntax error, unexpected 'unset' (T_UNSET)
Thank you,
Katie
Hi there!
I tried the code my colleague sent you and it worked fine for me.
I could save the file correctly.
Are the rest of your functions.php files correctly formatted?
Do you have all your tags closed?
You can also try to save it from a code editor by modifying the file directly from your installation.
Please, let us know.
Regards!