Last active
February 21, 2023 11:55
-
-
Save sarancartrabbit/5e5f00cd7fda68537f949123d69a8124 to your computer and use it in GitHub Desktop.
Discount rules v2: To check the parent category in the product
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
if(!function_exists('awdrcheckParentCategory')){ | |
function awdrcheckParentCategory ($categories){ | |
foreach($categories as $id) { | |
if ($term = get_term($id)) { | |
if ($parent_id = $term->parent) { | |
if (!in_array($parent_id, $categories)) { | |
$categories = array_merge($categories, awdrcheckParentCategory(array($parent_id))); | |
} | |
} | |
} | |
} | |
return array_unique($categories); | |
} | |
add_filter('advanced_woo_discount_rules_get_product_categories','awdrcheckParentCategory', 10, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment