A flat store-wide discount treats every customer the same. Loyalty Program for WooCommerce lets you reward higher tiers with bigger savings: VIP members might receive 10 percent off every order, while VVIP members get 20 percent. This guide walks through a single PHP snippet that applies the right percentage at checkout based on the customer’s current rank.
Find Your Rank IDs
The snippet below references ranks by numeric ID rather than name, so the same code keeps working if you rename a rank later. To find a rank’s ID, go to Loyalty Program > Ranks in WordPress admin, click Edit Rank on the row you want, and read the ID from the modal header: it appears as Edit Rank (#2). Use that number wherever the snippet shows a comment like // VIP or // VVIP.
The Snippet
The example hooks into woocommerce_cart_calculate_fees and uses WPGL_Ranks_Core::get_user_rank() to read the customer’s current tier. The discount is added as a negative cart fee, so it shows as a clear line on the cart and checkout totals and respects tax settings. Edit the $tier_discounts array to map your rank IDs to percentages.
<?php
/**
* Example: Tier-specific checkout discounts
*
* Apply a different percentage discount at checkout depending on the customer's
* membership tier (rank). For example: VIP gets 10% off, VVIP gets 20% off.
*
* The discount is added as a negative cart fee, so it shows up clearly on the
* cart and checkout totals and respects taxes.
*
* Rank IDs are visible in the admin: Loyalty Program -> Ranks -> Edit Rank.
* The modal header shows the rank ID, e.g. "Edit Rank (#2)".
*
* Copy this snippet to your theme's functions.php or a small custom plugin.
* Requires: Loyalty Program plugin with Ranks module active, WooCommerce.
*/
if (!defined('ABSPATH')) {
exit;
}
add_action('woocommerce_cart_calculate_fees', 'wpgl_apply_tier_checkout_discount');
function wpgl_apply_tier_checkout_discount($cart)
{
if (is_admin() && !defined('DOING_AJAX')) {
return;
}
$user_id = get_current_user_id();
if (!$user_id) {
return;
}
if (!class_exists('WPGL_Ranks_Core')) {
return;
}
// Map of rank ID => discount percentage. Edit IDs and percentages to match your setup.
$tier_discounts = [
2 => 10, // VIP
3 => 20, // VVIP
];
$user_rank = WPGL_Ranks_Core::get_user_rank($user_id);
if (!$user_rank || empty($user_rank->id)) {
return;
}
$rank_id = (int) $user_rank->id;
if (!isset($tier_discounts[$rank_id])) {
return;
}
$percent = (float) $tier_discounts[$rank_id];
$subtotal = (float) $cart->get_subtotal();
if ($subtotal <= 0 || $percent <= 0) {
return;
}
$discount = -1 * round($subtotal * ($percent / 100), wc_get_price_decimals());
$label = sprintf(
/* translators: 1: rank name, 2: discount percent */
__('%1$s member discount (%2$s%%)', 'wpgens-loyalty-program'),
$user_rank->name,
$percent
);
$cart->add_fee($label, $discount, true);
}
Where to Put This Snippet
Drop the snippet into a small site-specific plugin under wp-content/mu-plugins/ so it survives theme changes, or paste it into your child theme’s functions.php. It is also available in the plugin folder under examples/.
After deploying, log in as a user assigned to one of the configured tiers, add a product to the cart, and confirm the discount line appears with the expected percentage.