You can exclude certain products by ID from your global role-based rules using the wcfad_exclude_from_role_based_rules
filter as in the following snippet. Just replace the product IDs in the array:
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 | |
// Exclude some products from global role-based rules | |
function wcfad_exclude_from_role_based_rules( $excluded ) { | |
return array( 15, 119 ); | |
} | |
add_filter( 'wcfad_exclude_from_role_based_rules', 'wcfad_exclude_from_role_based_rules' ); |
If you would like to exclude all the products in one or more categories, you can use this snippet. Just change the name of the 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 | |
// Exclude all products within a category from global role-based rules | |
function wcfad_exclude_categories_from_role_based_rules( $excluded ) { | |
// Exclude all products in a category | |
$excluded = wc_get_products( | |
array( | |
'category' => array( 'fruit', 'vegetables' ), | |
'return' => 'ids' | |
) | |
); | |
// Include variations | |
if( $excluded ) { | |
foreach( $excluded as $excluded_id ) { | |
if( WC_Product_Factory::get_product_type( $excluded_id ) == 'variable' ) { | |
$product = wc_get_product( $excluded_id ); | |
$children = $product->get_children(); | |
$excluded = array_merge( $excluded, $children ); | |
} | |
} | |
} | |
return array_values( $excluded ); | |
} | |
add_filter( 'wcfad_exclude_from_role_based_rules', 'wcfad_exclude_categories_from_role_based_rules' ); |