Created
January 15, 2025 06:12
-
-
Save xlplugins/1af4add7618bae867a90247557594bd1 to your computer and use it in GitHub Desktop.
Cart : Exclude rewards for specific category
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
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