Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/1af4add7618bae867a90247557594bd1 to your computer and use it in GitHub Desktop.
Save xlplugins/1af4add7618bae867a90247557594bd1 to your computer and use it in GitHub Desktop.
Cart : Exclude rewards for specific category
add_filter( 'fkcart_reward_enabled', function ( $status ) {
if ( is_null( WC()->cart ) ) {
return false;
}
$cart_items = WC()->cart->get_cart();
$tmp_category_id = [ 19 ]; // Your category ID here (for more categories, keep them comma separated)
foreach ( $cart_items as $cart_item ) {
$product_id = $cart_item['product_id'];
$product = wc_get_product( $product_id );
if ( $product ) {
$category_ids = $product->get_category_ids(); // Get an array of category IDs
// Check if any product in the cart matches the target category
foreach ( $category_ids as $category_id ) {
if ( in_array( $category_id, $tmp_category_id ) ) {
return false; // If the category is found in the cart, disable the reward
}
}
}
}
return true; // Enable the reward if category 19 is not in the cart
}, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment