From 31fccea25cd53351e3ac51ad54d0f3d40199d80d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 21 Jun 2017 11:55:12 +0100 Subject: [PATCH] Exclude sale products from category checks in coupon class Fixes #15715 --- includes/class-wc-coupon.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/class-wc-coupon.php b/includes/class-wc-coupon.php index 020965b9efa..12db1fc16ae 100644 --- a/includes/class-wc-coupon.php +++ b/includes/class-wc-coupon.php @@ -860,6 +860,9 @@ class WC_Coupon extends WC_Legacy_Coupon { $valid_for_cart = false; if ( ! WC()->cart->is_empty() ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { + if ( $this->get_exclude_sale_items() && $cart_item['data'] && $cart_item['data']->is_on_sale() ) { + continue; + } $product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); // If we find an item with a cat in our allowed cat list, the coupon is valid @@ -963,7 +966,11 @@ class WC_Coupon extends WC_Legacy_Coupon { $valid_for_cart = true; if ( ! WC()->cart->is_empty() ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { + if ( $this->get_exclude_sale_items() && $cart_item['data'] && $cart_item['data']->is_on_sale() ) { + continue; + } $product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); + if ( sizeof( array_intersect( $product_cats, $this->get_excluded_product_categories() ) ) > 0 ) { $valid_for_cart = false; }