Points formulas
Points formulas

Knowledge Base

Points formulas is a way to push your loyalty program even further. In fact, it provides you with new ways to express your creativity and reward your customers.

What is it ?

In WooRewards, there are multiple places where you can set points values. For example, performing an action grants users points. In addition, redeeming a reward costs points.

With points formulas, instead of setting a fix points value, you have the possibility to set a formula. As a result, the points value will vary, depending on the situation.

The possibilities are endless. However, it will require some learning to get the best of it. Let’s begin now with the basics.

Operators

WooRewards supports basic operators. Therefore, you’ll find here the following possibilities

  • + : The addition operator
  • – : The subtraction operator
  • * : The multiplication operator
  • / : The division operator
  • > : The greater operator (The result of this operator is always 1 or 0)
  • < : The lower operator (The result of this operator is always 1 or 0)

This is pretty standard. Let’s complete it with some basic examples of formulas you can use.

  • = 2 + 2 : Simple addition. The result is 4
  • = (2 + 2) * 3 : An addition and a multiplication with priority brackets. The result is 12.
  • = 2 + (2 *3) : Same but with a different priority. The result is 8.

With these few examples, you can see that it’s fairly easy to set formulas. And useless too at this point. This is why, in the following section, we’ll see how to add some useful values.

Functions

In addition to operators, there are a couple of functions you can use in your formulas. Here are the available functions :

  • floor@ : Rounds the value to the nearest inferior integer
  • ceil@ : Rounds the value to the nearest superior integer
  • round@ : Rounds the value to the nearest integer (rounds up if .5 or above)
  • date@ value, ‘format’ : value is a timestamp, and format is the date format to consider (Example: date@ {time}, ‘d’)
  • min@ : Returns the minimal value between all values provided
  • max@ : Returns the maximal value between all values provided
  • equal@ : returns 0 if the arguments are not equal and 1 if they are
  • not@ : returns 1 if the argument’s value is 0
  • abs@ : returns the absolute value of the argument
  • mod@ : returns the remainder of a division of the first argument by the second. It applies the modulo operation

Variable values

Now, let’s get to the good stuff. To set formulas that will help you set up the perfect loyalty program, you need some variables. Variables have to be written into { Curly brackets }. Here are the possibilities :

  • time : returns the current timestamp.
  • user_integer:meta_key : returns a user meta as an integer value.
  • user_float:meta_key : returns a user meta as a float value.
  • user_timestamp:meta_key : returns a user meta as a timestamp (from int value or textual date).
  • points:stack_id : returns a points amount from the current user’s points reserve.
  • badge:xx : returns 1 or 0 if the current user owns the given badge (replace xx by the badge id).
  • role:xx : returns 1 or 0 if the current user owns the given role (replace xx by a slug).
  • referral:yy : where yy has to be replaced by one of the expression above. It returns the relevant value based on the referral user if any (or 0 if none). Example: {referral:points:default} get points of the referral in loyalty sytem with the slug default.

This immediately looks a lot more complicated. But don’t worry, it’ll become crystal clear (almost) with a few examples.

Finally, here are some other variable values that only work for methods to earn points tied to an order. For example, you can use it for the points methods “Spend Money”, “Place an order”, “Buy specific products” … Variables have to be written into { Curly brackets }.

  • order:total : The order total
  • order:total_vat_exc : The order total, without VAT
  • order:total_vat_inc : The order total, including VAT
  • order:subtotal : The order subtotal, before shipping and VAT
  • order:discount : The discounts total applied to the order
  • order:discount_tax : The discounts tax amount applied to the order
  • order:shipping : The shipping amount
  • order:shipping_tax : The shipping tax amount
  • order:fees : The order fees amount
  • order:onsale : The sum of all on-sale product prices in the order
  • order:regular : The sum of all not on-sale product prices in the order
  • pointsoncart:xx : The amount of points used as discount in the order (replace xx by the loyalty system shortcode attribute)
  • coupons : The number of coupons in the order
  • coupons:rr : The number of coupons where the code match the given regex (replace rr by a valid regular expression, including delimiters. Example: {coupons:/^test_/i})
  • products:pp : The number of products in the order with on of the given IDs (replace pp by a coma separated list of product IDs)
  • products_cat:cc : The number of products in the order included in the given categories (replace cc by a coma separated list of category IDs – not the slugs, we expect integers)
  • products_tag:cc : The number of products in the order with the given tags (replace cc by a coma separated list of tag IDs – not the slugs, we expect integers)
  • prices:pp : The sum of product’s prices in the order with on of the given IDs (replace pp by a coma separated list of product IDs)
  • prices_cat:cc : The sum of product’s prices in the order included in the given categories (replace cc by a coma separated list of category IDs – not the slugs, we expect integers)
  • prices_tag:cc : The sum of product’s prices in the order with the given tags (replace cc by a coma separated list of tag IDs – not the slugs, we expect integers)
  • subprices:pp : The sum of product’s prices before discounts in the order with on of the given IDs (replace pp by a coma separated list of product IDs)
  • subprices_cat:cc : The sum of product’s prices before discounts in the order included in the given categories (replace cc by a coma separated list of category IDs – not the slugs, we expect integers)
  • subprices_tag:cc : The sum of product’s prices before discounts in the order with the given tags (replace cc by a coma separated list of tag IDs – not the slugs, we expect integers)

Formulas examples

Now that we have a list of all possible values, let’s try them with some examples. Of course, these are only some of the possible uses of points formulas. The only limit is your creativity. Don’t hesitate to share your formulas with us !

Earn more points in higher levels

In this example, we’ll consider that you have a leveling system. The first level is at 1 point, the second level at 200 points and the third level at 500 points. At level 1, customers earn 1 point for each $1 spent. At level 2 they will earn 2 points for each $1 spent and, finally, at level 3, they will earn 3 points for each $1 spent.

Your leveling points and rewards system uses the leveling points reserve. Here is the formula to use :

=1 + ({points:leveling} > 199) + ({points:leveling} > 499)

No points if the cart contains coupons

If you want to grant points only for order without coupon, this formula is for you.

=not@ {coupons}

No points earned if any points is used in the cart for discount

If you want to grant points only for order without points on cart, this formula is for you.

=not@ {pointsoncart}

Point for spending money but only if a given product is here

If you want to grant points as usual but only if at least one product with ID 33 or 84 is in the cart, this formula is for you.

=min@ 1,{products:33,84}

Points equal to the customer’s age

If you want to offer a birthday gift to your customers that depend on their age, this formula is for you.

=round@ (({time} - {user_timestamp:billing_birth_date}) / (60*60*24*365))

More points depending on the user role

If you have a leveling system that gives specific user roles to your customers, you can also change how many points they earn depending on their role. In this example, we’ll say that Bronze members earn 10 points, Silver members earn 20 points and Gold members earn 50 points. Here’s the points formula :

=({role:bronze} * 10) + ({role:silver} * 20) + ({role:gold} * 30)

Give more points on a user’s birthday

If you want to give more points to users on their birthday, use this formula. Here, customers will earn 1 point when it’s not their birthday and 2 points when it’s their birthday :

= 1 + (equal@ (date@ {time}, 'd'), (date@ {user_timestamp:billing_birth_date}, 'd')) * (equal@ (date@ {time}, 'm'), (date@ {user_timestamp:billing_birth_date}, 'm'))

Earn more points depending on the order amount

In this example, we’ll see how to give more points depending on the order total amount. For orders under $100, customers will earn 1 point. For orders between $100 and $200, customers will earn 3 points. Finally, for orders above $200, customers will earn 10 points :

=1 + (({order:total} > 99) * 2) + (({order:total} > 199) * 7)

Some more tips

Points formulas also work on the “Generate Points” reward. You can use that to expand even further your loyalty program.

Don’t hesitate to experiment or ask us for help if you’re stuck with a formula.

Was this article helpful?
Dislike 0
Views: 482

Continue reading

Previous: Points Expiration
Next: Process past orders