Created
June 10, 2021 13:49
-
-
Save Balakrishnan-flycart/425eb7a72609da9b91b13ac79f120bef to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Filter Category Combination
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
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){ | |
//'array(23,24)' - give rule id as you needed | |
if(in_array($rule->getId(),array(23)) && class_exists('\Wdr\App\Helpers\Woocommerce')){ | |
$rule_filter = $rule->getFilter(); | |
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product); | |
$categories = \Wdr\App\Helpers\Woocommerce::getProductCategories($product); | |
$category_id = array(); | |
$is_product_in_category = false; | |
if($rule_filter){ | |
foreach($rule_filter as $filter){ | |
$type = isset($filter->type) ? $filter->type : ''; | |
if( $filter->method == 'in_list'){ | |
if($type == 'product_category'){ | |
$category_id = isset($filter->value) ? $filter->value : array(); | |
} | |
} | |
} | |
} | |
if(!empty($category_id) ){ | |
foreach ($category_id as $cat_id){ | |
if(in_array($cat_id, $categories)){ | |
$is_product_in_category = true; | |
}else{ | |
return false; | |
} | |
} | |
if($is_product_in_category){ | |
return true; | |
} | |
} | |
} | |
return $filter_passed; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment