1. Home
  2. Knowledge Base
  3. WooCommerce Fees and Discounts
  4. Exclude products from role-based rules
  1. Home
  2. Knowledge Base
  3. Advanced
  4. Exclude products from role-based rules
  1. Home
  2. Knowledge Base
  3. Role based pricing
  4. Exclude products from role-based rules

Exclude products from role-based rules

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:

<?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:

<?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'
)
);
return array_values( $excluded );
}
add_filter( 'wcfad_exclude_from_role_based_rules', 'wcfad_exclude_categories_from_role_based_rules' );

Here’s how to add a snippet to your site.

Was this article helpful?

Need More Support?

If you can't find the answer that you're looking for, then please use the link below to raise a support ticket.
Contact Support

Related Articles