Created
December 24, 2019 13:15
-
-
Save Balakrishnan-flycart/dbb0ea6f4c4e85b625f4a0ed0002b247 to your computer and use it in GitHub Desktop.
woo discount rules exclude product from discount in specific category using priority id
This file contains 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('woo_discount_rules_exclude_product_from_discount', function($return, $product, $id, $rule, $cart_item){ | |
$priority_id = array(3); //Enter the priority id for which you need discount. i,e: array(1,2,3) | |
$category_id = array(22); //Enter the category id for which you need discount. i,e: array(1,2,3) | |
if(in_array($id,$priority_id)){ | |
if (method_exists($product, 'get_category_ids')) { | |
if ($product->is_type('variation')) { | |
if (method_exists($product, 'get_parent_id')) { | |
$parent_id = $product->get_parent_id(); | |
if(!empty($parent_id)){ | |
$product = wc_get_product($parent_id); | |
} | |
} | |
} | |
$product_categories = $product->get_category_ids(); | |
if(!empty($product_categories) && is_array($product_categories)){ | |
$is_valid_category = array_intersect($category_id, $product_categories); | |
if(empty($is_valid_category)){ | |
$return = true; | |
} | |
} | |
} | |
return $return; | |
} | |
}, 10, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment