Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Balakrishnan-flycart/425eb7a72609da9b91b13ac79f120bef to your computer and use it in GitHub Desktop.
Save Balakrishnan-flycart/425eb7a72609da9b91b13ac79f120bef to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Filter Category Combination
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