Created
February 24, 2026 09:53
-
-
Save xlplugins/07942f5d4d420f2d00dc6aac6aedcde8 to your computer and use it in GitHub Desktop.
fKCart Rewards - Total Fallback
This file contains hidden or 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_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