Exclude sale products from category checks in coupon class

Fixes #15715
This commit is contained in:
Mike Jolley 2017-06-21 11:55:12 +01:00
parent e3a9cc9a3d
commit 31fccea25c
1 changed files with 7 additions and 0 deletions

View File

@ -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;
}