Last active
February 6, 2025 07:53
-
-
Save MWDelaney/0200a347e552350398ee4fe4cc7a10ce to your computer and use it in GitHub Desktop.
Revisions
-
MWDelaney revised this gist
Apr 12, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,9 @@ function mwd_get_applied_coupons() { } } // Remove any other coupons of this type // Loop through all other applied coupons foreach ( WC()->cart->get_coupons() as $code => $coupon ) { // Check whether each coupon matches the type of the coupon we just applied if($coupon->code != $_POST['coupon_code'] && $coupon->discount_type == $type_to_remove) { // Exclude "smart_coupon" type, since users should be able to use as many gift cards as they like if($coupon->discount_type != 'smart_coupon') { -
MWDelaney created this gist
Apr 12, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ <?php // Hook when a coupon is applied to a cart add_action( 'woocommerce_applied_coupon', 'mwd_get_applied_coupons' ); // Get the current applied coupon and compare it with other applied coupons function mwd_get_applied_coupons() { // Get the currently applied coupon's type using the $_POST global to retrieve the current coupon's code foreach ( WC()->cart->get_coupons() as $code => $coupon ) { if($coupon->code == $_POST['coupon_code']) { // Get this coupon's type so we can remove all other coupons of this type from the cart $type_to_remove = $coupon->discount_type; } } // Remove any other coupons of this type foreach ( WC()->cart->get_coupons() as $code => $coupon ) { if($coupon->code != $_POST['coupon_code'] && $coupon->discount_type == $type_to_remove) { // Exclude "smart_coupon" type, since users should be able to use as many gift cards as they like if($coupon->discount_type != 'smart_coupon') { // Remove all coupons that match the type of the coupon we just applied WC()->cart->remove_coupon( $coupon->code ); } } } } ?>