With this new snippet, we'll show you how to set a maximum points limit that your customers can't exceed, no matter how many purchases or loyalty actions they've made. It intercepts point additions before they are applied, and adjusts them if necessary to never exceed the set limit.
Loyalty schemes are excellent levers for building customer loyalty, but a poorly calibrated system can quickly unbalance your sales strategy. If you use WooRewards on your store WooCommerce, you know how powerful it is for rewarding your customers.
However, WooRewards does not natively offer a maximum points cap a user can accumulate. This can be a problem if some customers are collecting too many points and accessing expensive rewards too easily. Fortunately, this limit can be added via a simple snippet of code to insert into your WordPress theme.
1|Information
Before using this snippet, make sure you have installed the Code Snippets plugin (free) on your WordPress site. If not, you can download it via the link below. If you have never added a specific feature to your WordPress site, we recommend you start by reading our dedicated guide (link below).
2|Prérequis
Here is the list of extensions required for this snippet to work properly. Make sure to install them before activating the snippet.
WooCommerce | Necessary for selling virtual products on your site |
WooRewards | Loyalty plugin for the points limitation |
3|Snippet
Here is the snippet to use. The comments inside the code will guide you on how this snippet works.
Assurez-vous de cocher la case « Run snippet everywhere » avant d’activer le snippet.
/** Here we set up a code snippet to define a points ceiling that no user can exceed when collecting points via the loyalty system(s) set up via WooRewards. */
<?php
\add_filter('lws_woorewards_core_pool_point_add', function($value, $userId, $reason, $system, $origin){
$maxPoints = [
'standard' => 200, // replace with your own system name and max amount
];
if (!isset($maxPoints[$system->getName()])) return $value;
$max = $maxPoints[$system->getName()];
$before = $system->getPoints($userId);
if (($before + $value) > $max) {
$value = $max - $before;
}
return $value;
}, 10, 5);
\add_filter('lws_woorewards_core_pool_point_set', function($value, $userId, $reason, $system){
$maxPoints = [
'standard' => 200, // replace with your own system name and max amount
];
if (!isset($maxPoints[$system->getName()])) return $value;
$max = $maxPoints[$system->getName()];
if ($value > $max) {
$value = $max;
}
return $value;
}, 10, 4);
Things to remember
- Flexibility : The ceiling value can be easily modified to suit your strategy.
- Preventive : avoids excessive points accumulation.
- Unobtrusive : runs in the background without disrupting the user experience.
Take it a step further
This type of customization shows just how far WooCommerce and WooRewards can be extended via WordPress filters and actions. If you'd like to further customize your loyalty program, take a look at the WooRewards documentation or hire an experienced WordPress developer (see our Custom Developments page).
Our Plugins
We have created powerful and widely acclaimed plugins for WooCommerce. Boost your sales with our solutions
WooRewards
Discover the most powerful loyalty plugin for WooCommerce. Simple or tiered systems, referrals, social networks, badges and achievements, you will find all the tools to build YOUR loyalty program
Learn MoreVIP Membership
VIP Memberships is a complete membership management tool for your WooCommerce site. Sell subscriptions to your customers and offer them benefits such as preferential prices or exclusive products.
Learn MoreVirtual Wallet
Offer your customers a virtual wallet on your website. Let them save money by purchasing your products and use this credit on future purchases. This extension also offers a complete gift card tool
Learn MoreReferral Codes
Win new customers with this complete SEO tool. Whether through influencers or simple referrers, reward them and the new customers they bring
Learn More