Last active
December 27, 2019 15:04
-
-
Save kloon/4633463 to your computer and use it in GitHub Desktop.
WooCommerce Disable Coupons on Sale Items
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 characters
<?php | |
// Exclude coupons from being applied when products on sale | |
add_filter( 'woocommerce_coupon_is_valid', 'woocommerce_coupon_check_sale_items', 10, 2 ); | |
function woocommerce_coupon_check_sale_items( $valid, $coupon ) { | |
global $woocommerce; | |
$valid_for_cart = $valid; | |
if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) : | |
if ( function_exists( 'get_product') ) | |
$product = get_product( $cart_item['product_id'] ); | |
else $product = new WC_Product( $cart_item['product_id'] ); | |
if ( $product->is_on_sale() ) | |
$valid_for_cart = false; | |
endforeach; endif; | |
if ( ! $valid_for_cart ) $valid = false; | |
return $valid; | |
} | |
?> |
thanks
What does this function do that the "Exclude sale items" check box function does not do?
@mikakaltoft It does it manually, for all coupons. So useful when you have more number of coupons.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this function do that the "Exclude sale items" check box function does not do?