Created
May 6, 2020 08:49
-
-
Save plugin-republic/c4906e99c64ec4a2b9ae17525824cc50 to your computer and use it in GitHub Desktop.
Ensure global categories include products in child categories
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
<?php | |
/** | |
* Ensure global categories include products in child categories | |
*/ | |
function prefix_add_parents_to_permitted_cats( $categories, $product_id, $global, $rule ) { | |
// Iterate through each category | |
// If it's got children, ensure they're added to the list | |
if( $categories ) { | |
foreach( $categories as $cat_id ) { | |
$children = get_term_children( $cat_id, 'product_cat' ); | |
if( $children ) { | |
$categories = array_merge( $categories, $children ); | |
} | |
} | |
} | |
return $categories; | |
} | |
add_filter( 'pewc_filter_permitted_cats', 'prefix_add_parents_to_permitted_cats', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment