|
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){ |
|
//'array(339,340)' - give rule id as you needed |
|
if(in_array($rule->getId(),array(339,340)) && class_exists('\Wdr\App\Helpers\Woocommerce')){ |
|
$rule_filter = $rule->getFilter(); |
|
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product); |
|
$product_parent = \Wdr\App\Helpers\Woocommerce::getProductParentId($product_id); |
|
$product_id = !empty($product_parent) ? $product_parent : $product_id; |
|
$product_tag_ids = array(); |
|
if($rule_filter){ |
|
foreach($rule_filter as $filter){ |
|
$type = isset($filter->type) ? $filter->type : ''; |
|
if( $filter->method == 'in_list'){ |
|
if($type == 'product_tags'){ |
|
$product_tag_ids = isset($filter->value) ? $filter->value : array(); |
|
}else{ |
|
if(in_array($type, array_keys(\Wdr\App\Helpers\Woocommerce::getCustomProductTaxonomies()))){ |
|
$taxonomies[$type] = isset($filter->value) ? $filter->value : array(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if(!empty($product_tag_ids) && isset($taxonomies) && !empty($taxonomies) ){ |
|
$tag_ids = array(); |
|
if(function_exists('wp_get_post_terms')){ |
|
$terms = wp_get_post_terms( $product_id, 'product_tag' ); |
|
if( count($terms) > 0 ){ |
|
foreach($terms as $term){ |
|
$tag_ids[] = strval($term->term_id); |
|
} |
|
} |
|
} |
|
|
|
$is_product_has_tag = count(array_intersect($tag_ids, $product_tag_ids)) > 0; |
|
|
|
if($is_product_has_tag){ |
|
foreach($taxonomies as $key=>$taxonomy){ |
|
$term_ids = wp_get_post_terms($product_id, $key, array("fields" => "ids")); |
|
$is_product_has_term = count(array_intersect($term_ids, $taxonomy)) > 0; |
|
if(!$is_product_has_term){ |
|
return false; |
|
} |
|
} |
|
if($is_product_has_term){ |
|
return true; |
|
} |
|
}else{ |
|
return false; |
|
} |
|
} |
|
} |
|
return $filter_passed; |
|
}, 10, 4); |