Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save somewherewarm-snippets/395c6b4ea9fe075a6f01e760aec9a0ec to your computer and use it in GitHub Desktop.
Save somewherewarm-snippets/395c6b4ea9fe075a6f01e760aec9a0ec to your computer and use it in GitHub Desktop.
Use this snippet to prevent coupons from being applied to the cart when paying with gift cards.
<?php
/**
* Plugin Name: WooCommerce Gift Cards - Prevent use of coupons when paying with gift cards
* Plugin URI: https://woocommerce.com/products/gift-cards/
* Description: Use this snippet to prevent coupons from being applied to the cart when paying with gift cards.
* Version: 1.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Jason Kytros
*
*
* Copyright: © 2021 Automattic
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_action( 'woocommerce_check_cart_items', 'sw_gc_check_cart_coupons' );
function sw_gc_check_cart_coupons() {
$using_giftcards = ! empty( WC_GC()->giftcards->get() );
if ( $using_giftcards ) {
foreach ( WC()->cart->get_applied_coupons() as $code ) {
$coupon = new WC_Coupon( $code );
$coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_INVALID_REMOVED );
WC()->cart->remove_coupon( $code );
}
}
}
@zionlabbr
Copy link

Hello, how are you? great snippet, but how to do the same on checkout page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment