Last active
January 15, 2026 12:46
-
-
Save goranefbl/727497ba04f5438692db010443de4a00 to your computer and use it in GitHub Desktop.
points calculation
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
| <?php | |
| /** | |
| * Calculate points based on total amount instead of per-product | |
| * Useful when plugins give some products for free | |
| * 10 points per $1 spent (excluding shipping, including tax) | |
| */ | |
| // For cart/checkout display | |
| add_filter('wpgens_loyalty_cart_points_after_discount', function($total_points, $cart, $discount_ratio) { | |
| // Subtotal + tax - discounts (including discount tax) | |
| $cart_subtotal = $cart->get_subtotal() + $cart->get_subtotal_tax(); | |
| $cart_subtotal -= $cart->get_discount_total() + $cart->get_discount_tax(); | |
| // 10 points per $1 spent | |
| return floor($cart_subtotal * 10); | |
| }, 10, 3); | |
| // For order processing | |
| add_filter('wpgens_loyalty_order_points_after_discount', function($total_points, $order, $discount_ratio) { | |
| // Order total already includes tax, just subtract shipping | |
| $order_subtotal = $order->get_total() - $order->get_shipping_total() - $order->get_shipping_tax(); | |
| // 10 points per $1 spent | |
| return floor($order_subtotal * 10); | |
| }, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment