Merge pull request #17162 from woocommerce/fix/17150

Fixed discount logic to also look at parent categories when validatiing coupons
This commit is contained in:
Claudiu Lodromanean 2017-10-12 09:19:14 -07:00 committed by GitHub
commit cd0eb65852
1 changed files with 9 additions and 0 deletions

View File

@ -665,6 +665,10 @@ class WC_Discounts {
$product_cats = wc_get_product_cat_ids( $item->product->get_id() ); $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 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 ) { if ( count( array_intersect( $product_cats, $coupon->get_product_categories() ) ) > 0 ) {
$valid = true; $valid = true;
@ -797,6 +801,11 @@ class WC_Discounts {
} }
$product_cats = wc_get_product_cat_ids( $item->product->get_id() ); $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() ); $cat_id_list = array_intersect( $product_cats, $coupon->get_excluded_product_categories() );
if ( count( $cat_id_list ) > 0 ) { if ( count( $cat_id_list ) > 0 ) {
foreach ( $cat_id_list as $cat_id ) { foreach ( $cat_id_list as $cat_id ) {