You can ensure that any categories you select in global groups that use the ‘Categories’ rule will include child products. Just add this snippet:
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 ); |
This is how to add a snippet.