Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created February 24, 2026 09:53
Show Gist options
  • Select an option

  • Save xlplugins/f68d1fcef7988e4b7333c77c1e3f367b to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/f68d1fcef7988e4b7333c77c1e3f367b to your computer and use it in GitHub Desktop.
fKCart Rewards - Total Fallback
add_filter( 'fkcart_reward_total', 'fkcart_rewards_total_fallback', 999, 3 );
function fkcart_rewards_total_fallback( $total, $calculation_mode, $front ) {
if ( 'total' !== $calculation_mode ) {
return $total;
}
if ( is_null( WC()->cart ) || WC()->cart->is_empty() ) {
return $total;
}
// Only fallback when total is 0 or negative but cart has items
if ( (float) $total > 0 ) {
return $total;
}
$cart = WC()->cart;
$calculated = (float) $cart->get_cart_contents_total()
+ (float) $cart->get_fee_total()
+ (float) $cart->get_shipping_total()
+ (float) $cart->get_total_tax()
- (float) $cart->get_discount_total();
if ( $cart->display_prices_including_tax() ) {
$calculated -= (float) $cart->get_discount_tax();
}
$calculated = max( 0, $calculated );
// Add session coupons discount (same as get_cart_total does)
if ( class_exists( '\FKCart\Pro\Rewards' ) && method_exists( '\FKCart\Pro\Rewards', 'get_session_coupons_discount_total' ) ) {
$calculated += (float) \FKCart\Pro\Rewards::get_session_coupons_discount_total();
}
return $calculated > 0 ? $calculated : $total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment