Last active
May 23, 2022 19:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, how are you? great snippet, but how to do the same on checkout page?