From 4379a47cd50736f0952bdf5b4a7a082e10d1294a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 12 Oct 2017 15:40:58 +0100 Subject: [PATCH] Fixed discount logic to also look at parent categories when validatiing coupons Fixes #17150 --- includes/class-wc-discounts.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/class-wc-discounts.php b/includes/class-wc-discounts.php index c2881c5f172..0db29d0f8ae 100644 --- a/includes/class-wc-discounts.php +++ b/includes/class-wc-discounts.php @@ -665,6 +665,10 @@ class WC_Discounts { $product_cats = wc_get_product_cat_ids( $item->product->get_id() ); + if ( $item->product->get_parent_id() ) { + $product_cats = array_merge( $product_cats, wc_get_product_cat_ids( $item->product->get_parent_id() ) ); + } + // If we find an item with a cat in our allowed cat list, the coupon is valid. if ( count( array_intersect( $product_cats, $coupon->get_product_categories() ) ) > 0 ) { $valid = true; @@ -797,6 +801,11 @@ class WC_Discounts { } $product_cats = wc_get_product_cat_ids( $item->product->get_id() ); + + if ( $item->product->get_parent_id() ) { + $product_cats = array_merge( $product_cats, wc_get_product_cat_ids( $item->product->get_parent_id() ) ); + } + $cat_id_list = array_intersect( $product_cats, $coupon->get_excluded_product_categories() ); if ( count( $cat_id_list ) > 0 ) { foreach ( $cat_id_list as $cat_id ) {